// 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.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;

/**
 * Extension for the user profile screen.
 */
public class CookBookProfileExtension extends VerticalPanel {
  static class Factory implements Panel.EntryPoint {
    @Override
    public void onLoad(Panel panel) {
      panel.setWidget(new CookBookProfileExtension());
    }
  }

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

    // TODO: fetch employer and department via REST from server,
    // e.g. GET /accounts/self/cookbook~info

    g.setText(0, 0, "Employer");
    fmt.addStyleName(0, 0, "header");
    g.setText(0, 1, "CookBook Corporation");

    g.setText(1, 0, "Department");
    fmt.addStyleName(1, 0, "header");
    g.setText(1, 1, "Cookies");
    add(g);

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

@@ -660,16 +660,122 @@
 lient;%0A%0A
+import com.google.gerrit.client.GerritUiExtensionPoint;%0Aimport com.google.gerrit.client.info.AccountInfo;%0A
 import c
@@ -1193,24 +1193,131 @@
 el panel) %7B%0A
+      AccountInfo accountInfo =%0A          panel.getObject(GerritUiExtensionPoint.Key.ACCOUNT_INFO).cast();%0A
       panel.
@@ -1355,16 +1355,27 @@
 tension(
+accountInfo
 ));%0A    
@@ -1408,16 +1408,39 @@
 tension(
+AccountInfo accountInfo
 ) %7B%0A    
@@ -1457,17 +1457,17 @@
 ew Grid(
-2
+3
 , 2);%0A  
@@ -1913,16 +1913,237 @@
 %22Cookies
+ %22 + accountInfo.email());%0A%0A    g.setText(2, 0, %22CookBook Email%22);%0A    fmt.addStyleName(2, 0, %22header%22);%0A    g.setText(2, 1, accountInfo.username() != null%0A        ? accountInfo.username() + %22@cookbook.com%22%0A        : %22N/A
 %22);%0A    
@@ -2246,25 +2246,25 @@
 ddStyleName(
-1
+2
 , 0, %22bottom

Add example of how to get AccountInfo in extension panel