Add screen for service user

At the moment this screen just displays the same data about the
service user which can also be seen in the service user list. Later we
will also display the SSH keys on the new service user screen and
allow to change the properties of the service user.

Change-Id: Ia2e974f8df8f27210c228d06c86f00b302b8dd24
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserInfo.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserInfo.java
index 68c0a7b..6cee377 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserInfo.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserInfo.java
@@ -19,6 +19,7 @@
 public class ServiceUserInfo extends JavaScriptObject {
   public final native int _account_id() /*-{ return this._account_id || 0; }-*/;
   public final native String name() /*-{ return this.name; }-*/;
+  public final native String username() /*-{ return this.username; }-*/;
   public final native String email() /*-{ return this.email; }-*/;
   public final native String created_by() /*-{ return this.created_by; }-*/;
   public final native String created_at() /*-{ return this.created_at; }-*/;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserListScreen.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserListScreen.java
index 945859e..37517ca 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserListScreen.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserListScreen.java
@@ -20,6 +20,7 @@
 import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.user.client.ui.FlexTable;
 import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
+import com.google.gwt.user.client.ui.InlineHyperlink;
 import com.google.gwt.user.client.ui.VerticalPanel;
 
 public class ServiceUserListScreen extends VerticalPanel {
@@ -75,7 +76,8 @@
         fmt.addStyleName(row, 0, "leftMostCell");
       }
 
-      t.setText(row, 0, username);
+      t.setWidget(row, 0, new InlineHyperlink(
+          username, "/x/" + Plugin.get().getName() + "/user/" + username));
       t.setText(row, 1, a.name());
       t.setText(row, 2, a.email());
       t.setText(row, 3, a.created_by());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserPlugin.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserPlugin.java
index 4210adc..63b9a43 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserPlugin.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserPlugin.java
@@ -26,5 +26,6 @@
     Plugin.get().screen("create", new CreateServiceUserScreen.Factory());
     Plugin.get().screen("admin", new ServiceUserAdminScreen.Factory());
     Plugin.get().screen("list", new ServiceUserListScreen.Factory());
+    Plugin.get().screenRegex("user/(.*)", new ServiceUserScreen.Factory());
   }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserScreen.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserScreen.java
new file mode 100644
index 0000000..534063c
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserScreen.java
@@ -0,0 +1,70 @@
+// Copyright (C) 2014 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.serviceuser.client;
+
+import com.google.gerrit.plugin.client.Plugin;
+import com.google.gerrit.plugin.client.rpc.RestApi;
+import com.google.gerrit.plugin.client.screen.Screen;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.FlexTable;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.VerticalPanel;
+
+public class ServiceUserScreen extends VerticalPanel {
+  static class Factory implements Screen.EntryPoint {
+    @Override
+    public void onLoad(Screen screen) {
+      screen.setPageTitle("Service User " + screen.getToken(1));
+      screen.show(new ServiceUserScreen(screen.getToken(1)));
+    }
+  }
+
+  ServiceUserScreen(String serviceUser) {
+    setStyleName("serviceuser-panel");
+
+    new RestApi("config").id("server").view(Plugin.get().getPluginName(), "serviceusers")
+        .id(serviceUser).get(new AsyncCallback<ServiceUserInfo>() {
+            @Override
+            public void onSuccess(ServiceUserInfo info) {
+              display(info);
+            }
+
+            @Override
+            public void onFailure(Throwable caught) {
+              // never invoked
+            }
+          });
+  }
+
+  private void display(ServiceUserInfo info) {
+    MyTable t = new MyTable();
+    t.addRow("Username", info.username());
+    t.addRow("Full Name", info.name());
+    t.addRow("Email Address", info.email());
+    t.addRow("Created By", info.created_by());
+    t.addRow("Created At", info.created_at());
+    add(t);
+  }
+
+  private static class MyTable extends FlexTable {
+    private static int row = 0;
+
+    private void addRow(String label, String value) {
+      setWidget(row, 0, new Label(label + ":"));
+      setWidget(row, 1, new Label(value));
+      row++;
+    }
+  }
+}