IDEA-50621 (Changelists with empty names should not be created)
[fedora-idea.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / ui / EditChangelistDialog.java
blob0baf3126fdff8c08044f3879da12b2e528a555c4
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.
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 com.intellij.openapi.vcs.changes.LocalChangeListImpl;
26 import org.jetbrains.annotations.NotNull;
28 import javax.swing.*;
30 /**
31 * @author max
33 public class EditChangelistDialog extends DialogWrapper {
34 private final EditChangelistPanel myPanel;
35 private final Project myProject;
36 private final LocalChangeList myList;
38 public EditChangelistDialog(Project project, @NotNull LocalChangeList list) {
39 super(project, true);
40 myProject = project;
41 myList = list;
42 myPanel = new EditChangelistPanel(((LocalChangeListImpl) list).getEditHandler()) {
43 @Override
44 protected void nameChanged(String errorMessage) {
45 setOKActionEnabled(errorMessage == null);
46 setErrorText(errorMessage);
49 myPanel.setName(list.getName());
50 myPanel.setDescription(list.getComment());
51 myPanel.init(project, list);
52 myPanel.getMakeActiveCheckBox().setSelected(myList.isDefault());
53 myPanel.getMakeActiveCheckBox().setEnabled(!myList.isDefault());
54 setTitle(VcsBundle.message("changes.dialog.editchangelist.title"));
55 init();
58 protected JComponent createCenterPanel() {
59 return myPanel.getContent();
62 protected void doOKAction() {
63 String oldName = myList.getName();
64 String oldComment = myList.getComment();
66 if (!Comparing.equal(oldName, myPanel.getName()) && ChangeListManager.getInstance(myProject).findChangeList(myPanel.getName()) != null) {
67 Messages.showErrorDialog(myPanel.getContent(),
68 VcsBundle.message("changes.dialog.editchangelist.error.already.exists", myPanel.getName()),
69 VcsBundle.message("changes.dialog.editchangelist.title"));
70 return;
73 if (!Comparing.equal(oldName, myPanel.getName(), true) || !Comparing.equal(oldComment, myPanel.getDescription(), true)) {
74 final ChangeListManager clManager = ChangeListManager.getInstance(myProject);
76 final String newName = myPanel.getName();
77 if (! myList.getName().equals(newName)) {
78 clManager.editName(myList.getName(), newName);
80 final String newDescription = myPanel.getDescription();
81 if (! myList.getComment().equals(newDescription)) {
82 clManager.editComment(myList.getName(), newDescription);
85 if (!myList.isDefault() && myPanel.getMakeActiveCheckBox().isSelected()) {
86 ChangeListManager.getInstance(myProject).setDefaultChangeList(myList);
88 myPanel.changelistCreatedOrChanged(myList);
89 super.doOKAction();
92 public JComponent getPreferredFocusedComponent() {
93 return myPanel.getPrefferedFocusedComponent();
96 protected String getDimensionServiceKey() {
97 return "VCS.EditChangelistDialog";