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.ui.Messages;
21 import com.intellij.openapi.util.Comparing;
22 import com.intellij.openapi.vcs.VcsBundle;
23 import com.intellij.openapi.vcs.changes.ChangeListManager;
24 import com.intellij.openapi.vcs.changes.LocalChangeList;
25 import org.jetbrains.annotations.NotNull;
32 public class EditChangelistDialog extends DialogWrapper {
33 private final NewEditChangelistPanel myPanel;
34 private final Project myProject;
35 private final LocalChangeList myList;
37 public EditChangelistDialog(Project project, @NotNull LocalChangeList list) {
41 myPanel = new NewEditChangelistPanel(project) {
43 protected void nameChanged(String errorMessage) {
44 setOKActionEnabled(errorMessage == null);
45 setErrorText(errorMessage);
48 myPanel.setName(list.getName());
49 myPanel.setDescription(list.getComment());
51 myPanel.getMakeActiveCheckBox().setSelected(myList.isDefault());
52 myPanel.getMakeActiveCheckBox().setEnabled(!myList.isDefault());
53 setTitle(VcsBundle.message("changes.dialog.editchangelist.title"));
57 protected JComponent createCenterPanel() {
58 return myPanel.getContent();
61 protected void doOKAction() {
62 String oldName = myList.getName();
63 String oldComment = myList.getComment();
65 if (!Comparing.equal(oldName, myPanel.getName()) && ChangeListManager.getInstance(myProject).findChangeList(myPanel.getName()) != null) {
66 Messages.showErrorDialog(myPanel.getContent(),
67 VcsBundle.message("changes.dialog.editchangelist.error.already.exists", myPanel.getName()),
68 VcsBundle.message("changes.dialog.editchangelist.title"));
72 if (!Comparing.equal(oldName, myPanel.getName(), true) || !Comparing.equal(oldComment, myPanel.getDescription(), true)) {
73 final ChangeListManager clManager = ChangeListManager.getInstance(myProject);
75 final String newName = myPanel.getName();
76 if (! myList.getName().equals(newName)) {
77 clManager.editName(myList.getName(), newName);
79 final String newDescription = myPanel.getDescription();
80 if (! myList.getComment().equals(newDescription)) {
81 clManager.editComment(myList.getName(), newDescription);
84 if (!myList.isDefault() && myPanel.getMakeActiveCheckBox().isSelected()) {
85 ChangeListManager.getInstance(myProject).setDefaultChangeList(myList);
87 myPanel.changelistCreatedOrChanged(myList);
91 public JComponent getPreferredFocusedComponent() {
92 return myPanel.getPreferredFocusedComponent();
95 protected String getDimensionServiceKey() {
96 return "VCS.EditChangelistDialog";