// Copyright (C) 2015 The Android Open Source Project
//
// 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.googlesource.gerrit.plugins.cookbook.client;

import com.google.gerrit.client.GerritUiExtensionPoint;
import com.google.gerrit.client.info.ChangeInfo;
import com.google.gerrit.plugin.client.extension.Panel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwtexpui.clippy.client.CopyableLabel;

/**
 * Extension for change screen that displays the numeric change ID with
 * copy-to-clipboard icon.
 */
public class CookBookChangeScreenExtension extends VerticalPanel {
  static class Factory implements Panel.EntryPoint {
    @Override
    public void onLoad(Panel panel) {
      panel.setWidget(new CookBookChangeScreenExtension(panel));
    }
  }

  CookBookChangeScreenExtension(Panel panel) {
    ChangeInfo change =
        panel.getObject(GerritUiExtensionPoint.Key.CHANGE_INFO).cast();

    Grid g = new Grid(1, 2);
    g.addStyleName("infoBlock");
    CellFormatter fmt = g.getCellFormatter();

    g.setText(0, 0, "Numeric Change ID");
    fmt.addStyleName(0, 0, "header");
    g.setWidget(0, 1, new CopyableLabel(Integer.toString(change._number())));
    add(g);

    fmt.addStyleName(0, 0, "topmost");
    fmt.addStyleName(0, 1, "topmost");
    fmt.addStyleName(0, 0, "bottomheader");
  }
}

@@ -765,16 +765,78 @@
 geInfo;%0A
+import com.google.gerrit.client.info.ChangeInfo.RevisionInfo;%0A
 import c
@@ -1594,16 +1594,113 @@
 .cast();
+%0A    RevisionInfo rev =%0A        panel.getObject(GerritUiExtensionPoint.Key.REVISION_INFO).cast();
 %0A%0A    Gr
@@ -1715,17 +1715,17 @@
 ew Grid(
-1
+2
 , 2);%0A  
@@ -1878,24 +1878,102 @@
  %22header%22);%0A
+    fmt.addStyleName(0, 0, %22topmost%22);%0A    fmt.addStyleName(0, 1, %22topmost%22);%0A
     g.setWid
@@ -2047,24 +2047,61 @@
    add(g);%0A%0A
+    g.setText(1, 0, %22Patch Set ID%22);%0A
     fmt.addS
@@ -2105,38 +2105,37 @@
 ddStyleName(
-0
+1
 , 0, %22
-topmost
+header
 %22);%0A    fmt.
@@ -2143,38 +2143,43 @@
 ddStyleName(
-0, 1, %22topmost
+1, 0, %22bottomheader
 %22);%0A    fmt.
@@ -2191,20 +2191,20 @@
 yleName(
-0, 0
+1, 1
 , %22botto
@@ -2214,14 +2214,99 @@
 ader%22);%0A
+    g.setWidget(1, 1, new CopyableLabel(String.valueOf(rev._number())));%0A    add(g);%0A
   %7D%0A%7D%0A

Add example of revision info on panel extension point