VCS: better show changes comment view
[fedora-idea.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / ui / ChangeListViewerDialog.java
blob7e273ad2bef6b0cb92722f43c7563ec003d2d25e
1 /*
2 * Copyright 2000-2009 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 * Created by IntelliJ IDEA.
19 * User: yole
20 * Date: 20.07.2006
21 * Time: 21:07:50
23 package com.intellij.openapi.vcs.changes.ui;
25 import com.intellij.CommonBundle;
26 import com.intellij.openapi.actionSystem.DataProvider;
27 import com.intellij.openapi.project.Project;
28 import com.intellij.openapi.ui.DialogWrapper;
29 import com.intellij.openapi.ui.Splitter;
30 import com.intellij.openapi.vcs.VcsBundle;
31 import com.intellij.openapi.vcs.VcsDataKeys;
32 import com.intellij.openapi.vcs.changes.Change;
33 import com.intellij.openapi.vcs.changes.committed.CommittedChangesBrowserUseCase;
34 import com.intellij.openapi.vcs.changes.committed.RepositoryChangesBrowser;
35 import com.intellij.openapi.vcs.changes.issueLinks.IssueLinkHtmlRenderer;
36 import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
37 import com.intellij.openapi.vcs.versionBrowser.CommittedChangeListImpl;
38 import com.intellij.ui.BrowserHyperlinkListener;
39 import com.intellij.ui.SeparatorFactory;
40 import com.intellij.util.NotNullFunction;
41 import com.intellij.util.ui.UIUtil;
42 import org.jetbrains.annotations.NonNls;
44 import javax.swing.*;
45 import java.awt.*;
46 import java.util.ArrayList;
47 import java.util.Collection;
48 import java.util.Collections;
49 import java.util.Date;
51 /**
52 * @author max
54 public class ChangeListViewerDialog extends DialogWrapper implements DataProvider {
55 private Project myProject;
56 private CommittedChangeList myChangeList;
57 private RepositoryChangesBrowser myChangesBrowser;
58 private JEditorPane myCommitMessageArea;
59 // do not related to local data/changes etc
60 private final boolean myInAir;
61 private Change[] myChanges;
62 private NotNullFunction<Change, Change> myConvertor;
63 private JScrollPane commitMessageScroll;
65 public ChangeListViewerDialog(Project project, CommittedChangeList changeList) {
66 super(project, true);
67 myInAir = false;
68 initCommitMessageArea(project, changeList);
69 initDialog(project, changeList);
72 public ChangeListViewerDialog(Component parent, Project project, Collection<Change> changes, final boolean inAir) {
73 super(parent, true);
74 myInAir = inAir;
75 initDialog(project, new CommittedChangeListImpl("", "", "", -1, new Date(0), changes));
78 public ChangeListViewerDialog(Project project, Collection<Change> changes, final boolean inAir) {
79 super(project, true);
80 myInAir = inAir;
81 initDialog(project, new CommittedChangeListImpl("", "", "", -1, new Date(0), changes));
84 private void initDialog(final Project project, final CommittedChangeList changeList) {
85 myProject = project;
86 myChangeList = changeList;
87 final Collection<Change> changes = myChangeList.getChanges();
88 myChanges = changes.toArray(new Change[changes.size()]);
90 setTitle(VcsBundle.message("dialog.title.changes.browser"));
91 setCancelButtonText(CommonBundle.message("close.action.name"));
92 setModal(false);
94 init();
97 private void initCommitMessageArea(final Project project, final CommittedChangeList changeList) {
98 myCommitMessageArea = new JEditorPane(UIUtil.HTML_MIME, "");
99 myCommitMessageArea.setEditable(false);
100 @NonNls final String text = IssueLinkHtmlRenderer.formatTextIntoHtml(project, changeList.getComment());
101 myCommitMessageArea.setBackground(UIUtil.getComboBoxDisabledBackground());
102 myCommitMessageArea.addHyperlinkListener(new BrowserHyperlinkListener());
103 commitMessageScroll = new JScrollPane(myCommitMessageArea);
104 myCommitMessageArea.setText(text);
105 myCommitMessageArea.setCaretPosition(0);
109 protected String getDimensionServiceKey() {
110 return "VCS.ChangeListViewerDialog";
113 public Object getData(@NonNls final String dataId) {
114 if (VcsDataKeys.CHANGES.is(dataId)) {
115 return myChanges;
117 return null;
120 public void setConvertor(final NotNullFunction<Change, Change> convertor) {
121 myConvertor = convertor;
124 public JComponent createCenterPanel() {
125 final JPanel mainPanel = new JPanel();
126 mainPanel.setLayout(new BorderLayout());
127 final Splitter splitter = new Splitter(true, 0.9f);
128 myChangesBrowser = new RepositoryChangesBrowser(myProject, Collections.singletonList(myChangeList),
129 new ArrayList<Change>(myChangeList.getChanges()),
130 myChangeList) {
131 @Override
132 protected void showDiffForChanges(final Change[] changesArray, final int indexInSelection) {
133 if (myInAir && (myConvertor != null)) {
134 final Change[] convertedChanges = new Change[changesArray.length];
135 for (int i = 0; i < changesArray.length; i++) {
136 Change change = changesArray[i];
137 convertedChanges[i] = myConvertor.fun(change);
139 super.showDiffForChanges(convertedChanges, indexInSelection);
140 } else {
141 super.showDiffForChanges(changesArray, indexInSelection);
145 myChangesBrowser.setUseCase(myInAir ? CommittedChangesBrowserUseCase.IN_AIR : null);
146 splitter.setFirstComponent(myChangesBrowser);
148 if (myCommitMessageArea != null) {
149 JPanel commitPanel = new JPanel(new BorderLayout());
150 JComponent separator = SeparatorFactory.createSeparator(VcsBundle.message("label.commit.comment"), myCommitMessageArea);
151 commitPanel.add(separator, BorderLayout.NORTH);
152 commitPanel.add(commitMessageScroll, BorderLayout.CENTER);
154 splitter.setSecondComponent(commitPanel);
155 splitter.setShowDividerControls(true);
157 mainPanel.add(splitter, BorderLayout.CENTER);
159 return mainPanel;
162 @Override
163 protected void dispose() {
164 myChangesBrowser.dispose();
165 super.dispose();
168 @Override
169 protected Action[] createActions() {
170 return new Action[] { getCancelAction() };
173 @Override
174 public JComponent getPreferredFocusedComponent() {
175 return myChangesBrowser;