Revision: 14698
http://gate.svn.sourceforge.net/gate/?rev=14698&view=rev
Author: valyt
Date: 2011-12-08 11:23:28 +0000 (Thu, 08 Dec 2011)
Log Message:
-----------
- linked the new GWT UI from the info page
- simplified the (prematurely optimised) GWT UI implementation
- various bugfixes
Modified Paths:
--------------
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/server/GwtRpcService.groovy
mimir/trunk/mimir-web/grails-app/views/search/index.gsp
mimir/trunk/mimir-web/grails-app/views/search/info.gsp
mimir/trunk/mimir-web/src/gwt/gate/mimir/web/client/UI.java
Modified:
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/server/GwtRpcService.groovy
===================================================================
---
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/server/GwtRpcService.groovy
2011-12-08 10:25:13 UTC (rev 14697)
+++
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/server/GwtRpcService.groovy
2011-12-08 11:23:28 UTC (rev 14698)
@@ -127,9 +127,9 @@
if(firstDocumentRank >= 0) {
// also obtain some documents data
List<DocumentData> documents = []
- for(int docRank = firstDocumentRank;
- docRank < firstDocumentRank + documentsCount;
- docRank++) {
+ int maxRank = Math.min(firstDocumentRank + documentsCount,
+ qRunner.getDocumentsCount());
+ for(int docRank = firstDocumentRank; docRank < maxRank; docRank++) {
DocumentData docData = new DocumentData(
documentRank:docRank,
documentTitle:qRunner.getDocumentTitle(docRank),
@@ -169,7 +169,7 @@
docData.snippets = snippets
documents.add(docData)
}
- rData.setDocuments(documents)
+ if(documents) rData.setDocuments(documents)
}
return rData
} else {
Modified: mimir/trunk/mimir-web/grails-app/views/search/index.gsp
===================================================================
--- mimir/trunk/mimir-web/grails-app/views/search/index.gsp 2011-12-08
10:25:13 UTC (rev 14697)
+++ mimir/trunk/mimir-web/grails-app/views/search/index.gsp 2011-12-08
11:23:28 UTC (rev 14698)
@@ -3,7 +3,7 @@
<!-- Integrate with Sitemesh layouts -->
<meta name="layout" content="mimir" />
- <title>Mímir Index ${index?.name}</title>
+ <title>Mímir Index "${index?.name}"</title>
<!-- Pass some variable to the GWT code -->
<g:javascript>
@@ -31,7 +31,7 @@
<!-- Add the rest of the page here, or leave it -->
<!-- blank for a completely dynamic interface. -->
- <h1>Searching Index ${index?.name}</h1>
+ <h1>Searching Index "${index?.name}"</h1>
<div class="searchBox" id="searchBox"></div>
<div class="bluebar" id="feedbackBar"></div>
<div class="searchResults" id="searchResults"></div>
Modified: mimir/trunk/mimir-web/grails-app/views/search/info.gsp
===================================================================
--- mimir/trunk/mimir-web/grails-app/views/search/info.gsp 2011-12-08
10:25:13 UTC (rev 14697)
+++ mimir/trunk/mimir-web/grails-app/views/search/info.gsp 2011-12-08
11:23:28 UTC (rev 14698)
@@ -14,8 +14,7 @@
</g:if>
<h1>Mimir index "${indexInstance.name}"</h1>
<g:if test="${indexInstance.state == Index.SEARCHING}">
- <p><g:link controller="gus" action="gus"
- params="[indexId:indexInstance.indexId]"
+ <p><g:link action="index" params="[indexId:indexInstance.indexId]"
title="Search this index">Search this index using the web
UI.</g:link> </br>
<g:link controller="search"
action="help"
params="[indexId:indexInstance.indexId]"
Modified: mimir/trunk/mimir-web/src/gwt/gate/mimir/web/client/UI.java
===================================================================
--- mimir/trunk/mimir-web/src/gwt/gate/mimir/web/client/UI.java 2011-12-08
10:25:13 UTC (rev 14697)
+++ mimir/trunk/mimir-web/src/gwt/gate/mimir/web/client/UI.java 2011-12-08
11:23:28 UTC (rev 14698)
@@ -14,17 +14,11 @@
package gate.mimir.web.client;
-import java.util.ArrayList;
import java.util.List;
-import sun.awt.motif.MInputMethod;
-import gate.mimir.gus.client.GusService;
-import gate.mimir.gus.client.GusServiceAsync;
-
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
-import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
@@ -32,7 +26,6 @@
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Timer;
-import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.Anchor;
@@ -40,12 +33,10 @@
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HTMLPanel;
-import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.InlineHTML;
import com.google.gwt.user.client.ui.InlineHyperlink;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;
@@ -57,11 +48,18 @@
/**
* A Timer implementation that fetches the latest results information from
the
* server and updates the results display accordingly.
+ * It will re-schedule itself until all required data is made available by
+ * the server.
*/
protected class ResultsUpdater extends Timer {
private int newFirstDocument;
+ /**
+ * Creates a new results updater.
+ * @param newFirstDocument the first document to be displayed on the page.
+ * This can be used for navigating between pages.
+ */
public ResultsUpdater(int newFirstDocument) {
super();
this.newFirstDocument = newFirstDocument;
@@ -71,27 +69,16 @@
public void run() {
if(newFirstDocument != firstDocumentOnPage) {
// new page: clear data and old display
- documentsData.clear();
- searchResultsPanel.clear();
firstDocumentOnPage = newFirstDocument;
+ updateResultsDisplay(null);
}
- // calculate which documents we need now
- int firstDoc = firstDocumentOnPage + documentsData.size();
- int docCount = maxDocumentsOnPage - documentsData.size();
- if(docCount <= 0) {
- firstDoc = -1;
- } else {
- feedbackLabel.setText("Working...");
- }
- gwtRpcService.getResultsData(queryId, firstDoc, docCount,
+ feedbackLabel.setText("Working...");
+ gwtRpcService.getResultsData(queryId, firstDocumentOnPage,
maxDocumentsOnPage,
new AsyncCallback<ResultsData>() {
@Override
public void onSuccess(ResultsData result) {
updatePage(result);
- boolean allDone = (result.getResultsTotal() >= 0) &&
- ((documentsData.size() == maxDocumentsOnPage) ||
- firstDocumentOnPage + documentsData.size() ==
result.getResultsTotal());
- if(!allDone) schedule(500);
+ if(result.getResultsTotal() < 0) schedule(500);
}
@Override
@@ -115,32 +102,76 @@
}
}
+ /**
+ * Gets the Javascript variable value from the GSP view.
+ * @return
+ */
private native String getIndexId() /*-{
return $wnd.indexId;
}-*/;
+ /**
+ * Gets the Javascript variable value from the GSP view.
+ * @return
+ */
private native String getUriIsLink() /*-{
return $wnd.uriIsLink;
}-*/;
+ /**
+ * The remote service used to communicate with the server.
+ */
private GwtRpcServiceAsync gwtRpcService;
+ /**
+ * The TextArea where the query string is typed by the user.
+ */
protected TextArea searchBox;
+ /**
+ * The Search button.
+ */
protected Button searchButton;
+ /**
+ * The current query ID (used when communicating with the server).
+ */
protected String queryId;
+ /**
+ * The current query string (used to re-post the query if the session expired
+ * (e.g. the link was bookmarked).
+ */
protected String queryString;
+ /**
+ * Cached value for the current index ID (obtained once from
+ * {@link #getIndexId()}, then cached).
+ */
protected String indexId;
+ /**
+ * Cached value for the Javascript var (obtained once from
+ * {@link #getUriIsLink()}, then cached).
+ */
protected boolean uriIsLink;
+ /**
+ * The label displaying feedback to the user (e.g. how many documents were
+ * found, or the current error message).
+ */
protected Label feedbackLabel;
+ /**
+ * The panel covering the centre of the page, where the results documents are
+ * listed.
+ */
protected HTMLPanel searchResultsPanel;
+ /**
+ * The panel at the bottom of the page, containing links to other result
+ * pages.
+ */
protected HTMLPanel pageLinksPanel;
/**
@@ -148,14 +179,23 @@
*/
protected int firstDocumentOnPage;
+ /**
+ * How many documents should be shown on each result page.
+ */
protected int maxDocumentsOnPage = 20;
+ /**
+ * How many page links should be included at the bottom. The current page
+ * would normally appear in the middle.
+ */
protected int maxPages = 20;
+ /**
+ * How many characters are displayed for each snippet (for longer snippets,
+ * the middle content is truncated and replaced by an ellipsis).
+ */
protected int maxSnippetLength = 100;
- private List<DocumentData> documentsData;
-
/**
* This is the entry point method.
*/
@@ -177,11 +217,6 @@
protected void initLocalData() {
queryId = null;
firstDocumentOnPage = 0;
- if(documentsData == null){
- documentsData = new ArrayList<DocumentData>(maxDocumentsOnPage);
- } else {
- documentsData.clear();
- }
}
protected void initGui() {
@@ -198,14 +233,15 @@
searchDiv.add(searchButton);
HTMLPanel resultsBar =
HTMLPanel.wrap(Document.get().getElementById("feedbackBar"));
- feedbackLabel = new Label(" ");
+ feedbackLabel = new InlineLabel();
resultsBar.add(feedbackLabel);
+ resultsBar.add(new InlineHTML(" "));
searchResultsPanel =
HTMLPanel.wrap(Document.get().getElementById("searchResults"));
- for(int i = 0; i < 20; i++) searchResultsPanel.add(new Label(" "));
+ updateResultsDisplay(null);
pageLinksPanel =
HTMLPanel.wrap(Document.get().getElementById("pageLinks"));
- pageLinksPanel.add(new InlineLabel(" "));
+ pageLinksPanel.add(new InlineHTML(" "));
}
protected void initListeners() {
@@ -262,6 +298,17 @@
}
}
+ protected void updateResultsDisplay (List<DocumentData> documentsData) {
+ searchResultsPanel.clear();
+ if(documentsData == null || documentsData.isEmpty()) {
+ for(int i = 0; i < 20; i++) searchResultsPanel.add(new HTML(" "));
+ } else {
+ for(DocumentData docData : documentsData) {
+ searchResultsPanel.add(buildDocumentDisplay(docData));
+ }
+ }
+ }
+
protected void startSearch() {
// clean up old state
if(queryId != null) {
@@ -281,8 +328,7 @@
protected void postQuery(final String newQueryString) {
feedbackLabel.setText("Working...");
- // clear the old display
- searchResultsPanel.clear();
+ updateResultsDisplay(null);
gwtRpcService.search(getIndexId(), newQueryString, new
AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
@@ -330,30 +376,9 @@
}
textBuilder.append(":");
feedbackLabel.setText(textBuilder.toString());
-
+ // now update the documents display
if(resultsData.getDocuments() != null){
- // now update the documents display
- int docPosition = 0;
- for(DocumentData docData : resultsData.getDocuments()) {
- // skip already populated positions
- while(docPosition < documentsData.size() &&
- documentsData.get(docPosition).documentRank <
docData.documentRank){
- docPosition ++;
- }
- if(docPosition == documentsData.size()) {
- documentsData.add(docData);
- HTMLPanel documentDisplay = buildDocumentDisplay(docData);
-// if(docPosition % 2 == 0) documentDisplay.addStyleName("even");
- searchResultsPanel.add(documentDisplay);
- } else {
- if(documentsData.get(docPosition).documentRank ==
docData.documentRank) {
- // we got the same document: skip it
- } else {
- // malfunction?
- // TODO
- }
- }
- }
+ updateResultsDisplay(resultsData.getDocuments());
}
// page links
@@ -433,4 +458,4 @@
}
return documentDisplay;
}
-}
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of
discussion for anyone considering optimizing the pricing and packaging model
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs