Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
use default value for history token view
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Dec 9, 2011
1 parent 3dc5049 commit 4e73570
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 77 deletions.
Expand Up @@ -55,16 +55,14 @@ public static HistoryToken fromTokenString(String token)
{
HistoryToken historyToken = new HistoryToken();


if (token == null || token.length() == 0)
{
return historyToken;
}

String[] pair;
for (String pairString : token.split(PAIR_SEPARATOR))
{
pair = pairString.split(DELIMITER_K_V);
String[] pair = pairString.split(DELIMITER_K_V);
String key;
String value;
try
Expand All @@ -87,14 +85,7 @@ else if (key == HistoryToken.KEY_VIEW)
{
historyToken.setView(AppPresenter.Display.MainView.Editor);
}
else if (value.equals(VALUE_DOCLIST_VIEW))
{
historyToken.setView(AppPresenter.Display.MainView.Documents);
}
else
{ // invalid view
historyToken.setView(null);
}
// else default will be used
}
else if (key == HistoryToken.KEY_DOC_FILTER_OPTION)
{
Expand Down Expand Up @@ -129,19 +120,17 @@ public void setDocumentPath(String fullDocPath)
this.fullDocPath = fullDocPath;
}

public boolean hasView()
{
return view != null;
}

public AppPresenter.Display.MainView getView()
{
return view;
}

public void setView(AppPresenter.Display.MainView view)
{
this.view = view;
if (view == null)
this.view = DEFAULT_VIEW;
else
this.view = view;
}

public boolean hasDocFilterExact()
Expand Down Expand Up @@ -174,7 +163,6 @@ public void setDocFilterText(String value)
this.docFilterText = value;
}


/**
* @return a token string for use with
* {@link com.google.gwt.user.client.History}
Expand All @@ -184,21 +172,14 @@ public String toTokenString()
String token = "";
boolean first = true;

if (hasView())
if (view != DEFAULT_VIEW)
{
if (first)
first = false;
else
token += PAIR_SEPARATOR;
token += KEY_VIEW + DELIMITER_K_V;
if (view == AppPresenter.Display.MainView.Editor)
{
token += VALUE_EDITOR_VIEW;
}
else if (view == AppPresenter.Display.MainView.Documents)
{
token += VALUE_DOCLIST_VIEW;
}
// editor is the only non-default view
token += KEY_VIEW + DELIMITER_K_V + VALUE_EDITOR_VIEW;
}

if (!fullDocPath.equals(DEFAULT_DOCUMENT_PATH))
Expand Down
Expand Up @@ -321,65 +321,48 @@ private void processHistoryEvent(ValueChangeEvent<String> event)
{
try
{
Log.info("Responding to history token: " + event.getValue());

// TODO keep track of previous history token like in DocumentListPresenter
HistoryToken token = HistoryToken.fromTokenString(event.getValue());

Log.info("Responding to history token: " + event.getValue());
DocumentId docId = documentListPresenter.getDocumentId(token.getDocumentPath());

HistoryToken token = HistoryToken.fromTokenString(event.getValue());

DocumentId docId = documentListPresenter.getDocumentId(token.getDocumentPath());

if (docId != null && (selectedDocument == null || !selectedDocument.getId().equals(docId)))
{
Log.info("Firing document selection event");
try
if (docId != null && (selectedDocument == null || !selectedDocument.getId().equals(docId)))
{
eventBus.fireEvent(new DocumentSelectionEvent(docId));
}
catch (Throwable t)
{
Log.info("got exception from document selection event", t);
Log.info("Firing document selection event");
try
{
eventBus.fireEvent(new DocumentSelectionEvent(docId));
}
catch (Throwable t)
{
Log.info("got exception from document selection event", t);
}
Log.info("Fired document selection event for " + docId.getId());
}
Log.info("Fired document selection event for " + docId.getId());
}

if (token.hasView() && token.getView() != display.getCurrentView())
{
if (display.getCurrentView().equals(MainView.Editor))
if (token.getView() != display.getCurrentView())
{
translationPresenter.saveEditorPendingChange();
}
else
{ // document list view
if (selectedDocument != null)
if (display.getCurrentView().equals(MainView.Editor))
{
display.setSelectedDocument(selectedDocument);
translationPresenter.saveEditorPendingChange();
}
else
{ // document list view
if (selectedDocument != null)
{
display.setSelectedDocument(selectedDocument);
}
}
display.showInMainView(token.getView());
}
display.showInMainView(token.getView());
}
// TODO set defaults in history rather than having this block.
else if (!token.hasView())
{
// default view.
display.showInMainView(MainView.Documents);
}

// TODO use a cloned token below when the current token is stored. Ok to
// modify current token for now. (add clone method when doing this)

// update toggle link with alternate view latest history state
if (token.hasView() && token.getView().equals(MainView.Editor))
{
token.setView(MainView.Documents);
}
else
{ // doclist is default
token.setView(MainView.Editor);
}
((Anchor) display.getDocumentsLink()).setHref("#" + token.toTokenString());

// update toggle link with alternate view latest history state
if (token.getView().equals(MainView.Editor))
token.setView(MainView.Documents);
else
token.setView(MainView.Editor);
((Anchor) display.getDocumentsLink()).setHref("#" + token.toTokenString());
}
catch (Throwable t)
{
Expand Down
Expand Up @@ -142,7 +142,7 @@ public void onSelection(SelectionEvent<DocumentInfo> event)
}
else
{
isNewSelection = docId.equals(event.getSelectedItem().getId());
isNewSelection = !docId.equals(event.getSelectedItem().getId());
}

if (isNewSelection)
Expand Down

0 comments on commit 4e73570

Please sign in to comment.