Clean up AccountLinkPanel with lambdas

Dave apologizes for everything looking like a nail.

Change-Id: I0c47ab6e328599fd83caed20979507ef5aefe71b
This commit is contained in:
Dave Borowitz
2016-09-23 04:04:29 -04:00
parent 9c0ab72946
commit 388bc64c08
4 changed files with 32 additions and 70 deletions

View File

@@ -315,7 +315,7 @@ public class AccountGroupMembersScreen extends AccountGroupScreen {
CheckBox checkBox = new CheckBox(); CheckBox checkBox = new CheckBox();
table.setWidget(row, 1, checkBox); table.setWidget(row, 1, checkBox);
checkBox.setEnabled(enabled); checkBox.setEnabled(enabled);
table.setWidget(row, 2, new AccountLinkPanel(i)); table.setWidget(row, 2, AccountLinkPanel.create(i));
table.setText(row, 3, i.email()); table.setText(row, 3, i.email());
final FlexCellFormatter fmt = table.getFlexCellFormatter(); final FlexCellFormatter fmt = table.getFlexCellFormatter();

View File

@@ -22,7 +22,6 @@ import com.google.gerrit.client.info.AccountInfo;
import com.google.gerrit.client.info.ChangeInfo; import com.google.gerrit.client.info.ChangeInfo;
import com.google.gerrit.client.info.ChangeInfo.LabelInfo; import com.google.gerrit.client.info.ChangeInfo.LabelInfo;
import com.google.gerrit.client.ui.AccountLinkPanel; import com.google.gerrit.client.ui.AccountLinkPanel;
import com.google.gerrit.client.ui.AssigneeLinkPanel;
import com.google.gerrit.client.ui.BranchLink; import com.google.gerrit.client.ui.BranchLink;
import com.google.gerrit.client.ui.ChangeLink; import com.google.gerrit.client.ui.ChangeLink;
import com.google.gerrit.client.ui.NavigationTable; import com.google.gerrit.client.ui.NavigationTable;
@@ -237,13 +236,15 @@ public class ChangeTable extends NavigationTable<ChangeInfo> {
} }
if (c.owner() != null) { if (c.owner() != null) {
table.setWidget(row, C_OWNER, new AccountLinkPanel(c.owner(), status)); table.setWidget(row, C_OWNER,
AccountLinkPanel.withStatus(c.owner(), status));
} else { } else {
table.setText(row, C_OWNER, ""); table.setText(row, C_OWNER, "");
} }
if (c.assignee() != null) { if (c.assignee() != null) {
table.setWidget(row, C_ASSIGNEE, new AssigneeLinkPanel(c.assignee())); table.setWidget(row, C_ASSIGNEE,
AccountLinkPanel.forAssignee(c.assignee()));
if (Objects.equals(c.assignee().getId(), if (Objects.equals(c.assignee().getId(),
Gerrit.getUserAccount().getId())) { Gerrit.getUserAccount().getId())) {
table.getRowFormatter().addStyleName(row, table.getRowFormatter().addStyleName(row,

View File

@@ -22,30 +22,44 @@ import com.google.gerrit.common.PageLinks;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.FlowPanel;
import java.util.function.Function;
/** Link to any user's account dashboard. */ /** Link to any user's account dashboard. */
public class AccountLinkPanel extends FlowPanel { public class AccountLinkPanel extends FlowPanel {
public AccountLinkPanel(AccountInfo info) { public static AccountLinkPanel create(AccountInfo ai) {
this(info, Change.Status.NEW); return withStatus(ai, Change.Status.NEW);
} }
public AccountLinkPanel(AccountInfo info, Change.Status status) { public static AccountLinkPanel withStatus(AccountInfo ai,
Change.Status status) {
return new AccountLinkPanel(
ai, name -> PageLinks.toAccountQuery(name, status));
}
public static AccountLinkPanel forAssignee(AccountInfo ai) {
return new AccountLinkPanel(ai, PageLinks::toAssigneeQuery);
}
private AccountLinkPanel(AccountInfo ai,
Function<String, String> nameToQuery) {
addStyleName(Gerrit.RESOURCES.css().accountLinkPanel()); addStyleName(Gerrit.RESOURCES.css().accountLinkPanel());
InlineHyperlink l = InlineHyperlink l =
new InlineHyperlink(FormatUtil.name(info), PageLinks.toAccountQuery( new InlineHyperlink(
owner(info), status)) { FormatUtil.name(ai),
nameToQuery.apply(name(ai))) {
@Override @Override
public void go() { public void go() {
Gerrit.display(getTargetHistoryToken()); Gerrit.display(getTargetHistoryToken());
} }
}; };
l.setTitle(FormatUtil.nameEmail(info)); l.setTitle(FormatUtil.nameEmail(ai));
add(new AvatarImage(info)); add(new AvatarImage(ai));
add(l); add(l);
} }
public static String owner(AccountInfo ai) { private static String name(AccountInfo ai) {
if (ai.email() != null) { if (ai.email() != null) {
return ai.email(); return ai.email();
} else if (ai.name() != null) { } else if (ai.name() != null) {

View File

@@ -1,53 +0,0 @@
// Copyright (C) 2016 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.ui;
import com.google.gerrit.client.AvatarImage;
import com.google.gerrit.client.FormatUtil;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.info.AccountInfo;
import com.google.gerrit.common.PageLinks;
import com.google.gwt.user.client.ui.FlowPanel;
/** Link to any assignees accounts dashboard. */
public class AssigneeLinkPanel extends FlowPanel {
public AssigneeLinkPanel(AccountInfo info) {
addStyleName(Gerrit.RESOURCES.css().accountLinkPanel());
InlineHyperlink l =
new InlineHyperlink(FormatUtil.name(info), PageLinks.toAssigneeQuery(
assignedTo(info))) {
@Override
public void go() {
Gerrit.display(getTargetHistoryToken());
}
};
l.setTitle(FormatUtil.nameEmail(info));
add(new AvatarImage(info));
add(l);
}
public static String assignedTo(AccountInfo ai) {
if (ai.email() != null) {
return ai.email();
} else if (ai.name() != null) {
return ai.name();
} else {
return "";
}
}
}