Align parent links with parents in CommitBox

Added each parent commit to its own tr.

Bug: Issue 3120
Change-Id: Ibbbb9d8148d31e62fdcdfd9601465d71f8dc89d1
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/CommitBox.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/CommitBox.java
index c412587d..4bdd17f 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/CommitBox.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/CommitBox.java
@@ -31,11 +31,13 @@
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.core.client.JsArray;
 import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.TableRowElement;
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.resources.client.CssResource;
 import com.google.gwt.uibinder.client.UiBinder;
 import com.google.gwt.uibinder.client.UiField;
 import com.google.gwt.uibinder.client.UiHandler;
+import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.ui.Anchor;
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.Composite;
@@ -64,7 +66,7 @@
   @UiField Image mergeCommit;
   @UiField CopyableLabel commitName;
   @UiField FlowPanel webLinkPanel;
-  @UiField Element parents;
+  @UiField TableRowElement firstParent;
   @UiField FlowPanel parentCommits;
   @UiField FlowPanel parentWebLinks;
   @UiField InlineHyperlink authorNameEmail;
@@ -146,29 +148,56 @@
   }
 
   private void setParents(String project, JsArray<CommitInfo> commits) {
-    setVisible(parents, true);
+    setVisible(firstParent, true);
+    TableRowElement next = firstParent;
+    TableRowElement previous = null;
     for (CommitInfo c : Natives.asList(commits)) {
-      CopyableLabel copyLabel = new CopyableLabel(c.commit());
-      copyLabel.setTitle(c.subject());
-      copyLabel.setStyleName(style.clippy());
-      parentCommits.add(copyLabel);
-
-      GitwebLink gw = Gerrit.getGitwebLink();
-      if (gw != null) {
-        Anchor a =
-            new Anchor(gw.getLinkName(), gw.toRevision(project, c.commit()));
-        a.setStyleName(style.parentWebLink());
-        parentWebLinks.add(a);
+      if (next == firstParent) {
+        CopyableLabel copyLabel = getCommitLabel(c);
+        parentCommits.add(copyLabel);
+        addLinks(project, c, parentWebLinks);
+      } else {
+        next.appendChild(DOM.createTD());
+        Element td1 = DOM.createTD();
+        td1.appendChild(getCommitLabel(c).getElement());
+        next.appendChild(td1);
+        FlowPanel linksPanel = new FlowPanel();
+        linksPanel.addStyleName(style.parentWebLink());
+        addLinks(project, c, linksPanel);
+        Element td2 = DOM.createTD();
+        td2.appendChild(linksPanel.getElement());
+        next.appendChild(td2);
+        previous.getParentElement().insertAfter(next, previous);
       }
-      JsArray<WebLinkInfo> links = c.web_links();
-      if (links != null) {
-        for (WebLinkInfo link : Natives.asList(links)) {
-          parentWebLinks.add(link.toAnchor());
-        }
+      previous = next;
+      next = DOM.createTR().cast();
+    }
+  }
+
+  private void addLinks(String project, CommitInfo c, FlowPanel panel) {
+    GitwebLink gw = Gerrit.getGitwebLink();
+    if (gw != null) {
+      Anchor a =
+          new Anchor(gw.getLinkName(), gw.toRevision(project, c.commit()));
+      a.setStyleName(style.parentWebLink());
+      panel.add(a);
+    }
+    JsArray<WebLinkInfo> links = c.web_links();
+    if (links != null) {
+      for (WebLinkInfo link : Natives.asList(links)) {
+        panel.add(link.toAnchor());
       }
     }
   }
 
+  private CopyableLabel getCommitLabel(CommitInfo c) {
+    CopyableLabel copyLabel;
+    copyLabel = new CopyableLabel(c.commit());
+    copyLabel.setTitle(c.subject());
+    copyLabel.setStyleName(style.clippy());
+    return copyLabel;
+  }
+
   private static void formatLink(GitPerson person, FlowPanel p,
       InlineHyperlink name, Element date, ChangeInfo change) {
     // only try to fetch the avatar image for author and committer if an avatar
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/CommitBox.ui.xml b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/CommitBox.ui.xml
index 90632c8..5b7fb89 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/CommitBox.ui.xml
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/CommitBox.ui.xml
@@ -162,7 +162,7 @@
             <g:FlowPanel ui:field='webLinkPanel' styleName='{style.webLinkPanel}'/>
         </td>
       </tr>
-      <tr ui:field='parents' style='display: none'>
+      <tr ui:field='firstParent' style='display: none'>
         <th><ui:msg>Parent(s)</ui:msg></th>
         <td>
           <g:FlowPanel ui:field='parentCommits'/>