2 * Copyright 2000-2011 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 import com.intellij.openapi.project.Project;
19 import com.intellij.openapi.ui.Splitter;
20 import com.intellij.openapi.vcs.changes.Change;
21 import com.intellij.openapi.vcs.changes.ui.ChangesBrowser;
22 import com.intellij.util.Consumer;
23 import git4idea.history.browser.GitCommit;
24 import org.jetbrains.annotations.NotNull;
28 import java.util.Collections;
29 import java.util.List;
32 * List of commits at the left, the {@link ChangesBrowser} at the right.
33 * Select a commit to shows its changes in the changes browser.
35 * @author Kirill Likhodedov
37 public class GitCommitListWithDiffPanel extends JPanel {
39 private final ChangesBrowser myChangesBrowser;
40 private final GitCommitListPanel myCommitListPanel;
42 public GitCommitListWithDiffPanel(@NotNull Project project, @NotNull List<GitCommit> commits) {
43 super(new BorderLayout());
45 myCommitListPanel = new GitCommitListPanel(project, commits);
46 myCommitListPanel.addListSelectionListener(new Consumer<GitCommit>() {
47 @Override public void consume(GitCommit commit) {
48 myChangesBrowser.setChangesToDisplay(commit.getChanges());
52 myChangesBrowser = new ChangesBrowser(project, null, Collections.<Change>emptyList(), null, false, true, null, ChangesBrowser.MyUseCase.LOCAL_CHANGES, null);
53 myCommitListPanel.registerDiffAction(myChangesBrowser.getDiffAction());
55 Splitter splitter = new Splitter(false, 0.7f);
56 splitter.setHonorComponentsMinimumSize(false);
57 splitter.setFirstComponent(myCommitListPanel);
58 splitter.setSecondComponent(myChangesBrowser);
63 public JComponent getPreferredFocusComponent() {
64 return myCommitListPanel.getPreferredFocusComponent();
67 public void setCommits(@NotNull List<GitCommit> commits) {
68 myCommitListPanel.setCommits(commits);