Use GWT's built-in JsArray instead of NativeList
These are basically identical, except for a couple of utility methods, which are easily moved to static methods in Natives. Change-Id: I6fa23f462dc270595a19f4b373622ddee37e498e
This commit is contained in:
		@@ -23,6 +23,7 @@ import com.google.gerrit.client.groups.GroupList;
 | 
			
		||||
import com.google.gerrit.client.groups.MemberInfo;
 | 
			
		||||
import com.google.gerrit.client.groups.MemberList;
 | 
			
		||||
import com.google.gerrit.client.rpc.GerritCallback;
 | 
			
		||||
import com.google.gerrit.client.rpc.Natives;
 | 
			
		||||
import com.google.gerrit.client.ui.AccountGroupSuggestOracle;
 | 
			
		||||
import com.google.gerrit.client.ui.AccountLink;
 | 
			
		||||
import com.google.gerrit.client.ui.AddMemberBox;
 | 
			
		||||
@@ -160,14 +161,14 @@ public class AccountGroupMembersScreen extends AccountGroupScreen {
 | 
			
		||||
        MemberList.all(getGroupUUID(), new GerritCallback<MemberList>() {
 | 
			
		||||
          @Override
 | 
			
		||||
          public void onSuccess(MemberList result) {
 | 
			
		||||
            members.display(result.asList());
 | 
			
		||||
            members.display(Natives.asList(result));
 | 
			
		||||
          }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        GroupList.included(getGroupUUID(), new GerritCallback<GroupList>() {
 | 
			
		||||
          @Override
 | 
			
		||||
          public void onSuccess(GroupList result) {
 | 
			
		||||
            includes.display(result.asList());
 | 
			
		||||
            includes.display(Natives.asList(result));
 | 
			
		||||
          }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -15,11 +15,13 @@
 | 
			
		||||
package com.google.gerrit.client.admin;
 | 
			
		||||
 | 
			
		||||
import static com.google.gerrit.client.admin.Util.C;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.client.Dispatcher;
 | 
			
		||||
import com.google.gerrit.client.Gerrit;
 | 
			
		||||
import com.google.gerrit.client.groups.GroupInfo;
 | 
			
		||||
import com.google.gerrit.client.groups.GroupList;
 | 
			
		||||
import com.google.gerrit.client.groups.GroupMap;
 | 
			
		||||
import com.google.gerrit.client.rpc.Natives;
 | 
			
		||||
import com.google.gerrit.client.ui.HighlightingInlineHyperlink;
 | 
			
		||||
import com.google.gerrit.client.ui.NavigationTable;
 | 
			
		||||
import com.google.gerrit.client.ui.Util;
 | 
			
		||||
@@ -79,11 +81,11 @@ public class GroupTable extends NavigationTable<GroupInfo> {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void display(GroupMap groups, String toHighlight) {
 | 
			
		||||
    display(groups.values().asList(), toHighlight);
 | 
			
		||||
    display(Natives.asList(groups.values()), toHighlight);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void display(GroupList groups) {
 | 
			
		||||
    display(groups.asList(), null);
 | 
			
		||||
    display(Natives.asList(groups), null);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void display(List<GroupInfo> list, String toHighlight) {
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,7 @@ package com.google.gerrit.client.admin;
 | 
			
		||||
import com.google.gerrit.client.Gerrit;
 | 
			
		||||
import com.google.gerrit.client.plugins.PluginInfo;
 | 
			
		||||
import com.google.gerrit.client.plugins.PluginMap;
 | 
			
		||||
import com.google.gerrit.client.rpc.Natives;
 | 
			
		||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
 | 
			
		||||
import com.google.gerrit.client.ui.FancyFlexTable;
 | 
			
		||||
import com.google.gwt.user.client.ui.Anchor;
 | 
			
		||||
@@ -73,7 +74,7 @@ public class PluginListScreen extends PluginScreen {
 | 
			
		||||
        table.removeRow(table.getRowCount() - 1);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      for (final PluginInfo p : plugins.values().asList()) {
 | 
			
		||||
      for (final PluginInfo p : Natives.asList(plugins.values())) {
 | 
			
		||||
        final int row = table.getRowCount();
 | 
			
		||||
        table.insertRow(row);
 | 
			
		||||
        applyDataRowStyle(row);
 | 
			
		||||
 
 | 
			
		||||
@@ -16,9 +16,9 @@ package com.google.gerrit.client.admin;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.client.dashboards.DashboardList;
 | 
			
		||||
import com.google.gerrit.client.dashboards.DashboardsTable;
 | 
			
		||||
import com.google.gerrit.client.rpc.NativeList;
 | 
			
		||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.Project;
 | 
			
		||||
import com.google.gwt.core.client.JsArray;
 | 
			
		||||
import com.google.gwt.user.client.ui.FlowPanel;
 | 
			
		||||
 | 
			
		||||
public class ProjectDashboardsScreen extends ProjectScreen {
 | 
			
		||||
@@ -34,9 +34,9 @@ public class ProjectDashboardsScreen extends ProjectScreen {
 | 
			
		||||
  protected void onLoad() {
 | 
			
		||||
    super.onLoad();
 | 
			
		||||
    DashboardList.all(getProjectKey(),
 | 
			
		||||
        new ScreenLoadCallback<NativeList<DashboardList>>(this) {
 | 
			
		||||
        new ScreenLoadCallback<JsArray<DashboardList>>(this) {
 | 
			
		||||
      @Override
 | 
			
		||||
      protected void preDisplay(NativeList<DashboardList> result) {
 | 
			
		||||
      protected void preDisplay(JsArray<DashboardList> result) {
 | 
			
		||||
        dashes.display(result);
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
 
 | 
			
		||||
@@ -16,10 +16,11 @@ package com.google.gerrit.client.changes;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.client.Gerrit;
 | 
			
		||||
import com.google.gerrit.client.NotFoundScreen;
 | 
			
		||||
import com.google.gerrit.client.rpc.NativeList;
 | 
			
		||||
import com.google.gerrit.client.rpc.Natives;
 | 
			
		||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
 | 
			
		||||
import com.google.gerrit.client.ui.Screen;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.Account;
 | 
			
		||||
import com.google.gwt.core.client.JsArray;
 | 
			
		||||
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.Comparator;
 | 
			
		||||
@@ -64,9 +65,9 @@ public class AccountDashboardScreen extends Screen implements ChangeListScreen {
 | 
			
		||||
    super.onLoad();
 | 
			
		||||
    String who = mine ? "self" : ownerId.toString();
 | 
			
		||||
    ChangeList.query(
 | 
			
		||||
        new ScreenLoadCallback<NativeList<ChangeList>>(this) {
 | 
			
		||||
        new ScreenLoadCallback<JsArray<ChangeList>>(this) {
 | 
			
		||||
          @Override
 | 
			
		||||
          protected void preDisplay(NativeList<ChangeList> result) {
 | 
			
		||||
          protected void preDisplay(JsArray<ChangeList> result) {
 | 
			
		||||
            display(result);
 | 
			
		||||
          }
 | 
			
		||||
        },
 | 
			
		||||
@@ -81,7 +82,7 @@ public class AccountDashboardScreen extends Screen implements ChangeListScreen {
 | 
			
		||||
    table.setRegisterKeys(true);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void display(NativeList<ChangeList> result) {
 | 
			
		||||
  private void display(JsArray<ChangeList> result) {
 | 
			
		||||
    if (!mine && !hasChanges(result)) {
 | 
			
		||||
      // When no results are returned and the data is not for the
 | 
			
		||||
      // current user, the target user is presumed to not exist.
 | 
			
		||||
@@ -112,7 +113,7 @@ public class AccountDashboardScreen extends Screen implements ChangeListScreen {
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Collections.sort(out.asList(), outComparator());
 | 
			
		||||
    Collections.sort(Natives.asList(out), outComparator());
 | 
			
		||||
 | 
			
		||||
    table.updateColumnsForLabels(out, in, done);
 | 
			
		||||
    outgoing.display(out);
 | 
			
		||||
@@ -132,9 +133,9 @@ public class AccountDashboardScreen extends Screen implements ChangeListScreen {
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private boolean hasChanges(NativeList<ChangeList> result) {
 | 
			
		||||
    for (ChangeList list : result.asList()) {
 | 
			
		||||
      if (!list.isEmpty()) {
 | 
			
		||||
  private boolean hasChanges(JsArray<ChangeList> result) {
 | 
			
		||||
    for (ChangeList list : Natives.asList(result)) {
 | 
			
		||||
      if (list.length() != 0) {
 | 
			
		||||
        return true;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
@@ -142,7 +143,7 @@ public class AccountDashboardScreen extends Screen implements ChangeListScreen {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static String guessName(ChangeList list) {
 | 
			
		||||
    for (ChangeInfo change : list.asList()) {
 | 
			
		||||
    for (ChangeInfo change : Natives.asList(list)) {
 | 
			
		||||
      if (change.owner() != null && change.owner().name() != null) {
 | 
			
		||||
        return change.owner().name();
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
@@ -14,21 +14,21 @@
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.client.changes;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.client.rpc.NativeList;
 | 
			
		||||
import com.google.gerrit.client.rpc.RestApi;
 | 
			
		||||
import com.google.gerrit.common.changes.ListChangesOption;
 | 
			
		||||
import com.google.gwt.core.client.JsArray;
 | 
			
		||||
import com.google.gwt.user.client.rpc.AsyncCallback;
 | 
			
		||||
import com.google.gwtorm.client.KeyUtil;
 | 
			
		||||
 | 
			
		||||
import java.util.EnumSet;
 | 
			
		||||
 | 
			
		||||
/** List of changes available from {@code /changes/}. */
 | 
			
		||||
public class ChangeList extends NativeList<ChangeInfo> {
 | 
			
		||||
public class ChangeList extends JsArray<ChangeInfo> {
 | 
			
		||||
  private static final String URI = "/changes/";
 | 
			
		||||
 | 
			
		||||
  /** Run 2 or more queries in a single remote invocation. */
 | 
			
		||||
  public static void query(
 | 
			
		||||
      AsyncCallback<NativeList<ChangeList>> callback, String... queries) {
 | 
			
		||||
      AsyncCallback<JsArray<ChangeList>> callback, String... queries) {
 | 
			
		||||
    assert queries.length >= 2; // At least 2 is required for correct result.
 | 
			
		||||
    RestApi call = new RestApi(URI);
 | 
			
		||||
    for (String q : queries) {
 | 
			
		||||
 
 | 
			
		||||
@@ -142,7 +142,7 @@ public class ChangeTable2 extends NavigationTable<ChangeInfo> {
 | 
			
		||||
  public void updateColumnsForLabels(ChangeList... lists) {
 | 
			
		||||
    labelNames = new ArrayList<String>();
 | 
			
		||||
    for (ChangeList list : lists) {
 | 
			
		||||
      for (int i = 0; i < list.size(); i++) {
 | 
			
		||||
      for (int i = 0; i < list.length(); i++) {
 | 
			
		||||
        for (String name : list.get(i).labels()) {
 | 
			
		||||
          if (!labelNames.contains(name)) {
 | 
			
		||||
            labelNames.add(name);
 | 
			
		||||
@@ -395,7 +395,7 @@ public class ChangeTable2 extends NavigationTable<ChangeInfo> {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void display(ChangeList changeList) {
 | 
			
		||||
      final int sz = changeList != null ? changeList.size() : 0;
 | 
			
		||||
      final int sz = changeList != null ? changeList.length() : 0;
 | 
			
		||||
      final boolean hadData = rows > 0;
 | 
			
		||||
 | 
			
		||||
      if (hadData) {
 | 
			
		||||
 
 | 
			
		||||
@@ -16,9 +16,10 @@ package com.google.gerrit.client.changes;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.client.Gerrit;
 | 
			
		||||
import com.google.gerrit.client.rpc.GerritCallback;
 | 
			
		||||
import com.google.gerrit.client.rpc.NativeList;
 | 
			
		||||
import com.google.gerrit.client.rpc.Natives;
 | 
			
		||||
import com.google.gerrit.client.ui.InlineHyperlink;
 | 
			
		||||
import com.google.gerrit.common.PageLinks;
 | 
			
		||||
import com.google.gwt.core.client.JsArray;
 | 
			
		||||
import com.google.gwt.http.client.URL;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
@@ -91,13 +92,13 @@ public class DashboardTable extends ChangeTable2 {
 | 
			
		||||
        });
 | 
			
		||||
    } else if (! queries.isEmpty()) {
 | 
			
		||||
      ChangeList.query(
 | 
			
		||||
          new GerritCallback<NativeList<ChangeList>>() {
 | 
			
		||||
          new GerritCallback<JsArray<ChangeList>>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onSuccess(NativeList<ChangeList> result) {
 | 
			
		||||
              updateColumnsForLabels(
 | 
			
		||||
                  result.asList().toArray(new ChangeList[result.size()]));
 | 
			
		||||
              for (int i = 0; i < result.size(); i++) {
 | 
			
		||||
                sections.get(i).display(result.get(i));
 | 
			
		||||
            public void onSuccess(JsArray<ChangeList> result) {
 | 
			
		||||
              List<ChangeList> cls = Natives.asList(result);
 | 
			
		||||
              updateColumnsForLabels(cls.toArray(new ChangeList[cls.size()]));
 | 
			
		||||
              for (int i = 0; i < cls.size(); i++) {
 | 
			
		||||
                sections.get(i).display(cls.get(i));
 | 
			
		||||
              }
 | 
			
		||||
              finishDisplay();
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -116,9 +116,9 @@ public abstract class PagedSingleListScreen extends Screen {
 | 
			
		||||
 | 
			
		||||
  protected void display(final ChangeList result) {
 | 
			
		||||
    changes = result;
 | 
			
		||||
    if (!changes.isEmpty()) {
 | 
			
		||||
    if (changes.length() != 0) {
 | 
			
		||||
      final ChangeInfo f = changes.get(0);
 | 
			
		||||
      final ChangeInfo l = changes.get(changes.size() - 1);
 | 
			
		||||
      final ChangeInfo l = changes.get(changes.length() - 1);
 | 
			
		||||
 | 
			
		||||
      prev.setTargetHistoryToken(anchorPrefix + ",p," + f._sortkey());
 | 
			
		||||
      next.setTargetHistoryToken(anchorPrefix + ",n," + l._sortkey());
 | 
			
		||||
 
 | 
			
		||||
@@ -52,7 +52,7 @@ public class QueryScreen extends PagedSingleListScreen implements
 | 
			
		||||
      @Override
 | 
			
		||||
      public final void onSuccess(ChangeList result) {
 | 
			
		||||
        if (isAttached()) {
 | 
			
		||||
          if (result.size() == 1 && isSingleQuery(query)) {
 | 
			
		||||
          if (result.length() == 1 && isSingleQuery(query)) {
 | 
			
		||||
            ChangeInfo c = result.get(0);
 | 
			
		||||
            Change.Id id = c.legacy_id();
 | 
			
		||||
            Gerrit.display(PageLinks.toChange(id), new ChangeScreen(id));
 | 
			
		||||
 
 | 
			
		||||
@@ -14,16 +14,16 @@
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.client.dashboards;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.client.rpc.NativeList;
 | 
			
		||||
import com.google.gerrit.client.rpc.RestApi;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.Project;
 | 
			
		||||
import com.google.gwt.core.client.JsArray;
 | 
			
		||||
import com.google.gwt.http.client.URL;
 | 
			
		||||
import com.google.gwt.user.client.rpc.AsyncCallback;
 | 
			
		||||
 | 
			
		||||
/** Project dashboards from {@code /projects/<name>/dashboards/}. */
 | 
			
		||||
public class DashboardList extends NativeList<DashboardInfo> {
 | 
			
		||||
public class DashboardList extends JsArray<DashboardInfo> {
 | 
			
		||||
  public static void all(Project.NameKey project,
 | 
			
		||||
      AsyncCallback<NativeList<DashboardList>> callback) {
 | 
			
		||||
      AsyncCallback<JsArray<DashboardList>> callback) {
 | 
			
		||||
    base(project).addParameterTrue("inherited").get(callback);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -15,10 +15,11 @@
 | 
			
		||||
package com.google.gerrit.client.dashboards;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.client.Gerrit;
 | 
			
		||||
import com.google.gerrit.client.rpc.NativeList;
 | 
			
		||||
import com.google.gerrit.client.rpc.Natives;
 | 
			
		||||
import com.google.gerrit.client.ui.NavigationTable;
 | 
			
		||||
import com.google.gerrit.common.PageLinks;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.Project;
 | 
			
		||||
import com.google.gwt.core.client.JsArray;
 | 
			
		||||
import com.google.gwt.user.client.History;
 | 
			
		||||
import com.google.gwt.user.client.ui.Anchor;
 | 
			
		||||
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
 | 
			
		||||
@@ -53,13 +54,13 @@ public class DashboardsTable extends NavigationTable<DashboardInfo> {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void display(DashboardList dashes) {
 | 
			
		||||
    display(dashes.asList());
 | 
			
		||||
    display(Natives.asList(dashes));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void display(NativeList<DashboardList> in) {
 | 
			
		||||
  public void display(JsArray<DashboardList> in) {
 | 
			
		||||
    Map<String, DashboardInfo> map = new HashMap<String, DashboardInfo>();
 | 
			
		||||
    for (DashboardList list : in.asList()) {
 | 
			
		||||
      for (DashboardInfo d : list.asList()) {
 | 
			
		||||
    for (DashboardList list : Natives.asList(in)) {
 | 
			
		||||
      for (DashboardInfo d : Natives.asList(list)) {
 | 
			
		||||
        if (!map.containsKey(d.id())) {
 | 
			
		||||
          map.put(d.id(), d);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -15,11 +15,12 @@
 | 
			
		||||
package com.google.gerrit.client.groups;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.client.VoidResult;
 | 
			
		||||
import com.google.gerrit.client.rpc.NativeList;
 | 
			
		||||
import com.google.gerrit.client.rpc.Natives;
 | 
			
		||||
import com.google.gerrit.client.rpc.RestApi;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.Account;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGroup;
 | 
			
		||||
import com.google.gwt.core.client.JavaScriptObject;
 | 
			
		||||
import com.google.gwt.core.client.JsArray;
 | 
			
		||||
import com.google.gwt.user.client.rpc.AsyncCallback;
 | 
			
		||||
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
@@ -81,14 +82,14 @@ public class GroupApi {
 | 
			
		||||
  /** Add members to a group. */
 | 
			
		||||
  public static void addMembers(AccountGroup.UUID group,
 | 
			
		||||
      Set<String> members,
 | 
			
		||||
      final AsyncCallback<NativeList<MemberInfo>> cb) {
 | 
			
		||||
      final AsyncCallback<JsArray<MemberInfo>> cb) {
 | 
			
		||||
    if (members.size() == 1) {
 | 
			
		||||
      addMember(group,
 | 
			
		||||
          members.iterator().next(),
 | 
			
		||||
          new AsyncCallback<MemberInfo>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onSuccess(MemberInfo result) {
 | 
			
		||||
              cb.onSuccess(NativeList.of(result));
 | 
			
		||||
              cb.onSuccess(Natives.arrayOf(result));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
@@ -129,14 +130,14 @@ public class GroupApi {
 | 
			
		||||
  /** Include groups into a group. */
 | 
			
		||||
  public static void addIncludedGroups(AccountGroup.UUID group,
 | 
			
		||||
      Set<String> includedGroups,
 | 
			
		||||
      final AsyncCallback<NativeList<GroupInfo>> cb) {
 | 
			
		||||
      final AsyncCallback<JsArray<GroupInfo>> cb) {
 | 
			
		||||
    if (includedGroups.size() == 1) {
 | 
			
		||||
      addIncludedGroup(group,
 | 
			
		||||
          includedGroups.iterator().next(),
 | 
			
		||||
          new AsyncCallback<GroupInfo>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onSuccess(GroupInfo result) {
 | 
			
		||||
              cb.onSuccess(NativeList.of(result));
 | 
			
		||||
              cb.onSuccess(Natives.arrayOf(result));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -14,13 +14,13 @@
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.client.groups;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.client.rpc.NativeList;
 | 
			
		||||
import com.google.gerrit.client.rpc.RestApi;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGroup;
 | 
			
		||||
import com.google.gwt.core.client.JsArray;
 | 
			
		||||
import com.google.gwt.user.client.rpc.AsyncCallback;
 | 
			
		||||
 | 
			
		||||
/** Groups available from {@code /groups/} or {@code /accounts/{id}/groups}. */
 | 
			
		||||
public class GroupList extends NativeList<GroupInfo> {
 | 
			
		||||
public class GroupList extends JsArray<GroupInfo> {
 | 
			
		||||
  public static void my(AsyncCallback<GroupList> callback) {
 | 
			
		||||
    new RestApi("/accounts/self/groups").get(callback);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -14,12 +14,12 @@
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.client.groups;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.client.rpc.NativeList;
 | 
			
		||||
import com.google.gerrit.client.rpc.RestApi;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGroup;
 | 
			
		||||
import com.google.gwt.core.client.JsArray;
 | 
			
		||||
import com.google.gwt.user.client.rpc.AsyncCallback;
 | 
			
		||||
 | 
			
		||||
public class MemberList extends NativeList<MemberInfo> {
 | 
			
		||||
public class MemberList extends JsArray<MemberInfo> {
 | 
			
		||||
  public static void all(AccountGroup.UUID group,
 | 
			
		||||
      AsyncCallback<MemberList> callback) {
 | 
			
		||||
    new RestApi("/groups/").id(group.get()).view("members").get(callback);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,62 +0,0 @@
 | 
			
		||||
// Copyright (C) 2012 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.google.gerrit.client.rpc;
 | 
			
		||||
 | 
			
		||||
import com.google.gwt.core.client.JavaScriptObject;
 | 
			
		||||
 | 
			
		||||
import java.util.AbstractList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/** A read-only list of native JavaScript objects stored in a JSON array. */
 | 
			
		||||
public class NativeList<T extends JavaScriptObject> extends JavaScriptObject {
 | 
			
		||||
  public static <T extends JavaScriptObject> NativeList<T> of(T a) {
 | 
			
		||||
    NativeList<T> list = createArray().cast();
 | 
			
		||||
    list.add(a);
 | 
			
		||||
    return list;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected NativeList() {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public final List<T> asList() {
 | 
			
		||||
    return new AbstractList<T>() {
 | 
			
		||||
      @Override
 | 
			
		||||
      public T set(int index, T element) {
 | 
			
		||||
        T old = NativeList.this.get(index);
 | 
			
		||||
        NativeList.this.set0(index, element);
 | 
			
		||||
        return old;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      @Override
 | 
			
		||||
      public T get(int index) {
 | 
			
		||||
        return NativeList.this.get(index);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      @Override
 | 
			
		||||
      public int size() {
 | 
			
		||||
        return NativeList.this.size();
 | 
			
		||||
      }
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public final boolean isEmpty() {
 | 
			
		||||
    return size() == 0;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public final native int size() /*-{ return this.length; }-*/;
 | 
			
		||||
  public final native T get(int i) /*-{ return this[i]; }-*/;
 | 
			
		||||
  public final native void add(T v) /*-{ this.push(v); }-*/;
 | 
			
		||||
  private final native void set0(int i, T v) /*-{ this[i] = v; }-*/;
 | 
			
		||||
}
 | 
			
		||||
@@ -15,6 +15,7 @@
 | 
			
		||||
package com.google.gerrit.client.rpc;
 | 
			
		||||
 | 
			
		||||
import com.google.gwt.core.client.JavaScriptObject;
 | 
			
		||||
import com.google.gwt.core.client.JsArray;
 | 
			
		||||
import com.google.gwt.user.client.rpc.AsyncCallback;
 | 
			
		||||
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
@@ -53,7 +54,7 @@ public class NativeMap<T extends JavaScriptObject> extends JavaScriptObject {
 | 
			
		||||
    return Natives.keys(this);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public final native NativeList<T> values()
 | 
			
		||||
  public final native JsArray<T> values()
 | 
			
		||||
  /*-{
 | 
			
		||||
    var s = this;
 | 
			
		||||
    var v = [];
 | 
			
		||||
 
 | 
			
		||||
@@ -15,9 +15,12 @@
 | 
			
		||||
package com.google.gerrit.client.rpc;
 | 
			
		||||
 | 
			
		||||
import com.google.gwt.core.client.JavaScriptObject;
 | 
			
		||||
import com.google.gwt.core.client.JsArray;
 | 
			
		||||
import com.google.gwt.json.client.JSONObject;
 | 
			
		||||
 | 
			
		||||
import java.util.AbstractList;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
public class Natives {
 | 
			
		||||
@@ -32,6 +35,34 @@ public class Natives {
 | 
			
		||||
    return Collections.emptySet();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static <T extends JavaScriptObject> List<T> asList(
 | 
			
		||||
      final JsArray<T> arr) {
 | 
			
		||||
    return new AbstractList<T>() {
 | 
			
		||||
      @Override
 | 
			
		||||
      public T set(int index, T element) {
 | 
			
		||||
        T old = arr.get(index);
 | 
			
		||||
        arr.set(index, element);
 | 
			
		||||
        return old;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      @Override
 | 
			
		||||
      public T get(int index) {
 | 
			
		||||
        return arr.get(index);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      @Override
 | 
			
		||||
      public int size() {
 | 
			
		||||
        return arr.length();
 | 
			
		||||
      }
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static <T extends JavaScriptObject> JsArray<T> arrayOf(T element) {
 | 
			
		||||
    JsArray<T> arr = JavaScriptObject.createArray().cast();
 | 
			
		||||
    arr.push(element);
 | 
			
		||||
    return arr;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @SuppressWarnings("unchecked")
 | 
			
		||||
  public static <T extends JavaScriptObject> T parseJSON(String json) {
 | 
			
		||||
    if (json.startsWith("\"")) {
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,7 @@ package com.google.gerrit.client.ui;
 | 
			
		||||
import com.google.gerrit.client.RpcStatus;
 | 
			
		||||
import com.google.gerrit.client.projects.ProjectMap;
 | 
			
		||||
import com.google.gerrit.client.rpc.GerritCallback;
 | 
			
		||||
import com.google.gerrit.client.rpc.Natives;
 | 
			
		||||
 | 
			
		||||
/** Suggestion Oracle for Project.NameKey entities. */
 | 
			
		||||
public class ProjectNameSuggestOracle extends SuggestAfterTypingNCharsOracle {
 | 
			
		||||
@@ -29,7 +30,7 @@ public class ProjectNameSuggestOracle extends SuggestAfterTypingNCharsOracle {
 | 
			
		||||
            new GerritCallback<ProjectMap>() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public void onSuccess(ProjectMap map) {
 | 
			
		||||
                callback.onSuggestionsReady(req, new Response(map.values().asList()));
 | 
			
		||||
                callback.onSuggestionsReady(req, new Response(Natives.asList(map.values())));
 | 
			
		||||
              }
 | 
			
		||||
            });
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,7 @@ package com.google.gerrit.client.ui;
 | 
			
		||||
import com.google.gerrit.client.Gerrit;
 | 
			
		||||
import com.google.gerrit.client.projects.ProjectInfo;
 | 
			
		||||
import com.google.gerrit.client.projects.ProjectMap;
 | 
			
		||||
import com.google.gerrit.client.rpc.Natives;
 | 
			
		||||
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
 | 
			
		||||
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
@@ -55,7 +56,7 @@ public class ProjectsTable extends NavigationTable<ProjectInfo> {
 | 
			
		||||
    while (1 < table.getRowCount())
 | 
			
		||||
      table.removeRow(table.getRowCount() - 1);
 | 
			
		||||
 | 
			
		||||
    List<ProjectInfo> list = projects.values().asList();
 | 
			
		||||
    List<ProjectInfo> list = Natives.asList(projects.values());
 | 
			
		||||
    Collections.sort(list, new Comparator<ProjectInfo>() {
 | 
			
		||||
      @Override
 | 
			
		||||
      public int compare(ProjectInfo a, ProjectInfo b) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user