diff --git a/server/zanata-war/src/main/java/org/zanata/webtrans/client/history/HistoryToken.java b/server/zanata-war/src/main/java/org/zanata/webtrans/client/history/HistoryToken.java index 70b72964ac..3db53cdae7 100644 --- a/server/zanata-war/src/main/java/org/zanata/webtrans/client/history/HistoryToken.java +++ b/server/zanata-war/src/main/java/org/zanata/webtrans/client/history/HistoryToken.java @@ -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 @@ -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) { @@ -129,11 +120,6 @@ public void setDocumentPath(String fullDocPath) this.fullDocPath = fullDocPath; } - public boolean hasView() - { - return view != null; - } - public AppPresenter.Display.MainView getView() { return view; @@ -141,7 +127,10 @@ public AppPresenter.Display.MainView getView() public void setView(AppPresenter.Display.MainView view) { - this.view = view; + if (view == null) + this.view = DEFAULT_VIEW; + else + this.view = view; } public boolean hasDocFilterExact() @@ -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} @@ -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)) diff --git a/server/zanata-war/src/main/java/org/zanata/webtrans/client/presenter/AppPresenter.java b/server/zanata-war/src/main/java/org/zanata/webtrans/client/presenter/AppPresenter.java index 0b6b8d6a36..df23cc4eab 100644 --- a/server/zanata-war/src/main/java/org/zanata/webtrans/client/presenter/AppPresenter.java +++ b/server/zanata-war/src/main/java/org/zanata/webtrans/client/presenter/AppPresenter.java @@ -321,65 +321,48 @@ private void processHistoryEvent(ValueChangeEvent 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) { diff --git a/server/zanata-war/src/main/java/org/zanata/webtrans/client/presenter/DocumentListPresenter.java b/server/zanata-war/src/main/java/org/zanata/webtrans/client/presenter/DocumentListPresenter.java index a64af9a7be..f0372bdce9 100644 --- a/server/zanata-war/src/main/java/org/zanata/webtrans/client/presenter/DocumentListPresenter.java +++ b/server/zanata-war/src/main/java/org/zanata/webtrans/client/presenter/DocumentListPresenter.java @@ -142,7 +142,7 @@ public void onSelection(SelectionEvent event) } else { - isNewSelection = docId.equals(event.getSelectedItem().getId()); + isNewSelection = !docId.equals(event.getSelectedItem().getId()); } if (isNewSelection)