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

Commit

Permalink
clean up AppPresenter document selection and view change logic
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Jan 12, 2012
1 parent c9fd2eb commit b4b3b1e
Showing 1 changed file with 42 additions and 47 deletions.
Expand Up @@ -92,7 +92,7 @@ public interface Display extends net.customware.gwt.presenter.client.widget.Widg
private final TranslationStats selectedDocumentStats = new TranslationStats();
private final TranslationStats projectStats = new TranslationStats();
private TranslationStats currentDisplayStats = new TranslationStats();
private MainView currentView;
private MainView currentView = null;

private static final String WORKSPACE_TITLE_QUERY_PARAMETER_KEY = "title";

Expand All @@ -113,6 +113,8 @@ public AppPresenter(Display display, EventBus eventBus, final TranslationPresent
@Override
protected void onBind()
{
documentListPresenter.bind();
translationPresenter.bind();

registerHandler(eventBus.addHandler(NotificationEvent.getType(), new NotificationEventHandler()
{
Expand All @@ -125,10 +127,6 @@ public void onNotification(NotificationEvent event)
}
}));

documentListPresenter.bind();
translationPresenter.bind();

showView(MainView.Documents);

registerHandler(eventBus.addHandler(DocumentStatsUpdatedEvent.getType(), new DocumentStatsUpdatedEventHandler()
{
Expand Down Expand Up @@ -197,23 +195,22 @@ public void onClick(ClickEvent event)
}
}));

display.setUserLabel(identity.getPerson().getName());

String workspaceTitle = windowLocation.getParameter(WORKSPACE_TITLE_QUERY_PARAMETER_KEY);

display.setWorkspaceNameLabel(workspaceContext.getWorkspaceName(), workspaceTitle);

window.setTitle(messages.windowTitle(workspaceContext.getWorkspaceName(), workspaceContext.getLocaleName()));

history.addValueChangeHandler(new ValueChangeHandler<String>()
registerHandler(history.addValueChangeHandler(new ValueChangeHandler<String>()
{

@Override
public void onValueChange(ValueChangeEvent<String> event)
{
processHistoryEvent(event);
}
});
}));

display.setUserLabel(identity.getPerson().getName());
String workspaceTitle = windowLocation.getParameter(WORKSPACE_TITLE_QUERY_PARAMETER_KEY);
display.setWorkspaceNameLabel(workspaceContext.getWorkspaceName(), workspaceTitle);
window.setTitle(messages.windowTitle(workspaceContext.getWorkspaceName(), workspaceContext.getLocaleName()));

showView(MainView.Documents);

history.fireCurrentHistoryState();
}
Expand All @@ -239,7 +236,7 @@ private void processHistoryEvent(ValueChangeEvent<String> event)

if (docId != null && (selectedDocument == null || !selectedDocument.getId().equals(docId)))
{
showDocumentInfo(docId);
selectDocument(docId);
eventBus.fireEvent(new DocumentSelectionEvent(docId));
}

Expand All @@ -249,48 +246,43 @@ private void processHistoryEvent(ValueChangeEvent<String> event)
token.setView(MainView.Documents);
}

if (token.getView() != currentView)
showView(token.getView());
}

private void showView(MainView viewToShow)
{
if (currentView != viewToShow)
{
if (currentView.equals(MainView.Editor))
switch (viewToShow)
{
translationPresenter.saveEditorPendingChange();
}
else
{ // document list view
case Documents:
if (currentView == MainView.Editor)
translationPresenter.saveEditorPendingChange();
display.setDocumentLabel("", messages.noDocumentSelected());
currentDisplayStats = projectStats;
break;

case Editor:
if (selectedDocument != null)
{
display.setDocumentLabel(selectedDocument.getPath(), selectedDocument.getName());
}
currentDisplayStats = selectedDocumentStats;
break;
}
showView(token.getView());
display.showInMainView(viewToShow);
currentView = viewToShow;
refreshStatsDisplay();
}
}

private void showView(MainView viewToShow)
{
currentView = viewToShow;
display.showInMainView(viewToShow);
switch (viewToShow)
{
case Documents:
currentDisplayStats = projectStats;
display.setDocumentLabel("", messages.noDocumentSelected());
break;

case Editor:
currentDisplayStats = selectedDocumentStats;
break;
}

refreshStatsDisplay();
}

/**
* Show the name and stats for the given document
* Set selected document to the given document, update name and stats to
* match the newly selected document.
*
* @param event
* @param docId id of the document to select
*/
private void showDocumentInfo(DocumentId docId)
private void selectDocument(DocumentId docId)
{

if (selectedDocument == null || !docId.equals(selectedDocument.getId()))
Expand All @@ -299,9 +291,12 @@ private void showDocumentInfo(DocumentId docId)
if (docInfo != null)
{
selectedDocument = docInfo;
display.setDocumentLabel(selectedDocument.getPath(), selectedDocument.getName());
selectedDocumentStats.set(selectedDocument.getStats());
refreshStatsDisplay();
if (currentView == MainView.Editor)
{
display.setDocumentLabel(selectedDocument.getPath(), selectedDocument.getName());
refreshStatsDisplay();
}
}
}
}
Expand Down

0 comments on commit b4b3b1e

Please sign in to comment.