Disable checkbox for useContentMerge if 'Fast Forward Only'

Disable the checkbox 'Automatically resolve conflicts' in the
ProjectInfoScreen if 'Fast Forward Only' is chosen as submit
type. Since the setting for the useContentMerge option is ignored if
'Fast Forward Only' is chosen as submit type it is only confusing
to the user if this option is editable but has no effect.

Change-Id: I963df4d577120e1671dd7e9faf195c600df6ff5e
Signed-off-by: Edwin Kempin <edwin.kempin@gmail.com>
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/Documentation/config-replication.txt b/Documentation/config-replication.txt
index 4292001..1e20d2b 100644
--- a/Documentation/config-replication.txt
+++ b/Documentation/config-replication.txt
@@ -145,7 +145,7 @@
 [[remote.name.replicationRetry]]remote.<name>.replicationRetry::
 +
 Number of minutes to wait before scheduling a remote push operation
-previously failed due offline remote server.
+previously failed due to an offline remote server.
 +
 If a remote push operation fails because a remote server was
 offline, all push operations to the same destination URL are
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java
index f424bff..22fd8d9 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java
@@ -21,6 +21,9 @@
 import com.google.gerrit.client.ui.SmallHeading;
 import com.google.gerrit.common.data.ProjectDetail;
 import com.google.gerrit.reviewdb.Project;
+import com.google.gerrit.reviewdb.Project.SubmitType;
+import com.google.gwt.event.dom.client.ChangeEvent;
+import com.google.gwt.event.dom.client.ChangeHandler;
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.user.client.ui.Button;
@@ -118,6 +121,12 @@
     for (final Project.SubmitType type : Project.SubmitType.values()) {
       submitType.addItem(Util.toLongString(type), type.name());
     }
+    submitType.addChangeHandler(new ChangeHandler() {
+      @Override
+      public void onChange(ChangeEvent event) {
+        setEnabledForUseContentMerge();
+      }
+    });
     saveEnabler.listenTo(submitType);
     projectOptionsPanel.add(submitType);
 
@@ -132,6 +141,22 @@
     add(projectOptionsPanel);
   }
 
+  /**
+   * Enables the {@link #useContentMerge} checkbox if the selected submit type
+   * allows the usage of content merge.
+   * If the submit type (currently only 'Fast Forward Only') does not allow
+   * content merge the useContentMerge checkbox gets disabled.
+   */
+  private void setEnabledForUseContentMerge() {
+    if (SubmitType.FAST_FORWARD_ONLY.equals(Project.SubmitType
+        .valueOf(submitType.getValue(submitType.getSelectedIndex())))) {
+      useContentMerge.setEnabled(false);
+      useContentMerge.setValue(false);
+    } else {
+      useContentMerge.setEnabled(true);
+    }
+  }
+
   private void initAgreements() {
     agreementsPanel = new VerticalPanel();
     agreementsPanel.add(new SmallHeading(Util.C.headingAgreements()));
@@ -148,14 +173,16 @@
   }
 
   private void setSubmitType(final Project.SubmitType newSubmitType) {
+    int index = -1;
     if (submitType != null) {
       for (int i = 0; i < submitType.getItemCount(); i++) {
         if (newSubmitType.name().equals(submitType.getValue(i))) {
-          submitType.setSelectedIndex(i);
-          return;
+          index = i;
+          break;
         }
       }
-      submitType.setSelectedIndex(-1);
+      submitType.setSelectedIndex(index);
+      setEnabledForUseContentMerge();
     }
   }