IDEA-57797 Edit changelist: "comment" field should have wrapping
authorirengrig <Irina.Chernushina@jetbrains.com>
Sun, 5 Dec 2010 16:42:20 +0000 (19:42 +0300)
committerirengrig <Irina.Chernushina@jetbrains.com>
Sun, 5 Dec 2010 16:42:20 +0000 (19:42 +0300)
IDEA-60087 VersionControl: in NewChangelist dialog multiline comment entering is confusing
+ spell checking
 [review=kirill.safonov]

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.form
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.form [deleted file]
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/EditChangelistPanel.java [deleted file]
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/NewChangelistDialog.form
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/NewChangelistDialog.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/NewEditChangelistPanel.java [new file with mode: 0644]

index 8d716da36cf8f6521b9b585aaa41c18acb76414e..54faa9e76ab2de77d99d693fdf025ddea7dbdd3d 100644 (file)
@@ -136,7 +136,7 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
       }
     };
 
-    myChangeListChooser = new ChangeListChooserPanel(null, new Consumer<String>() {
+    myChangeListChooser = new ChangeListChooserPanel(project, new Consumer<String>() {
       public void consume(final String errorMessage) {
         setOKActionEnabled(errorMessage == null);
         setErrorText(errorMessage);
@@ -145,7 +145,7 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
     ChangeListManager changeListManager = ChangeListManager.getInstance(project);
     myChangeListChooser.setChangeLists(changeListManager.getChangeListsCopy());
     myChangeListChooser.setDefaultSelection(changeListManager.getDefaultChangeList());
-    myChangeListChooser.init(project);
+    myChangeListChooser.init();
 
     myInfoCalculator = new ChangesLegendCalculator();
     myCommitLegendPanel = new CommitLegendPanel(myInfoCalculator);
index bbcae9197eb7c5b11227c26bdbb435921ff6f2e5..1c7c45a2f025566de06d42044fb6fadb87e32231 100644 (file)
@@ -52,14 +52,14 @@ public class ChangeListChooser extends DialogWrapper {
       }
     }
 
-    myPanel = new ChangeListChooserPanel(null, new Consumer<String>() {
+    myPanel = new ChangeListChooserPanel(myProject, new Consumer<String>() {
       public void consume(final String errorMessage) {
         setOKActionEnabled(errorMessage == null);
         setErrorText(errorMessage);
       }
     });
 
-    myPanel.init(project);
+    myPanel.init();
     myPanel.setChangeLists(changelists);
     myPanel.setDefaultSelection(defaultSelection);
 
index 4042c6410a27fb93ce522cf782792dd72d370652..7228db028df1275da4a92fb215f20210588c2409 100644 (file)
         </constraints>
         <properties/>
       </component>
-      <nested-form id="8eefe" form-file="com/intellij/openapi/vcs/changes/ui/EditChangelistPanel.form" binding="myNewListPanel" custom-create="true">
+      <component id="54fed" class="com.intellij.openapi.vcs.changes.ui.NewEditChangelistPanel" binding="myNewListPanel" custom-create="true">
         <constraints>
-          <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="3" use-parent-layout="false"/>
+          <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="3" use-parent-layout="false">
+            <minimum-size width="300" height="150"/>
+            <preferred-size width="300" height="150"/>
+          </grid>
         </constraints>
-      </nested-form>
+        <properties/>
+      </component>
     </children>
   </grid>
   <buttonGroups>
index 0ddfb96e029513a4523db502d1f0fbfc9b46c449..73bddba1d1d789d22b027150902bb6bff765fe82 100644 (file)
@@ -20,13 +20,13 @@ import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.vcs.VcsBundle;
 import com.intellij.openapi.vcs.VcsConfiguration;
 import com.intellij.openapi.vcs.changes.ChangeList;
-import com.intellij.openapi.vcs.changes.ChangeListEditHandler;
 import com.intellij.openapi.vcs.changes.ChangeListManager;
 import com.intellij.openapi.vcs.changes.LocalChangeList;
 import com.intellij.openapi.vcs.changes.issueLinks.IssueLinkRenderer;
 import com.intellij.ui.HtmlListCellRenderer;
 import com.intellij.ui.SimpleTextAttributes;
 import com.intellij.util.Consumer;
+import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -44,14 +44,13 @@ public class ChangeListChooserPanel extends JPanel {
   private JRadioButton myRbExisting;
   private JRadioButton myRbNew;
   private JComboBox myExistingListsCombo;
-  private EditChangelistPanel myNewListPanel;
-  @Nullable private final ChangeListEditHandler myHandler;
+  private NewEditChangelistPanel myNewListPanel;
   private final Consumer<String> myOkEnabledListener;
   private Project myProject;
 
-  public ChangeListChooserPanel(@Nullable final ChangeListEditHandler handler, @NotNull final Consumer<String> okEnabledListener) {
+  public ChangeListChooserPanel(final Project project, @NotNull final Consumer<String> okEnabledListener) {
     super(new BorderLayout());
-    myHandler = handler;
+    myProject = project;
     myOkEnabledListener = okEnabledListener;
     add(myPanel, BorderLayout.CENTER);
 
@@ -62,11 +61,9 @@ public class ChangeListChooserPanel extends JPanel {
     });
   }
 
-  public void init(final Project project) {
-    myProject = project;
-
+  public void init() {
     myExistingListsCombo.setRenderer(new HtmlListCellRenderer(myExistingListsCombo.getRenderer()) {
-      private final IssueLinkRenderer myLinkRenderer = new IssueLinkRenderer(project, this);
+      private final IssueLinkRenderer myLinkRenderer = new IssueLinkRenderer(myProject, this);
 
       @Override
       protected void doCustomize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
@@ -77,7 +74,7 @@ public class ChangeListChooserPanel extends JPanel {
         }
       }
     });
-    myNewListPanel.init(project, null);
+    myNewListPanel.init(null);
   }
 
   public void setChangeLists(Collection<? extends ChangeList> changeLists) {
@@ -96,12 +93,12 @@ public class ChangeListChooserPanel extends JPanel {
   private void updateEnabledItems() {
     if (myRbExisting.isSelected()) {
       myExistingListsCombo.setEnabled(true);
-      myNewListPanel.setEnabled(false);
+      UIUtil.setEnabled(myNewListPanel, false, true);
       myExistingListsCombo.requestFocus();
     }
     else {
       myExistingListsCombo.setEnabled(false);
-      myNewListPanel.setEnabled(true);
+      UIUtil.setEnabled(myNewListPanel, true, true);
       myNewListPanel.requestFocus();
     }
     if (myProject != null) {
@@ -161,7 +158,7 @@ public class ChangeListChooserPanel extends JPanel {
   }
 
   private void createUIComponents() {
-    myNewListPanel = new EditChangelistPanel(myHandler) {
+    myNewListPanel = new NewEditChangelistPanel(myProject) {
 
       @Override
       protected void nameChanged(String errorMessage) {
index 08adbd1fdc7a8d6faeea7b61196b5ae6463ae95a..0c880b94ef6f85c46c43fa10b664f916f9219f2f 100644 (file)
@@ -22,7 +22,6 @@ import com.intellij.openapi.util.Comparing;
 import com.intellij.openapi.vcs.VcsBundle;
 import com.intellij.openapi.vcs.changes.ChangeListManager;
 import com.intellij.openapi.vcs.changes.LocalChangeList;
-import com.intellij.openapi.vcs.changes.LocalChangeListImpl;
 import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
@@ -31,7 +30,7 @@ import javax.swing.*;
  * @author max
  */
 public class EditChangelistDialog extends DialogWrapper {
-  private final EditChangelistPanel myPanel;
+  private final NewEditChangelistPanel myPanel;
   private final Project myProject;
   private final LocalChangeList myList;
 
@@ -39,7 +38,7 @@ public class EditChangelistDialog extends DialogWrapper {
     super(project, true);
     myProject = project;
     myList = list;
-    myPanel = new EditChangelistPanel(((LocalChangeListImpl) list).getEditHandler()) {
+    myPanel = new NewEditChangelistPanel(project) {
       @Override
       protected void nameChanged(String errorMessage) {
         setOKActionEnabled(errorMessage == null);
@@ -48,7 +47,7 @@ public class EditChangelistDialog extends DialogWrapper {
     };
     myPanel.setName(list.getName());
     myPanel.setDescription(list.getComment());
-    myPanel.init(project, list);
+    myPanel.init(list);
     myPanel.getMakeActiveCheckBox().setSelected(myList.isDefault());
     myPanel.getMakeActiveCheckBox().setEnabled(!myList.isDefault());
     setTitle(VcsBundle.message("changes.dialog.editchangelist.title"));
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/EditChangelistPanel.form b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/EditChangelistPanel.form
deleted file mode 100644 (file)
index a37e21e..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.vcs.changes.ui.EditChangelistPanel">
-  <grid id="27dc6" binding="myContent" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
-    <margin top="0" left="0" bottom="0" right="0"/>
-    <constraints>
-      <xy x="20" y="20" width="500" height="197"/>
-    </constraints>
-    <properties/>
-    <border type="none"/>
-    <children>
-      <component id="50c54" class="javax.swing.JLabel">
-        <constraints>
-          <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <labelFor value="164a0"/>
-          <text resource-bundle="messages/VcsBundle" key="edit.changelist.name"/>
-        </properties>
-      </component>
-      <component id="c6b25" class="javax.swing.JLabel">
-        <constraints>
-          <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <labelFor value="4ec74"/>
-          <text resource-bundle="messages/VcsBundle" key="edit.changelist.description"/>
-        </properties>
-      </component>
-      <component id="164a0" class="com.intellij.ui.EditorTextField" binding="myNameTextField">
-        <constraints>
-          <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
-            <preferred-size width="150" height="-1"/>
-          </grid>
-        </constraints>
-        <properties/>
-      </component>
-      <scrollpane class="com.intellij.ui.components.JBScrollPane" id="18eaf">
-        <constraints>
-          <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties/>
-        <border type="none"/>
-        <children>
-          <component id="4ec74" class="com.intellij.ui.EditorTextField" binding="myDescriptionTextArea">
-            <constraints/>
-            <properties>
-              <columns value="50"/>
-              <lineWrap value="true"/>
-              <rows value="5"/>
-              <wrapStyleWord value="true"/>
-            </properties>
-          </component>
-        </children>
-      </scrollpane>
-      <grid id="361c1" binding="myAdditionalControlsPanel" layout-manager="FlowLayout" hgap="0" vgap="0" flow-align="1">
-        <constraints>
-          <grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="8" fill="2" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties/>
-        <border type="none"/>
-        <children>
-          <component id="c949a" class="javax.swing.JCheckBox" binding="myMakeActiveCheckBox">
-            <constraints/>
-            <properties>
-              <text resource-bundle="messages/VcsBundle" key="new.changelist.make.active.checkbox"/>
-            </properties>
-          </component>
-        </children>
-      </grid>
-    </children>
-  </grid>
-</form>
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/EditChangelistPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/EditChangelistPanel.java
deleted file mode 100644 (file)
index f50908b..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.openapi.vcs.changes.ui;
-
-import com.intellij.openapi.editor.event.DocumentEvent;
-import com.intellij.openapi.editor.event.DocumentListener;
-import com.intellij.openapi.extensions.Extensions;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vcs.VcsBundle;
-import com.intellij.openapi.vcs.VcsConfiguration;
-import com.intellij.openapi.vcs.changes.ChangeListEditHandler;
-import com.intellij.openapi.vcs.changes.ChangeListManager;
-import com.intellij.openapi.vcs.changes.LocalChangeList;
-import com.intellij.ui.EditorTextField;
-import com.intellij.util.Consumer;
-import com.intellij.util.ui.UIUtil;
-import org.jetbrains.annotations.Nullable;
-
-import javax.swing.*;
-import java.awt.event.InputMethodEvent;
-import java.awt.event.InputMethodListener;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-
-/**
- * @author max
- */
-public abstract class EditChangelistPanel {
-  private EditorTextField myNameTextField;
-  private EditorTextField myDescriptionTextArea;
-  private JPanel myContent;
-  private JPanel myAdditionalControlsPanel;
-  private JCheckBox myMakeActiveCheckBox;
-
-  @Nullable
-  private final ChangeListEditHandler myHandler;
-  private Consumer<LocalChangeList> myConsumer;
-
-  public EditChangelistPanel(@Nullable final ChangeListEditHandler handler) {
-    myHandler = handler;
-
-    myDescriptionTextArea.setOneLineMode(false);
-    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) {
-      myDescriptionTextArea.addKeyListener(new KeyListener() {
-        public void keyTyped(final KeyEvent e) {
-        }
-        public void keyPressed(final KeyEvent e) {
-        }
-        public void keyReleased(final KeyEvent e) {
-          onEditComment(EditChangelistPanel.this.myHandler);
-        }
-      });
-      myDescriptionTextArea.addInputMethodListener(new InputMethodListener() {
-        public void inputMethodTextChanged(final InputMethodEvent event) {
-          onEditComment(EditChangelistPanel.this.myHandler);
-        }
-        public void caretPositionChanged(final InputMethodEvent event) {
-        }
-      });
-    }
-  }
-
-  public JCheckBox getMakeActiveCheckBox() {
-    return myMakeActiveCheckBox;
-  }
-
-  public void init(final Project project, final LocalChangeList initial) {
-    myMakeActiveCheckBox.setSelected(VcsConfiguration.getInstance(project).MAKE_NEW_CHANGELIST_ACTIVE);
-    for (EditChangelistSupport support : Extensions.getExtensions(EditChangelistSupport.EP_NAME, project)) {
-      support.installSearch(myNameTextField, myDescriptionTextArea);
-      myConsumer = support.addControls(myAdditionalControlsPanel, initial);
-    }
-    myNameTextField.getDocument().addDocumentListener(new DocumentListener() {
-      @Override
-      public void beforeDocumentChange(DocumentEvent event) {
-      }
-
-      @Override
-      public void documentChanged(DocumentEvent event) {
-        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) {
-    if (myConsumer != null) {
-      myConsumer.consume(list);
-    }
-  }
-
-  private void onEditComment(ChangeListEditHandler handler) {
-    if (handler != null) {
-      myNameTextField.setText(handler.changeNameOnChangeComment(myNameTextField.getText(), myDescriptionTextArea.getText()));
-    }
-  }
-
-  private void onEditName(ChangeListEditHandler handler) {
-    if (handler != null) {
-      myDescriptionTextArea.setText(handler.changeCommentOnChangeName(myNameTextField.getText(), myDescriptionTextArea.getText()));
-    }
-  }
-
-  public void setName(String s) {
-    myNameTextField.setText(s);
-  }
-
-  public String getName() {
-    return myNameTextField.getText();
-  }
-
-  public void setDescription(String s) {
-    myDescriptionTextArea.setText(s);
-  }
-
-  public String getDescription() {
-    return myDescriptionTextArea.getText();
-  }
-
-  public JComponent getContent() {
-    return myContent;
-  }
-
-  public void setEnabled(boolean b) {
-    UIUtil.setEnabled(myContent, b, true);
-  }
-
-  public void requestFocus() {
-    myNameTextField.requestFocus();
-  }
-
-  public JComponent getPreferredFocusedComponent() {
-    return myNameTextField;
-  }
-
-  protected abstract void nameChanged(String errorMessage);
-}
index b3a72a5bce766ab6cd35b4eec84ec27287c2a37c..be48a18b8513e16762e70ebcceaf50bfd5e60dfb 100644 (file)
@@ -2,23 +2,29 @@
 <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.vcs.changes.ui.NewChangelistDialog">
   <grid id="27dc6" binding="myTopPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
     <constraints>
-      <xy x="20" y="20" width="500" height="400"/>
+      <xy x="20" y="20" width="500" height="413"/>
     </constraints>
     <properties/>
     <border type="none"/>
     <children>
-      <nested-form id="41c97" form-file="com/intellij/openapi/vcs/changes/ui/EditChangelistPanel.form" binding="myPanel" custom-create="true">
-        <constraints border-constraint="Center"/>
-      </nested-form>
-      <grid id="4554b" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+      <grid id="4554b" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
         <margin top="0" left="0" bottom="0" right="0"/>
-        <constraints border-constraint="South"/>
+        <constraints border-constraint="Center"/>
         <properties/>
         <border type="none"/>
         <children>
+          <component id="df554" class="com.intellij.openapi.vcs.changes.ui.NewEditChangelistPanel" binding="myPanel" custom-create="true">
+            <constraints>
+              <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
+                <minimum-size width="300" height="150"/>
+                <preferred-size width="300" height="150"/>
+              </grid>
+            </constraints>
+            <properties/>
+          </component>
           <component id="58c5a" class="javax.swing.JLabel" binding="myErrorLabel">
             <constraints>
-              <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+              <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
             </constraints>
             <properties>
               <foreground awt-color="red"/>
index bb5820fe3a8d80da685927c0293a230aca481593..ed94d182adadbd97797758f02a582ab18090bd3d 100644 (file)
@@ -27,7 +27,7 @@ import javax.swing.*;
  */
 public class NewChangelistDialog extends DialogWrapper {
 
-  private EditChangelistPanel myPanel;
+  private NewEditChangelistPanel myPanel;
   private JPanel myTopPanel;
   private JLabel myErrorLabel;
   private final Project myProject;
@@ -37,7 +37,7 @@ public class NewChangelistDialog extends DialogWrapper {
     myProject = project;
     setTitle(VcsBundle.message("changes.dialog.newchangelist.title"));
 
-    myPanel.init(project, null);
+    myPanel.init(null);
 
     init();
   }
@@ -65,19 +65,19 @@ public class NewChangelistDialog extends DialogWrapper {
   }
 
   protected String getDimensionServiceKey() {
-    return "VCS.NewChangelistDialog";
+    return "VCS.EditChangelistDialog";
   }
 
   public boolean isNewChangelistActive() {
     return myPanel.getMakeActiveCheckBox().isSelected();
   }
 
-  public EditChangelistPanel getPanel() {
+  public NewEditChangelistPanel getPanel() {
     return myPanel;
   }
 
   private void createUIComponents() {
-    myPanel = new EditChangelistPanel(null) {
+    myPanel = new NewEditChangelistPanel(myProject) {
       @Override
       protected void nameChanged(String errorMessage) {
         setOKActionEnabled(errorMessage == null);
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/NewEditChangelistPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/NewEditChangelistPanel.java
new file mode 100644 (file)
index 0000000..97a2b5b
--- /dev/null
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.openapi.vcs.changes.ui;
+
+import com.intellij.openapi.components.ServiceManager;
+import com.intellij.openapi.editor.event.DocumentEvent;
+import com.intellij.openapi.editor.event.DocumentListener;
+import com.intellij.openapi.editor.ex.EditorEx;
+import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.fileTypes.FileTypes;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vcs.VcsBundle;
+import com.intellij.openapi.vcs.VcsConfiguration;
+import com.intellij.openapi.vcs.changes.ChangeListManager;
+import com.intellij.openapi.vcs.changes.LocalChangeList;
+import com.intellij.ui.EditorCustomization;
+import com.intellij.ui.EditorTextField;
+import com.intellij.ui.EditorTextFieldProvider;
+import com.intellij.util.Consumer;
+
+import javax.swing.*;
+import java.awt.*;
+
+public abstract class NewEditChangelistPanel extends JPanel {
+  private EditorTextField myNameTextField;
+  private EditorTextField myDescriptionTextArea;
+  private JPanel myAdditionalControlsPanel;
+  private JCheckBox myMakeActiveCheckBox;
+
+  private Consumer<LocalChangeList> myConsumer;
+  private boolean myNameNotPatched;
+  private final Project myProject;
+
+  public NewEditChangelistPanel(final Project project) {
+    super(new GridBagLayout());
+    myProject = project;
+    final GridBagConstraints gb = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
+                                                                   new Insets(1, 1, 1, 1), 0, 0);
+    myNameNotPatched = true;
+
+    final JLabel nameLabel = new JLabel(VcsBundle.message("edit.changelist.name"));
+    add(nameLabel, gb);
+    ++ gb.gridx;
+    gb.fill = GridBagConstraints.HORIZONTAL;
+    gb.weightx = 1;
+    myNameTextField = createEditorField(project, 1);
+    myNameTextField.setOneLineMode(true);
+    add(myNameTextField, gb);
+    nameLabel.setLabelFor(myNameTextField);
+
+    ++ gb.gridy;
+    gb.gridx = 0;
+
+    gb.weightx = 0;
+    gb.fill = GridBagConstraints.NONE;
+    final JLabel commentLabel = new JLabel(VcsBundle.message("edit.changelist.description"));
+    add(commentLabel, gb);
+    ++ gb.gridx;
+    gb.weightx = 1;
+    gb.weighty = 1;
+    gb.fill = GridBagConstraints.BOTH;
+    myDescriptionTextArea = createEditorField(project, 4);
+    myDescriptionTextArea.setOneLineMode(false);
+    add(myDescriptionTextArea, gb);
+    commentLabel.setLabelFor(myDescriptionTextArea);
+
+    ++ gb.gridy;
+    gb.gridx = 0;
+    gb.gridwidth = 2;
+    gb.weighty = 0;
+    myAdditionalControlsPanel = new JPanel();
+    final BoxLayout layout = new BoxLayout(myAdditionalControlsPanel, BoxLayout.X_AXIS);
+    myAdditionalControlsPanel.setLayout(layout);
+    myMakeActiveCheckBox = new JCheckBox(VcsBundle.message("new.changelist.make.active.checkbox"));
+    myAdditionalControlsPanel.add(myMakeActiveCheckBox);
+    add(myAdditionalControlsPanel, gb);
+
+    setPreferredSize(new Dimension(300, 150));
+    setMinimumSize(new Dimension(300, 150));
+
+    // a hack to create editor inside field
+    setName("a");
+    setName("");
+  }
+
+  public JCheckBox getMakeActiveCheckBox() {
+    return myMakeActiveCheckBox;
+  }
+
+  public void init(final LocalChangeList initial) {
+    myMakeActiveCheckBox.setSelected(VcsConfiguration.getInstance(myProject).MAKE_NEW_CHANGELIST_ACTIVE);
+    for (EditChangelistSupport support : Extensions.getExtensions(EditChangelistSupport.EP_NAME, myProject)) {
+      support.installSearch(myNameTextField, myDescriptionTextArea);
+      myConsumer = support.addControls(myAdditionalControlsPanel, initial);
+    }
+    myNameTextField.getDocument().addDocumentListener(new DocumentListener() {
+      @Override
+      public void beforeDocumentChange(DocumentEvent event) {
+      }
+
+      @Override
+      public void documentChanged(DocumentEvent event) {
+        nameChangedImpl(myProject, initial);
+      }
+    });
+    nameChangedImpl(myProject, initial);
+  }
+
+  protected void nameChangedImpl(final Project project, final LocalChangeList initial) {
+    if (myNameNotPatched) {
+      final EditorEx editor = (EditorEx)myNameTextField.getEditor();
+      if (editor != null) {
+        editor.setHorizontalScrollbarVisible(false);
+        myNameNotPatched = false;
+      }
+    }
+    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) {
+    if (myConsumer != null) {
+      myConsumer.consume(list);
+    }
+  }
+
+  public void setName(String s) {
+    myNameTextField.setText(s);
+  }
+
+  public String getName() {
+    return myNameTextField.getText();
+  }
+
+  public void setDescription(String s) {
+    myDescriptionTextArea.setText(s);
+  }
+
+  public String getDescription() {
+    return myDescriptionTextArea.getText();
+  }
+
+  public JComponent getContent() {
+    return this;
+  }
+
+  public void requestFocus() {
+    myNameTextField.requestFocus();
+  }
+
+  public JComponent getPreferredFocusedComponent() {
+    return myNameTextField;
+  }
+
+  protected abstract void nameChanged(String errorMessage);
+
+  private static EditorTextField createEditorField(final Project project, final int defaultLines) {
+    final EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class);
+    final EditorTextField editorField;
+    if (defaultLines == 1) {
+      editorField = service.getEditorField(
+        FileTypes.PLAIN_TEXT.getLanguage(), project, EditorCustomization.Feature.SPELL_CHECK);
+    } else {
+      editorField = service.getEditorField(
+        FileTypes.PLAIN_TEXT.getLanguage(), project, EditorCustomization.Feature.SOFT_WRAP, EditorCustomization.Feature.SPELL_CHECK
+      );
+    }
+    final int height = editorField.getFontMetrics(editorField.getFont()).getHeight();
+    editorField.getComponent().setMinimumSize(new Dimension(100, height));
+    return editorField;
+  }
+}