Create a link utility to jump to an account dashboard

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2008-12-04 11:43:31 -08:00
parent ea18481c37
commit 25ea21c4f0
4 changed files with 112 additions and 16 deletions

View File

@@ -0,0 +1,51 @@
// Copyright 2008 Google Inc.
//
// 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.account;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.Link;
import com.google.gerrit.client.changes.AccountDashboardScreen;
import com.google.gerrit.client.data.AccountInfo;
import com.google.gerrit.client.ui.DirectScreenLink;
import com.google.gerrit.client.ui.Screen;
/** Link to any user's account dashboard. */
public class AccountDashboardLink extends DirectScreenLink {
private static String name(final AccountInfo ai) {
if (ai.getFullName() != null) {
return ai.getFullName();
}
if (ai.getPreferredEmail() != null) {
return ai.getPreferredEmail();
}
return Gerrit.C.anonymousCoward();
}
private AccountInfo account;
public AccountDashboardLink(final AccountInfo ai) {
this(name(ai), ai);
}
public AccountDashboardLink(final String text, final AccountInfo ai) {
super(text, Link.toAccountDashboard(ai));
account = ai;
}
@Override
protected Screen createScreen() {
return new AccountDashboardScreen(account.getId());
}
}

View File

@@ -14,15 +14,12 @@
package com.google.gerrit.client.changes; package com.google.gerrit.client.changes;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.Link; import com.google.gerrit.client.Link;
import com.google.gerrit.client.data.ChangeInfo; import com.google.gerrit.client.data.ChangeInfo;
import com.google.gwt.user.client.DOM; import com.google.gerrit.client.ui.DirectScreenLink;
import com.google.gwt.user.client.Event; import com.google.gerrit.client.ui.Screen;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Hyperlink;
public class ChangeLink extends Hyperlink { public class ChangeLink extends DirectScreenLink {
private ChangeInfo change; private ChangeInfo change;
public ChangeLink(final String text, final ChangeInfo c) { public ChangeLink(final String text, final ChangeInfo c) {
@@ -31,11 +28,7 @@ public class ChangeLink extends Hyperlink {
} }
@Override @Override
public void onBrowserEvent(final Event event) { protected Screen createScreen() {
if (DOM.eventGetType(event) == Event.ONCLICK) { return new ChangeScreen(change);
History.newItem(getTargetHistoryToken(), false);
Gerrit.display(new ChangeScreen(change));
DOM.eventPreventDefault(event);
}
} }
} }

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.client.changes;
import com.google.gerrit.client.Gerrit; import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.Link; import com.google.gerrit.client.Link;
import com.google.gerrit.client.SignedInListener; import com.google.gerrit.client.SignedInListener;
import com.google.gerrit.client.account.AccountDashboardLink;
import com.google.gerrit.client.data.ChangeInfo; import com.google.gerrit.client.data.ChangeInfo;
import com.google.gerrit.client.reviewdb.Change; import com.google.gerrit.client.reviewdb.Change;
import com.google.gerrit.client.rpc.GerritCallback; import com.google.gerrit.client.rpc.GerritCallback;
@@ -32,7 +33,6 @@ import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FocusListener; import com.google.gwt.user.client.ui.FocusListener;
import com.google.gwt.user.client.ui.FocusPanel; import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HasFocus; import com.google.gwt.user.client.ui.HasFocus;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.KeyboardListener; import com.google.gwt.user.client.ui.KeyboardListener;
import com.google.gwt.user.client.ui.KeyboardListenerAdapter; import com.google.gwt.user.client.ui.KeyboardListenerAdapter;
@@ -356,9 +356,7 @@ public class ChangeTable extends Composite implements HasFocus {
s += " (" + c.getStatus().name() + ")"; s += " (" + c.getStatus().name() + ")";
} }
table.setWidget(row, C_SUBJECT, new ChangeLink(s, c)); table.setWidget(row, C_SUBJECT, new ChangeLink(s, c));
table.setWidget(row, C_OWNER, new AccountDashboardLink(c.getOwner()));
table.setWidget(row, C_OWNER, new Hyperlink(c.getOwner().getFullName(),
Link.toAccountDashboard(c.getOwner())));
table.setText(row, C_REVIEWERS, "TODO"); table.setText(row, C_REVIEWERS, "TODO");
table.setText(row, C_PROJECT, c.getProject().getName()); table.setText(row, C_PROJECT, c.getProject().getName());
table.setText(row, C_LAST_UPDATE, "TODO"); table.setText(row, C_LAST_UPDATE, "TODO");

View File

@@ -0,0 +1,54 @@
// Copyright 2008 Google Inc.
//
// 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.Gerrit;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Hyperlink;
/**
* Link to a Screen which can carry richer payload.
* <p>
* A standard Hyperlink widget which updates the current history token when
* activated, but subclasses are able to create the Screen instance themselves,
* passing additional data into the Screen's constructor. This may permit the
* screen to show some limited information early, before RPCs required to fully
* populate it are even started.
*/
public abstract class DirectScreenLink extends Hyperlink {
/**
* Creates a link with its text and target history token specified.
*
* @param text the hyperlink's text
* @param historyToken the history token to which it will link
*/
protected DirectScreenLink(final String text, final String historyToken) {
super(text, historyToken);
}
@Override
public void onBrowserEvent(final Event event) {
if (DOM.eventGetType(event) == Event.ONCLICK) {
History.newItem(getTargetHistoryToken(), false);
Gerrit.display(createScreen());
DOM.eventPreventDefault(event);
}
}
/** Create the screen this link wants to display. */
protected abstract Screen createScreen();
}