Make hyperlinks update URL when screen is visible

Instead of updating the URL to the screen and then loading the RPCs,
update the URL after the RPCs are complete and the screen is going
to be made visible to the user.  This allows us to behave similar
to the way Gmail reacts, which is to avoid the URL update until the
data you are viewing matches the URL.

Change-Id: Iadde8240d506e3a51b9f064ecfa5fb91045616f5
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-12-30 09:33:11 -08:00
parent 08ba0c6817
commit 53eae8cdd3
32 changed files with 303 additions and 146 deletions

View File

@@ -50,6 +50,7 @@ import com.google.gerrit.client.changes.PatchTable;
import com.google.gerrit.client.changes.PublishCommentScreen;
import com.google.gerrit.client.patches.PatchScreen;
import com.google.gerrit.client.ui.Screen;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.auth.SignInMode;
import com.google.gerrit.reviewdb.Account;
import com.google.gerrit.reviewdb.AccountGroup;
@@ -60,11 +61,9 @@ import com.google.gerrit.reviewdb.Project;
import com.google.gerrit.reviewdb.Change.Status;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwtorm.client.KeyUtil;
public class HistoryHandler implements ValueChangeHandler<String> {
public class Dispatcher {
public static String toPatchSideBySide(final Patch.Key id) {
return toPatch("sidebyside", id);
}
@@ -100,34 +99,31 @@ public class HistoryHandler implements ValueChangeHandler<String> {
}
}
public void onValueChange(final ValueChangeEvent<String> event) {
final String token = event.getValue();
void display(final String token) {
assert token != null;
try {
select(token);
} catch (RuntimeException err) {
GWT.log("Error parsing history token: " + token, err);
Gerrit.display(new NotFoundScreen());
Gerrit.display(token, new NotFoundScreen());
}
}
private static void select(final String token) {
if (token == null) {
Gerrit.display(new NotFoundScreen());
} else if (token.startsWith("patch,")) {
if (token.startsWith("patch,")) {
patch(token, null, 0, null);
} else if (token.startsWith("change,publish,")) {
publish(token);
} else if (MINE.equals(token) || token.startsWith("mine,")) {
Gerrit.display(mine(token));
Gerrit.display(token, mine(token));
} else if (token.startsWith("all,")) {
Gerrit.display(all(token));
Gerrit.display(token, all(token));
} else if (token.startsWith("project,")) {
Gerrit.display(project(token));
Gerrit.display(token, project(token));
} else if (SETTINGS.equals(token) //
|| REGISTER.equals(token) //
@@ -141,7 +137,7 @@ public class HistoryHandler implements ValueChangeHandler<String> {
admin(token);
} else {
Gerrit.display(core(token));
Gerrit.display(token, core(token));
}
}
@@ -240,7 +236,7 @@ public class HistoryHandler implements ValueChangeHandler<String> {
private static void publish(final String token) {
new RunAsyncCallback() {
public void onSuccess() {
Gerrit.display(select());
Gerrit.display(token, select());
}
private Screen select() {
@@ -260,7 +256,7 @@ public class HistoryHandler implements ValueChangeHandler<String> {
final int patchIndex, final PatchTable patchTable) {
GWT.runAsync(new RunAsyncCallback() {
public void onSuccess() {
Gerrit.display(select());
Gerrit.display(token, select());
}
private Screen select() {
@@ -296,7 +292,7 @@ public class HistoryHandler implements ValueChangeHandler<String> {
private static void settings(final String token) {
GWT.runAsync(new RunAsyncCallback() {
public void onSuccess() {
Gerrit.display(select());
Gerrit.display(token, select());
}
private Screen select() {
@@ -318,12 +314,13 @@ public class HistoryHandler implements ValueChangeHandler<String> {
final String[] args = skip(p, token).split(",");
final SignInMode mode = SignInMode.valueOf(args[0]);
final String msg = KeyUtil.decode(args[1]);
final String to = PageLinks.MINE;
switch (Gerrit.getConfig().getAuthType()) {
case OPENID:
new OpenIdSignInDialog(mode, msg).center();
new OpenIdSignInDialog(mode, to, msg).center();
break;
case LDAP:
new UserPassSignInDialog(msg).center();
new UserPassSignInDialog(to, msg).center();
break;
default:
return null;
@@ -356,7 +353,7 @@ public class HistoryHandler implements ValueChangeHandler<String> {
private static void admin(final String token) {
GWT.runAsync(new RunAsyncCallback() {
public void onSuccess() {
Gerrit.display(select());
Gerrit.display(token, select());
}
private Screen select() {

View File

@@ -60,7 +60,8 @@ import java.util.ArrayList;
public class Gerrit implements EntryPoint {
public static final GerritConstants C = GWT.create(GerritConstants.class);
public static final GerritMessages M = GWT.create(GerritMessages.class);
public static final GerritResources RESOURCES = GWT.create(GerritResources.class);
public static final GerritResources RESOURCES =
GWT.create(GerritResources.class);
public static final SystemInfoService SYSTEM_SVC;
private static String myHost;
@@ -73,6 +74,7 @@ public class Gerrit implements EntryPoint {
private static RootPanel siteHeader;
private static RootPanel siteFooter;
private static SearchPanel searchPanel;
private static final Dispatcher dispatcher = new Dispatcher();
private static ViewSite<Screen> body;
static {
@@ -80,29 +82,65 @@ public class Gerrit implements EntryPoint {
JsonUtil.bind(SYSTEM_SVC, "rpc/SystemInfoService");
}
public static void display(final String historyToken, final boolean go) {
History.newItem(historyToken, go);
if (!go && historyHooks != null) {
dispatchHistoryHooks(historyToken);
/**
* Load the screen at the given location, displaying when ready.
* <p>
* If the URL is not already pointing at this location, a new item will be
* added to the browser's history when the screen is fully loaded and
* displayed on the UI.
*
* @param token location to parse, load, and render.
*/
public static void display(final String token) {
if (body.getView() == null || !body.getView().displayToken(token)) {
dispatcher.display(token);
}
}
public static void display(final String historyToken, final Screen view) {
History.newItem(historyToken, false);
display(view);
if (historyHooks != null) {
dispatchHistoryHooks(historyToken);
}
}
public static void display(final Screen view) {
/**
* Load the screen passed, assuming token can be used to locate it.
* <p>
* The screen is loaded in the background. When it is ready to be visible a
* new item will be added to the browser's history, the screen will be made
* visible, and the window title may be updated.
* <p>
* If {@link Screen#isRequiresSignIn()} is true and the user is not signed in
* yet the screen instance will be discarded, sign-in will take place, and
* will redirect to this location upon success.
*
* @param token location that refers to {@code view}.
* @param view the view to load.
*/
public static void display(final String token, final Screen view) {
if (view.isRequiresSignIn() && !isSignedIn()) {
doSignIn();
doSignIn(token);
} else {
view.setToken(token);
body.setView(view);
}
}
/**
* Update the current history token after a screen change.
* <p>
* The caller has already updated the UI, but wants to publish a different
* history token for the current browser state. This really only makes sense
* if the caller is a {@code TabPanel} and is firing an event when the tab
* changed to a different part.
*
* @param token new location that is already visible.
*/
public static void updateImpl(final String token) {
History.newItem(token, false);
if (historyHooks != null) {
// Because we blocked firing the event our history hooks won't be
// informed of the current token. Manually fire the event to them.
//
dispatchHistoryHooks(token);
}
}
public static void setQueryString(String query) {
searchPanel.setText(query);
}
@@ -133,11 +171,11 @@ public class Gerrit implements EntryPoint {
}
/** Sign the user into the application. */
public static void doSignIn() {
public static void doSignIn(final String token) {
switch (myConfig.getAuthType()) {
case HTTP:
case HTTP_LDAP:
Location.assign(Location.getPath() + "login/" + History.getToken());
Location.assign(Location.getPath() + "login/" + token);
break;
case DEVELOPMENT_BECOME_ANY_ACCOUNT:
@@ -145,11 +183,11 @@ public class Gerrit implements EntryPoint {
break;
case OPENID:
new OpenIdSignInDialog(SignInMode.SIGN_IN, null).center();
new OpenIdSignInDialog(SignInMode.SIGN_IN, token, null).center();
break;
case LDAP:
new UserPassSignInDialog(null).center();
new UserPassSignInDialog(token, null).center();
break;
}
}
@@ -198,6 +236,13 @@ public class Gerrit implements EntryPoint {
body = new ViewSite<Screen>() {
@Override
protected void onShowView(Screen view) {
final String token = view.getToken();
if (!token.equals(History.getToken())) {
History.newItem(token, false);
if (historyHooks != null) {
dispatchHistoryHooks(token);
}
}
super.onShowView(view);
view.onShowView();
}
@@ -302,17 +347,21 @@ public class Gerrit implements EntryPoint {
starting.getElement().getParentElement().removeChild(starting.getElement());
RootPanel.detachNow(starting);
History.addValueChangeHandler(new HistoryHandler());
History.addValueChangeHandler(new ValueChangeHandler<String>() {
public void onValueChange(final ValueChangeEvent<String> event) {
display(event.getValue());
}
});
JumpKeys.register(body);
if ("".equals(History.getToken())) {
if (isSignedIn()) {
History.newItem(PageLinks.MINE);
display(PageLinks.MINE);
} else {
History.newItem(PageLinks.ALL_OPEN);
display(PageLinks.ALL_OPEN);
}
} else {
History.fireCurrentHistoryState();
display(History.getToken());
}
}
@@ -361,12 +410,13 @@ public class Gerrit implements EntryPoint {
case OPENID:
menuRight.addItem(C.menuRegister(), new Command() {
public void execute() {
new OpenIdSignInDialog(SignInMode.REGISTER, null).center();
final String to = History.getToken();
new OpenIdSignInDialog(SignInMode.REGISTER, to, null).center();
}
});
menuRight.addItem(C.menuSignIn(), new Command() {
public void execute() {
doSignIn();
doSignIn(History.getToken());
}
});
break;
@@ -377,7 +427,7 @@ public class Gerrit implements EntryPoint {
}
menuRight.addItem(C.menuSignIn(), new Command() {
public void execute() {
doSignIn();
doSignIn(History.getToken());
}
});
break;

View File

@@ -29,13 +29,13 @@ class JumpKeys {
jumps.add(new KeyCommand(0, 'o', Gerrit.C.jumpAllOpen()) {
@Override
public void onKeyPress(final KeyPressEvent event) {
Gerrit.display(PageLinks.ALL_OPEN, true);
Gerrit.display(PageLinks.ALL_OPEN);
}
});
jumps.add(new KeyCommand(0, 'm', Gerrit.C.jumpAllMerged()) {
@Override
public void onKeyPress(final KeyPressEvent event) {
Gerrit.display(PageLinks.ALL_MERGED, true);
Gerrit.display(PageLinks.ALL_MERGED);
}
});
@@ -43,19 +43,19 @@ class JumpKeys {
jumps.add(new KeyCommand(0, 'i', Gerrit.C.jumpMine()) {
@Override
public void onKeyPress(final KeyPressEvent event) {
Gerrit.display(PageLinks.MINE, true);
Gerrit.display(PageLinks.MINE);
}
});
jumps.add(new KeyCommand(0, 'd', Gerrit.C.jumpMineDrafts()) {
@Override
public void onKeyPress(final KeyPressEvent event) {
Gerrit.display(PageLinks.MINE_DRAFTS, true);
Gerrit.display(PageLinks.MINE_DRAFTS);
}
});
jumps.add(new KeyCommand(0, 's', Gerrit.C.jumpMineStarred()) {
@Override
public void onKeyPress(final KeyPressEvent event) {
Gerrit.display(PageLinks.MINE_STARRED, true);
Gerrit.display(PageLinks.MINE_STARRED);
}
});
}

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.client;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
@@ -36,7 +37,7 @@ public class NotSignedInDialog extends AutoCenterDialogBox {
@Override
public void onClick(ClickEvent event) {
hide();
Gerrit.doSignIn();
Gerrit.doSignIn(History.getToken());
}
});
buttons.add(signin);

View File

@@ -136,10 +136,9 @@ class SearchPanel extends Composite {
searchBox.setFocus(false);
if (query.matches("^[1-9][0-9]*$")) {
final Change.Id ck = Change.Id.parse(query);
Gerrit.display(PageLinks.toChange(ck), new ChangeScreen(ck));
Gerrit.display(PageLinks.toChange(Change.Id.parse(query)));
} else {
Gerrit.display(PageLinks.toChangeQuery(query), true);
Gerrit.display(PageLinks.toChangeQuery(query));
}
}
}

View File

@@ -20,15 +20,18 @@ import com.google.gwtexpui.user.client.AutoCenterDialogBox;
/** Prompts the user to sign in to their account. */
public abstract class SignInDialog extends AutoCenterDialogBox {
protected final SignInMode mode;
protected final String token;
/**
* Create a new dialog to handle user sign in.
*
* @param signInMode type of mode the login will perform.
* @param token the token to jump to after sign-in is complete.
*/
protected SignInDialog(final SignInMode signInMode) {
protected SignInDialog(final SignInMode signInMode, final String token) {
super(/* auto hide */true, /* modal */true);
mode = signInMode;
this.mode = signInMode;
this.token = token;
switch (signInMode) {
case LINK_IDENTIY:

View File

@@ -43,6 +43,18 @@ public class AccountSettings extends AccountScreen {
initialTabToken = tabToken;
}
@Override
public boolean displayToken(String token) {
final int tabIdx = tabTokens.indexOf(token);
if (0 <= tabIdx) {
tabs.selectTab(tabIdx);
setToken(token);
return true;
} else {
return false;
}
}
@Override
protected void onLoad() {
super.onLoad();
@@ -149,14 +161,15 @@ public class AccountSettings extends AccountScreen {
tabs.addSelectionHandler(new SelectionHandler<Integer>() {
@Override
public void onSelection(final SelectionEvent<Integer> event) {
Gerrit.display(tabTokens.get(event.getSelectedItem()), false);
setToken(tabTokens.get(event.getSelectedItem()));
}
});
}
private void infoRow(final int row, final String name) {
info.setText(row, labelIdx, name);
info.getCellFormatter().addStyleName(row, 0, Gerrit.RESOURCES.css().header());
info.getCellFormatter().addStyleName(row, 0,
Gerrit.RESOURCES.css().header());
}
void display(final Account account) {

View File

@@ -27,7 +27,7 @@ import com.google.gerrit.reviewdb.ContributorAgreement;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gerrit.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwtexpui.safehtml.client.SafeHtml;
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;

View File

@@ -24,6 +24,7 @@ import com.google.gerrit.common.auth.openid.OpenIdUrls;
import com.google.gerrit.reviewdb.AccountExternalId;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
@@ -61,7 +62,8 @@ class ExternalIdPanel extends Composite {
linkIdentity.addClickHandler(new ClickHandler() {
@Override
public void onClick(final ClickEvent event) {
new OpenIdSignInDialog(SignInMode.LINK_IDENTIY, null).center();
final String to = History.getToken();
new OpenIdSignInDialog(SignInMode.LINK_IDENTIY, to, null).center();
}
});
body.add(linkIdentity);

View File

@@ -218,7 +218,7 @@ public class NewAgreementScreen extends AccountScreen {
Util.ACCOUNT_SEC.enterAgreement(current.getId(),
new GerritCallback<VoidResult>() {
public void onSuccess(final VoidResult result) {
Gerrit.display(nextToken, true);
Gerrit.display(nextToken);
}
@Override

View File

@@ -22,7 +22,7 @@ import com.google.gerrit.reviewdb.Account;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.InlineHyperlink;
import com.google.gerrit.client.ui.InlineHyperlink;
public class RegisterScreen extends AccountScreen {
private final String nextToken;

View File

@@ -14,10 +14,10 @@
package com.google.gerrit.client.account;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.rpc.ScreenLoadCallback;
import com.google.gerrit.client.ui.AccountScreen;
import com.google.gerrit.common.PageLinks;
import com.google.gwt.user.client.History;
import com.google.gwtjsonrpc.client.VoidResult;
public class ValidateEmailScreen extends AccountScreen {
@@ -44,7 +44,7 @@ public class ValidateEmailScreen extends AccountScreen {
@Override
protected void postDisplay() {
History.newItem(PageLinks.SETTINGS_CONTACT, true);
Gerrit.display(PageLinks.SETTINGS_CONTACT);
}
});
}

View File

@@ -15,7 +15,7 @@
package com.google.gerrit.client.admin;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.HistoryHandler;
import com.google.gerrit.client.Dispatcher;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.rpc.ScreenLoadCallback;
import com.google.gerrit.client.ui.AccountScreen;
@@ -91,7 +91,7 @@ public class GroupListScreen extends AccountScreen {
Util.GROUP_SVC.createGroup(newName, new GerritCallback<AccountGroup.Id>() {
public void onSuccess(final AccountGroup.Id result) {
History.newItem(HistoryHandler.toAccountGroup(result));
History.newItem(Dispatcher.toAccountGroup(result));
}
});
}

View File

@@ -15,14 +15,14 @@
package com.google.gerrit.client.admin;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.HistoryHandler;
import com.google.gerrit.client.Dispatcher;
import com.google.gerrit.client.ui.NavigationTable;
import com.google.gerrit.reviewdb.AccountGroup;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gerrit.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.client.ui.HTMLTable.Cell;
@@ -71,7 +71,7 @@ public class GroupTable extends NavigationTable<AccountGroup> {
@Override
protected void onOpenRow(final int row) {
History.newItem(HistoryHandler.toAccountGroup(getRowItem(row).getId()));
History.newItem(Dispatcher.toAccountGroup(getRowItem(row).getId()));
}
public void display(final List<AccountGroup> result) {
@@ -88,7 +88,7 @@ public class GroupTable extends NavigationTable<AccountGroup> {
void populate(final int row, final AccountGroup k) {
if (enableLink) {
table.setWidget(row, 1, new Hyperlink(k.getName(), HistoryHandler.toAccountGroup(k
table.setWidget(row, 1, new Hyperlink(k.getName(), Dispatcher.toAccountGroup(k
.getId())));
} else {
table.setText(row, 1, k.getName());

View File

@@ -14,8 +14,8 @@
package com.google.gerrit.client.admin;
import com.google.gerrit.client.Dispatcher;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.HistoryHandler;
import com.google.gerrit.client.rpc.ScreenLoadCallback;
import com.google.gerrit.client.ui.AccountScreen;
import com.google.gerrit.common.data.ProjectDetail;
@@ -44,6 +44,18 @@ public class ProjectAdminScreen extends AccountScreen {
initialTabToken = token;
}
@Override
public boolean displayToken(String token) {
final int tabIdx = tabTokens.indexOf(token);
if (0 <= tabIdx) {
tabs.selectTab(tabIdx);
setToken(token);
return true;
} else {
return false;
}
}
@Override
protected void onLoad() {
super.onLoad();
@@ -71,7 +83,7 @@ public class ProjectAdminScreen extends AccountScreen {
return new ProjectInfoPanel(projectName);
}
}, Util.C.projectAdminTabGeneral());
tabTokens.add(HistoryHandler.toProjectAdmin(projectName, INFO_TAB));
tabTokens.add(Dispatcher.toProjectAdmin(projectName, INFO_TAB));
if (!Gerrit.getConfig().getWildProject().equals(projectName)) {
tabs.add(new LazyPanel() {
@@ -80,7 +92,7 @@ public class ProjectAdminScreen extends AccountScreen {
return new ProjectBranchesPanel(projectName);
}
}, Util.C.projectAdminTabBranches());
tabTokens.add(HistoryHandler.toProjectAdmin(projectName, BRANCH_TAB));
tabTokens.add(Dispatcher.toProjectAdmin(projectName, BRANCH_TAB));
}
tabs.add(new LazyPanel() {
@@ -89,12 +101,12 @@ public class ProjectAdminScreen extends AccountScreen {
return new ProjectRightsPanel(projectName);
}
}, Util.C.projectAdminTabAccess());
tabTokens.add(HistoryHandler.toProjectAdmin(projectName, ACCESS_TAB));
tabTokens.add(Dispatcher.toProjectAdmin(projectName, ACCESS_TAB));
tabs.addSelectionHandler(new SelectionHandler<Integer>() {
@Override
public void onSelection(final SelectionEvent<Integer> event) {
Gerrit.display(tabTokens.get(event.getSelectedItem()), false);
setToken(tabTokens.get(event.getSelectedItem()));
}
});
}

View File

@@ -15,7 +15,7 @@
package com.google.gerrit.client.admin;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.HistoryHandler;
import com.google.gerrit.client.Dispatcher;
import com.google.gerrit.client.rpc.ScreenLoadCallback;
import com.google.gerrit.client.ui.AccountScreen;
import com.google.gerrit.client.ui.NavigationTable;
@@ -26,7 +26,7 @@ import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gerrit.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.client.ui.HTMLTable.Cell;
@@ -105,7 +105,7 @@ public class ProjectListScreen extends AccountScreen {
}
private String link(final Project item) {
return HistoryHandler.toProjectAdmin(item.getNameKey(), ProjectAdminScreen.INFO_TAB);
return Dispatcher.toProjectAdmin(item.getNameKey(), ProjectAdminScreen.INFO_TAB);
}
void display(final List<Project> result) {

View File

@@ -31,7 +31,6 @@ import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
@@ -67,9 +66,9 @@ public class OpenIdSignInDialog extends SignInDialog implements
private CheckBox rememberId;
private boolean discovering;
public OpenIdSignInDialog(final SignInMode requestedMode,
public OpenIdSignInDialog(final SignInMode requestedMode, final String token,
final String initialErrorMsg) {
super(requestedMode);
super(requestedMode, token);
formBody = new FlowPanel();
formBody.setStyleName(OpenIdResources.I.css().loginForm());
@@ -94,8 +93,10 @@ public class OpenIdSignInDialog extends SignInDialog implements
createErrorBox();
createIdentBox();
link(OpenIdUrls.URL_GOOGLE, OpenIdUtil.C.nameGoogle(), OpenIdResources.I.iconGoogle());
link(OpenIdUrls.URL_YAHOO, OpenIdUtil.C.nameYahoo(), OpenIdResources.I.iconYahoo());
link(OpenIdUrls.URL_GOOGLE, OpenIdUtil.C.nameGoogle(), OpenIdResources.I
.iconGoogle());
link(OpenIdUrls.URL_YAHOO, OpenIdUtil.C.nameYahoo(), OpenIdResources.I
.iconYahoo());
if (initialErrorMsg != null) {
showError(initialErrorMsg);
@@ -313,7 +314,6 @@ public class OpenIdSignInDialog extends SignInDialog implements
hideError();
final boolean remember = rememberId != null && rememberId.getValue();
final String token = History.getToken();
OpenIdUtil.SVC.discover(openidIdentifier, mode, remember, token,
new GerritCallback<DiscoveryResult>() {
public void onSuccess(final DiscoveryResult result) {

View File

@@ -29,7 +29,6 @@ import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window.Location;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
@@ -55,8 +54,8 @@ public class UserPassSignInDialog extends SignInDialog {
private TextBox username;
private TextBox password;
public UserPassSignInDialog(final String initialErrorMsg) {
super(SignInMode.SIGN_IN);
public UserPassSignInDialog(final String token, final String initialErrorMsg) {
super(SignInMode.SIGN_IN, token);
formBody = new FlowPanel();
formBody.setStyleName(UserPassResources.I.css().loginForm());
@@ -199,9 +198,9 @@ public class UserPassSignInDialog extends SignInDialog {
Util.SVC.authenticate(user, pass, new GerritCallback<LoginResult>() {
public void onSuccess(final LoginResult result) {
if (result.success) {
String token = History.getToken();
if (result.isNew && !token.startsWith(PageLinks.REGISTER + ",")) {
token = PageLinks.REGISTER + "," + token;
String to = token;
if (result.isNew && !to.startsWith(PageLinks.REGISTER + ",")) {
to = PageLinks.REGISTER + "," + to;
}
// Unfortunately we no longer support updating the web UI when the
@@ -209,7 +208,7 @@ public class UserPassSignInDialog extends SignInDialog {
// that isn't easy because we might need to change the anchor. So
// we bounce through a little redirection servlet on the server.
//
Location.replace(Location.getPath() + "login/" + token);
Location.replace(Location.getPath() + "login/" + to);
} else {
showError(Util.C.invalidLogin());
enable(true);

View File

@@ -24,7 +24,7 @@ import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gerrit.client.ui.Hyperlink;
import com.google.gwtexpui.globalkey.client.KeyCommand;
import java.util.List;

View File

@@ -370,9 +370,9 @@ public class ChangeScreen extends Screen {
@Override
public void onKeyPress(final KeyPressEvent event) {
if (Gerrit.isSignedIn()) {
Gerrit.display(PageLinks.MINE, true);
Gerrit.display(PageLinks.MINE);
} else {
Gerrit.display(PageLinks.ALL_OPEN, true);
Gerrit.display(PageLinks.ALL_OPEN);
}
}
}

View File

@@ -16,7 +16,7 @@ package com.google.gerrit.client.changes;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.patches.PatchScreen;
import com.google.gerrit.client.ui.DirectScreenLink;
import com.google.gerrit.client.ui.InlineHyperlink;
import com.google.gerrit.client.ui.NavigationTable;
import com.google.gerrit.client.ui.PatchLink;
import com.google.gerrit.reviewdb.Patch;
@@ -102,7 +102,7 @@ public class PatchTable extends Composite {
/**
* @return a link to the previous file in this patch set, or null.
*/
public DirectScreenLink getPreviousPatchLink(int index, PatchScreen.Type patchType) {
public InlineHyperlink getPreviousPatchLink(int index, PatchScreen.Type patchType) {
if (0 < index)
return createLink(index - 1, patchType, SafeHtml.asis(Util.C
.prevPatchLinkIcon()), null);
@@ -112,7 +112,7 @@ public class PatchTable extends Composite {
/**
* @return a link to the next file in this patch set, or null.
*/
public DirectScreenLink getNextPatchLink(int index, PatchScreen.Type patchType) {
public InlineHyperlink getNextPatchLink(int index, PatchScreen.Type patchType) {
if (index < patchList.size() - 1)
return createLink(index + 1, patchType, null, SafeHtml.asis(Util.C
.nextPatchLinkIcon()));
@@ -457,8 +457,8 @@ public class PatchTable extends Composite {
if (link instanceof FlowPanel) {
link = ((FlowPanel) link).getWidget(0);
}
if (link instanceof DirectScreenLink) {
((DirectScreenLink) link).go();
if (link instanceof InlineHyperlink) {
((InlineHyperlink) link).go();
}
}
}

View File

@@ -37,6 +37,7 @@ import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.UIObject;
@@ -310,7 +311,7 @@ public abstract class AbstractPatchContentTable extends NavigationTable<Object>
}
if (!Gerrit.isSignedIn()) {
Gerrit.doSignIn();
Gerrit.doSignIn(History.getToken());
return;
}

View File

@@ -18,13 +18,13 @@ import static com.google.gerrit.reviewdb.AccountGeneralPreferences.DEFAULT_CONTE
import static com.google.gerrit.reviewdb.AccountGeneralPreferences.WHOLE_FILE_CONTEXT;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.HistoryHandler;
import com.google.gerrit.client.Dispatcher;
import com.google.gerrit.client.changes.ChangeScreen;
import com.google.gerrit.client.changes.PatchTable;
import com.google.gerrit.client.changes.Util;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.ui.ChangeLink;
import com.google.gerrit.client.ui.DirectScreenLink;
import com.google.gerrit.client.ui.InlineHyperlink;
import com.google.gerrit.client.ui.Screen;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.data.CommentDetail;
@@ -144,10 +144,10 @@ public abstract class PatchScreen extends Screen {
private HandlerRegistration regNavigation;
/** Link to the screen for the previous file, null if not applicable */
private DirectScreenLink previousFileLink;
private InlineHyperlink previousFileLink;
/** Link to the screen for the next file, null if not applicable */
private DirectScreenLink nextFileLink;
private InlineHyperlink nextFileLink;
private static final char SHORTCUT_PREVIOUS_FILE = '[';
private static final char SHORTCUT_NEXT_FILE = ']';
@@ -244,7 +244,7 @@ public abstract class PatchScreen extends Screen {
}
}
private void installLinkShortCut(final DirectScreenLink link, char shortcut,
private void installLinkShortCut(final InlineHyperlink link, char shortcut,
String help) {
keysNavigation.add(new KeyCommand(0, shortcut, help) {
@Override
@@ -483,7 +483,7 @@ public abstract class PatchScreen extends Screen {
contentTable = new UnifiedDiffTable();
contentTable.fileList = fileList;
contentPanel.add(contentTable);
History.newItem(HistoryHandler.toPatchUnified(patchKey), false);
setToken(Dispatcher.toPatchUnified(patchKey));
}
if (hasDifferences) {

View File

@@ -43,7 +43,7 @@ public abstract class ScreenLoadCallback<T> extends GerritCallback<T> {
@Override
public void onFailure(final Throwable caught) {
if (isNoSuchEntity(caught)) {
Gerrit.display(new NotFoundScreen());
Gerrit.display(screen.getToken(), new NotFoundScreen());
} else {
super.onFailure(caught);
}

View File

@@ -23,7 +23,7 @@ import com.google.gerrit.common.data.AccountInfoCache;
import com.google.gerrit.reviewdb.Account;
/** Link to any user's account dashboard. */
public class AccountDashboardLink extends DirectScreenLink {
public class AccountDashboardLink extends InlineHyperlink {
/** Create a link after locating account details from an active cache. */
public static AccountDashboardLink link(final AccountInfoCache cache,
final Account.Id id) {

View File

@@ -22,7 +22,7 @@ import com.google.gerrit.reviewdb.Change;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
public class ChangeLink extends DirectScreenLink {
public class ChangeLink extends InlineHyperlink {
public static String permalink(final Change.Id c) {
return GWT.getHostPageBaseURL() + c.get();
}

View File

@@ -0,0 +1,65 @@
// Copyright (C) 2008 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.Gerrit;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.impl.HyperlinkImpl;
/** Standard GWT hyperlink with late updating of the token. */
public class Hyperlink extends com.google.gwt.user.client.ui.Hyperlink {
static final HyperlinkImpl impl = GWT.create(HyperlinkImpl.class);
/**
* Creates a hyperlink with its text and target history token specified.
*
* @param text the hyperlink's text
* @param token the history token to which it will link, which may not be null
* (use {@link Anchor} instead if you don't need history processing)
*/
public Hyperlink(final String text, final String token) {
super(text, token);
}
/**
* Creates a hyperlink with its text and target history token specified.
*
* @param text the hyperlink's text
* @param asHTML <code>true</code> to treat the specified text as html
* @param token the history token to which it will link
* @see #setTargetHistoryToken
*/
public Hyperlink(String text, boolean asHTML, String token) {
super(text, asHTML, token);
}
@Override
public void onBrowserEvent(final Event event) {
if (DOM.eventGetType(event) == Event.ONCLICK && impl.handleAsClick(event)) {
DOM.eventPreventDefault(event);
go();
} else {
super.onBrowserEvent(event);
}
}
/** Create the screen and start rendering, updating the browser history. */
public void go() {
Gerrit.display(getTargetHistoryToken());
}
}

View File

@@ -14,30 +14,23 @@
package com.google.gerrit.client.ui;
import static com.google.gerrit.client.ui.LinkMenuItem.impl;
import static com.google.gerrit.client.ui.Hyperlink.impl;
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.ui.InlineHyperlink;
/**
* 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 InlineHyperlink {
/** Standard GWT hyperlink with late updating of the token. */
public class InlineHyperlink extends
com.google.gwt.user.client.ui.InlineHyperlink {
/**
* 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
* @param token the history token to which it will link
*/
protected DirectScreenLink(final String text, final String historyToken) {
super(text, historyToken);
public InlineHyperlink(final String text, final String token) {
super(text, token);
}
@Override
@@ -45,9 +38,13 @@ public abstract class DirectScreenLink extends InlineHyperlink {
if (DOM.eventGetType(event) == Event.ONCLICK && impl.handleAsClick(event)) {
DOM.eventPreventDefault(event);
go();
} else {
super.onBrowserEvent(event);
}
}
/** Create the screen and start rendering, updating the browser history. */
public abstract void go();
public void go() {
Gerrit.display(getTargetHistoryToken());
}
}

View File

@@ -15,17 +15,10 @@
package com.google.gerrit.client.ui;
import com.google.gerrit.client.Gerrit;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.AnchorElement;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Accessibility;
import com.google.gwt.user.client.ui.InlineHyperlink;
import com.google.gwt.user.client.ui.impl.HyperlinkImpl;
public class LinkMenuItem extends InlineHyperlink {
static final HyperlinkImpl impl = GWT.create(HyperlinkImpl.class);
public LinkMenuItem(final String text, final String targetHistoryToken) {
super(text, targetHistoryToken);
setStyleName(Gerrit.RESOURCES.css().menuItem());
@@ -33,10 +26,8 @@ public class LinkMenuItem extends InlineHyperlink {
}
@Override
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
if (DOM.eventGetType(event) == Event.ONCLICK && impl.handleAsClick(event)) {
public void go() {
super.go();
AnchorElement.as(getElement()).blur();
}
}
}

View File

@@ -14,11 +14,12 @@
package com.google.gerrit.client.ui;
import com.google.gerrit.client.HistoryHandler;
import com.google.gerrit.client.Dispatcher;
import com.google.gerrit.client.changes.PatchTable;
import com.google.gerrit.reviewdb.Patch;
import com.google.gwt.user.client.History;
public abstract class PatchLink extends DirectScreenLink {
public abstract class PatchLink extends InlineHyperlink {
protected Patch.Key patchKey;
protected int patchIndex;
protected PatchTable parentPatchTable;
@@ -41,7 +42,7 @@ public abstract class PatchLink extends DirectScreenLink {
@Override
public void go() {
HistoryHandler.patch( //
Dispatcher.patch( //
getTargetHistoryToken(), //
patchKey, //
patchIndex, //
@@ -52,7 +53,7 @@ public abstract class PatchLink extends DirectScreenLink {
public static class SideBySide extends PatchLink {
public SideBySide(final String text, final Patch.Key patchKey,
final int patchIndex, PatchTable parentPatchTable) {
super(text, patchKey, patchIndex, HistoryHandler
super(text, patchKey, patchIndex, Dispatcher
.toPatchSideBySide(patchKey), parentPatchTable);
}
}
@@ -61,7 +62,7 @@ public abstract class PatchLink extends DirectScreenLink {
public Unified(final String text, final Patch.Key patchKey,
final int patchIndex, PatchTable parentPatchTable) {
super(text, patchKey, patchIndex,
HistoryHandler.toPatchUnified(patchKey), parentPatchTable);
Dispatcher.toPatchUnified(patchKey), parentPatchTable);
}
}
}

View File

@@ -15,7 +15,7 @@
package com.google.gerrit.client.ui;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.HistoryHandler;
import com.google.gerrit.client.Dispatcher;
import com.google.gerrit.client.changes.ByProjectAbandonedChangesScreen;
import com.google.gerrit.client.changes.ByProjectMergedChangesScreen;
import com.google.gerrit.client.changes.ByProjectOpenChangesScreen;
@@ -24,7 +24,7 @@ import com.google.gerrit.reviewdb.Project;
import com.google.gerrit.reviewdb.Change.Status;
/** Link to the open changes of a project. */
public class ProjectLink extends DirectScreenLink {
public class ProjectLink extends InlineHyperlink {
private Project.NameKey project;
private Status status;
@@ -34,7 +34,7 @@ public class ProjectLink extends DirectScreenLink {
public ProjectLink(final String text, final Project.NameKey proj,
Change.Status stat) {
super(text, HistoryHandler.toProject(proj, stat));
super(text, Dispatcher.toProject(proj, stat));
status = stat;
project = proj;
}

View File

@@ -26,6 +26,7 @@ public abstract class Screen extends View {
private FlowPanel header;
private InlineLabel headerText;
private FlowPanel body;
private String token;
private boolean requiresSignIn;
private String windowTitle;
@@ -75,6 +76,31 @@ public abstract class Screen extends View {
body.add(w);
}
/** Get the history token for this screen. */
public String getToken() {
return token;
}
/** Set the history token for this screen. */
public void setToken(final String t) {
assert t != null && !t.isEmpty();
token = t;
if (isCurrentView()) {
Gerrit.updateImpl(token);
}
}
/**
* If this view can display the given token, update it.
*
* @param newToken token the UI wants to show.
* @return true if this view can show the token immediately, false if not.
*/
public boolean displayToken(String newToken) {
return false;
}
/** Set whether or not {@link Gerrit#isSignedIn()} must be true. */
public final void setRequiresSignIn(final boolean b) {
requiresSignIn = b;