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.
17 package com
.intellij
.openapi
.vcs
.changes
.committed
;
19 import com
.intellij
.CommonBundle
;
20 import com
.intellij
.openapi
.application
.ModalityState
;
21 import com
.intellij
.openapi
.project
.Project
;
22 import com
.intellij
.openapi
.ui
.DialogWrapper
;
23 import com
.intellij
.openapi
.vcs
.VcsBundle
;
24 import com
.intellij
.openapi
.vcs
.versionBrowser
.CommittedChangeList
;
25 import com
.intellij
.util
.AsynchConsumer
;
29 import java
.util
.List
;
34 public class ChangesBrowserDialog
extends DialogWrapper
{
35 private Project myProject
;
36 private CommittedChangesTableModel myChanges
;
38 private CommittedChangesBrowser myCommittedChangesBrowser
;
39 private AsynchConsumer
<List
<CommittedChangeList
>> myAppender
;
41 public enum Mode
{ Simple
, Browse
, Choose
}
43 public ChangesBrowserDialog(Project project
, CommittedChangesTableModel changes
, final Mode mode
) {
45 initDialog(project
, changes
, mode
);
48 public ChangesBrowserDialog(Project project
, Component parent
, CommittedChangesTableModel changes
, final Mode mode
) {
50 initDialog(project
, changes
, mode
);
53 private void initDialog(final Project project
, final CommittedChangesTableModel changes
, final Mode mode
) {
57 setTitle(VcsBundle
.message("dialog.title.changes.browser"));
58 setCancelButtonText(CommonBundle
.getCloseButtonText());
59 final ModalityState currentState
= ModalityState
.current();
60 if ((mode
!= Mode
.Choose
) && (ModalityState
.NON_MODAL
.equals(currentState
))) {
63 myAppender
= new AsynchConsumer
<List
<CommittedChangeList
>>() {
65 public void finished() {
66 new AbstractCalledLater(myProject
, ModalityState
.stateForComponent(myCommittedChangesBrowser
)) {
68 myCommittedChangesBrowser
.stopLoading();
73 public void consume(final List
<CommittedChangeList
> committedChangeLists
) {
74 new AbstractCalledLater(myProject
, ModalityState
.stateForComponent(myCommittedChangesBrowser
)) {
76 final boolean selectFirst
= (myChanges
.getRowCount() == 0) && (!committedChangeLists
.isEmpty());
77 myChanges
.addRows(committedChangeLists
);
79 myCommittedChangesBrowser
.selectFirstIfAny();
81 myCommittedChangesBrowser
.resortKeepSelection();
91 public AsynchConsumer
<List
<CommittedChangeList
>> getAppender() {
95 public void startLoading() {
96 myCommittedChangesBrowser
.startLoading();
99 protected String
getDimensionServiceKey() {
100 return "VCS.ChangesBrowserDialog";
103 protected JComponent
createCenterPanel() {
104 myCommittedChangesBrowser
= new CommittedChangesBrowser(myProject
, myChanges
);
105 return myCommittedChangesBrowser
;
109 protected void dispose() {
111 myCommittedChangesBrowser
.dispose();
115 protected void createDefaultActions() {
116 super.createDefaultActions();
117 if (myMode
== Mode
.Browse
) {
118 getOKAction().putValue(Action
.NAME
, VcsBundle
.message("button.search.again"));
123 protected Action
[] createActions() {
124 if (myMode
== Mode
.Simple
) {
125 return new Action
[] { getCancelAction() };
127 return super.createActions();
130 public CommittedChangeList
getSelectedChangeList() {
131 return myCommittedChangesBrowser
.getSelectedChangeList();