IDEA-50621 (Changelists with empty names should not be created)
authorirengrig <Irina.Chernushina@jetbrains.com>
Wed, 20 Jan 2010 17:14:54 +0000 (20:14 +0300)
committerirengrig <Irina.Chernushina@jetbrains.com>
Wed, 20 Jan 2010 17:14:54 +0000 (20:14 +0300)
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDialog.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangeListChooser.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangeListChooserPanel.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/EditChangelistDialog.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/EditChangelistPanel.java

index 905e45c537c8940a159f3d40aa3e473d2e03f15e..136892925fe647970aa63cb931b38e24f0c0ea3d 100644 (file)
@@ -650,9 +650,10 @@ public class ApplyPatchDialog extends DialogWrapper {
   }
 
   private void createUIComponents() {
-    myChangeListChooser = new ChangeListChooserPanel(null, new Consumer<Boolean>() {
-      public void consume(final Boolean aBoolean) {
-        setOKActionEnabled(aBoolean);
+    myChangeListChooser = new ChangeListChooserPanel(null, new Consumer<String>() {
+      public void consume(final String errorMessage) {
+        setOKActionEnabled(errorMessage == null);
+        setErrorText(errorMessage);
       }
     });
   }
index ec3d0cef02a188e0c65c9652083883edf41542b2..9824f05e6fe6f73b2b7a21b1f9f8b97ee70eb21f 100644 (file)
@@ -16,7 +16,6 @@
 package com.intellij.openapi.vcs.changes.patch;
 
 import com.intellij.openapi.actionSystem.*;
-import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diff.impl.patch.FilePatch;
 import com.intellij.openapi.diff.impl.patch.PatchReader;
 import com.intellij.openapi.diff.impl.patch.PatchSyntaxException;
@@ -31,10 +30,8 @@ import com.intellij.openapi.ui.TextFieldWithBrowseButton;
 import com.intellij.openapi.ui.popup.JBPopupFactory;
 import com.intellij.openapi.ui.popup.PopupStep;
 import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
-import com.intellij.openapi.util.Computable;
 import com.intellij.openapi.util.IconLoader;
 import com.intellij.openapi.util.Pair;
-import com.intellij.openapi.util.SystemInfo;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vcs.ObjectsConvertor;
 import com.intellij.openapi.vcs.VcsBundle;
@@ -52,7 +49,6 @@ import com.intellij.ui.SimpleColoredComponent;
 import com.intellij.ui.SimpleTextAttributes;
 import com.intellij.util.Consumer;
 import com.intellij.util.containers.Convertor;
-import com.intellij.util.containers.MultiMap;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -137,9 +133,10 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
       }
     };
 
-    myChangeListChooser = new ChangeListChooserPanel(null, new Consumer<Boolean>() {
-      public void consume(final Boolean aBoolean) {
-        setOKActionEnabled(aBoolean);
+    myChangeListChooser = new ChangeListChooserPanel(null, new Consumer<String>() {
+      public void consume(final String errorMessage) {
+        setOKActionEnabled(errorMessage == null);
+        setErrorText(errorMessage);
       }
     });
     ChangeListManager changeListManager = ChangeListManager.getInstance(project);
index 155557ab6f3c36b407bf9cf5602506c8d3375f79..bbcae9197eb7c5b11227c26bdbb435921ff6f2e5 100644 (file)
@@ -18,9 +18,9 @@ package com.intellij.openapi.vcs.changes.ui;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.vcs.changes.ChangeList;
+import com.intellij.openapi.vcs.changes.ChangeListEditHandler;
 import com.intellij.openapi.vcs.changes.LocalChangeList;
 import com.intellij.openapi.vcs.changes.LocalChangeListImpl;
-import com.intellij.openapi.vcs.changes.ChangeListEditHandler;
 import com.intellij.util.Consumer;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -52,9 +52,10 @@ public class ChangeListChooser extends DialogWrapper {
       }
     }
 
-    myPanel = new ChangeListChooserPanel(null, new Consumer<Boolean>() {
-      public void consume(final Boolean aBoolean) {
-        setOKActionEnabled(aBoolean);
+    myPanel = new ChangeListChooserPanel(null, new Consumer<String>() {
+      public void consume(final String errorMessage) {
+        setOKActionEnabled(errorMessage == null);
+        setErrorText(errorMessage);
       }
     });
 
index 9026188cda261288218e1a549c63bd3ff9e931c7..a74e309a53a35a7038272ad7fe50d9774f2030c4 100644 (file)
@@ -46,9 +46,10 @@ public class ChangeListChooserPanel extends JPanel {
   private JComboBox myExisitingsCombo;
   private EditChangelistPanel myNewListPanel;
   @Nullable private final ChangeListEditHandler myHandler;
-  private final Consumer<Boolean> myOkEnabledListener;
+  private final Consumer<String> myOkEnabledListener;
+  private Project myProject;
 
-  public ChangeListChooserPanel(@Nullable final ChangeListEditHandler handler, @NotNull final Consumer<Boolean> okEnabledListener) {
+  public ChangeListChooserPanel(@Nullable final ChangeListEditHandler handler, @NotNull final Consumer<String> okEnabledListener) {
     super(new BorderLayout());
     myHandler = handler;
     myOkEnabledListener = okEnabledListener;
@@ -62,6 +63,7 @@ public class ChangeListChooserPanel extends JPanel {
   }
 
   public void init(final Project project) {
+    myProject = project;
 
     myExisitingsCombo.setRenderer(new ColoredListCellRenderer() {
 
@@ -100,6 +102,9 @@ public class ChangeListChooserPanel extends JPanel {
       myNewListPanel.setEnabled(true);
       myNewListPanel.requestFocus();
     }
+    if (myProject != null) {
+      myNewListPanel.nameChangedImpl(myProject, null);
+    }
   }
 
   @Nullable
@@ -158,7 +163,11 @@ public class ChangeListChooserPanel extends JPanel {
 
       @Override
       protected void nameChanged(String errorMessage) {
-        myOkEnabledListener.consume(myRbExisting.isSelected() || errorMessage == null);
+        if (myRbExisting.isSelected()) {
+          myOkEnabledListener.consume(null);
+        } else {
+          myOkEnabledListener.consume(errorMessage);
+        }
       }
     };
   }
index 66edf9b29b5e988505b22fca0befa1eec1652a80..0baf3126fdff8c08044f3879da12b2e528a555c4 100644 (file)
@@ -19,7 +19,6 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.Comparing;
-import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vcs.VcsBundle;
 import com.intellij.openapi.vcs.changes.ChangeListManager;
 import com.intellij.openapi.vcs.changes.LocalChangeList;
@@ -43,7 +42,8 @@ public class EditChangelistDialog extends DialogWrapper {
     myPanel = new EditChangelistPanel(((LocalChangeListImpl) list).getEditHandler()) {
       @Override
       protected void nameChanged(String errorMessage) {
-        setOKActionEnabled(!StringUtil.isEmptyOrSpaces(myPanel.getName()));
+        setOKActionEnabled(errorMessage == null);
+        setErrorText(errorMessage);
       }
     };
     myPanel.setName(list.getName());
index e5a0dc6087afbb75b3692f80202c256b4cd668dc..ca08000163f536eaf9d9d462f0984e87c446012a 100644 (file)
@@ -51,24 +51,24 @@ public abstract class EditChangelistPanel {
   public EditChangelistPanel(@Nullable final ChangeListEditHandler handler) {
     myHandler = handler;
 
+    myNameTextField.addKeyListener(new KeyListener() {
+      public void keyTyped(final KeyEvent e) {
+        onEditName(EditChangelistPanel.this.myHandler);
+      }
+      public void keyPressed(final KeyEvent e) {
+      }
+      public void keyReleased(final KeyEvent e) {
+        onEditName(EditChangelistPanel.this.myHandler);
+      }
+    });
+    myNameTextField.addInputMethodListener(new InputMethodListener() {
+      public void inputMethodTextChanged(final InputMethodEvent event) {
+        onEditName(EditChangelistPanel.this.myHandler);
+      }
+      public void caretPositionChanged(final InputMethodEvent event) {
+      }
+    });
     if (myHandler != null) {
-      myNameTextField.addKeyListener(new KeyListener() {
-        public void keyTyped(final KeyEvent e) {
-          onEditName(EditChangelistPanel.this.myHandler);
-        }
-        public void keyPressed(final KeyEvent e) {
-        }
-        public void keyReleased(final KeyEvent e) {
-          onEditName(EditChangelistPanel.this.myHandler);
-        }
-      });
-      myNameTextField.addInputMethodListener(new InputMethodListener() {
-        public void inputMethodTextChanged(final InputMethodEvent event) {
-          onEditName(EditChangelistPanel.this.myHandler);
-        }
-        public void caretPositionChanged(final InputMethodEvent event) {
-        }
-      });
       myDescriptionTextArea.addKeyListener(new KeyListener() {
         public void keyTyped(final KeyEvent e) {
         }
@@ -101,14 +101,21 @@ public abstract class EditChangelistPanel {
     myNameTextField.getDocument().addDocumentListener(new DocumentAdapter() {
       @Override
       protected void textChanged(DocumentEvent e) {
-        String name = getName();
-        if ((initial == null || !name.equals(initial.getName())) && ChangeListManager.getInstance(project).findChangeList(name) != null) {
-          nameChanged(VcsBundle.message("new.changelist.duplicate.name.error"));
-        } else {
-          nameChanged(null);
-        }
+        nameChangedImpl(project, initial);
       }
     });
+    nameChangedImpl(project, initial);
+  }
+
+  protected void nameChangedImpl(final Project project, final LocalChangeList initial) {
+    String name = getName();
+    if (name == null || name.trim().length() == 0) {
+      nameChanged("Cannot create new changelist with empty name.");
+    } else if ((initial == null || !name.equals(initial.getName())) && ChangeListManager.getInstance(project).findChangeList(name) != null) {
+      nameChanged(VcsBundle.message("new.changelist.duplicate.name.error"));
+    } else {
+      nameChanged(null);
+    }
   }
 
   public void changelistCreatedOrChanged(LocalChangeList list) {
@@ -118,11 +125,15 @@ public abstract class EditChangelistPanel {
   }
 
   private void onEditComment(ChangeListEditHandler handler) {
-    myNameTextField.setText(handler.changeNameOnChangeComment(myNameTextField.getText(), myDescriptionTextArea.getText()));
+    if (handler != null) {
+      myNameTextField.setText(handler.changeNameOnChangeComment(myNameTextField.getText(), myDescriptionTextArea.getText()));
+    }
   }
 
   private void onEditName(ChangeListEditHandler handler) {
-    myDescriptionTextArea.setText(handler.changeCommentOnChangeName(myNameTextField.getText(), myDescriptionTextArea.getText()));
+    if (handler != null) {
+      myDescriptionTextArea.setText(handler.changeCommentOnChangeName(myNameTextField.getText(), myDescriptionTextArea.getText()));
+    }
   }
 
   public void setName(String s) {