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.
16 package com.intellij.openapi.vcs.changes.ui;
18 import com.intellij.openapi.project.Project;
19 import com.intellij.openapi.ui.DialogWrapper;
20 import com.intellij.openapi.vcs.changes.ChangeList;
21 import com.intellij.openapi.vcs.changes.ChangeListEditHandler;
22 import com.intellij.openapi.vcs.changes.LocalChangeList;
23 import com.intellij.openapi.vcs.changes.LocalChangeListImpl;
24 import com.intellij.util.Consumer;
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
29 import java.util.Collection;
34 public class ChangeListChooser extends DialogWrapper {
35 private final Project myProject;
36 private LocalChangeList mySelectedList;
37 private final ChangeListChooserPanel myPanel;
39 public ChangeListChooser(@NotNull Project project,
40 @NotNull Collection<? extends ChangeList> changelists,
41 @Nullable ChangeList defaultSelection,
43 @Nullable final String defaultName) {
44 super(project, false);
47 ChangeListEditHandler handler;
48 for (ChangeList changelist : changelists) {
49 handler = ((LocalChangeListImpl)changelist).getEditHandler();
50 if (handler != null) {
55 myPanel = new ChangeListChooserPanel(myProject, new Consumer<String>() {
56 public void consume(final String errorMessage) {
57 setOKActionEnabled(errorMessage == null);
58 setErrorText(errorMessage);
63 myPanel.setChangeLists(changelists);
64 myPanel.setDefaultSelection(defaultSelection);
67 if (defaultName != null) {
68 myPanel.setDefaultName(defaultName);
74 public JComponent getPreferredFocusedComponent() {
75 return myPanel.getPreferredFocusedComponent();
78 protected String getDimensionServiceKey() {
79 return "VCS.ChangelistChooser";
82 protected void doOKAction() {
83 mySelectedList = myPanel.getSelectedList(myProject);
84 if (mySelectedList != null) {
89 public LocalChangeList getSelectedList() {
90 return mySelectedList;
93 protected JComponent createCenterPanel() {