VCS: asynch load of committed changes [in "browse changes" - SVN, CVS] - works for...
[fedora-idea.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / committed / ChangesBrowserDialog.java
blob547dc50d9049b19cb0ae4298ed74e56e8224e7bf
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.
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;
27 import javax.swing.*;
28 import java.awt.*;
29 import java.util.List;
31 /**
32 * @author max
34 public class ChangesBrowserDialog extends DialogWrapper {
35 private Project myProject;
36 private CommittedChangesTableModel myChanges;
37 private Mode myMode;
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) {
44 super(project, true);
45 initDialog(project, changes, mode);
48 public ChangesBrowserDialog(Project project, Component parent, CommittedChangesTableModel changes, final Mode mode) {
49 super(parent, true);
50 initDialog(project, changes, mode);
53 private void initDialog(final Project project, final CommittedChangesTableModel changes, final Mode mode) {
54 myProject = project;
55 myChanges = changes;
56 myMode = 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))) {
61 setModal(false);
63 myAppender = new AsynchConsumer<List<CommittedChangeList>>() {
65 public void finished() {
66 new AbstractCalledLater(myProject, ModalityState.stateForComponent(myCommittedChangesBrowser)) {
67 public void run() {
68 myCommittedChangesBrowser.stopLoading();
70 }.callMe();
73 public void consume(final List<CommittedChangeList> committedChangeLists) {
74 new AbstractCalledLater(myProject, ModalityState.stateForComponent(myCommittedChangesBrowser)) {
75 public void run() {
76 final boolean selectFirst = (myChanges.getRowCount() == 0) && (!committedChangeLists.isEmpty());
77 myChanges.addRows(committedChangeLists);
78 if (selectFirst) {
79 myCommittedChangesBrowser.selectFirstIfAny();
80 } else {
81 myCommittedChangesBrowser.resortKeepSelection();
84 }.callMe();
88 init();
91 public AsynchConsumer<List<CommittedChangeList>> getAppender() {
92 return myAppender;
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;
108 @Override
109 protected void dispose() {
110 super.dispose();
111 myCommittedChangesBrowser.dispose();
114 @Override
115 protected void createDefaultActions() {
116 super.createDefaultActions();
117 if (myMode == Mode.Browse) {
118 getOKAction().putValue(Action.NAME, VcsBundle.message("button.search.again"));
122 @Override
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();