com.esri.adf.web.data.results
Class WebResults

java.lang.Object
  extended by com.esri.adf.web.data.results.WebResults
All Implemented Interfaces:
Serializable

public class WebResults
extends Object
implements Serializable

The WebResults object is a container of arbitrary result objects. Any POJO representing a result can be added to WebResults. Result objects shipped out of the box include QueryResult, AddressCandidate, GPTaskResult, etc.

A WebResults object is maintained by the WebContext and can be accessed by using the WebContext.getWebResults() method. The result objects that you add to WebResults can provide 4 pieces of information for the user (The first one is required, the rest are optional):

  1. A display text for the result (e.g. a result for a city should display the name of the city)
  2. Result details (a java.util.Map of name-value attribute pairs)
  3. Actions that can be performed on the result (e.g. zoom, highlight, etc.)
  4. Action to be performed when the user removes the result (e.g. clear any graphics associated with the removed result(s))

So, for instance, the QueryResult provides these 4 pieces of information with these methods:

  1. Display text - QueryResult.getName()
  2. Result details - QueryResult.getDetails()
  3. Actions - QueryResult.zoom(), QueryResult.highlight(), QueryResult.clearGraphic()
  4. On remove - QueryResult.clearGraphic()
With this info, you can now add a java.util.List of QueryResults to WebResults:

 WebResults wresults = ctx.getWebResults();
 
 //a List of QueryResult objects
 List queryResults = ...; //perform queries such as find, identify, etc.
 
 wresults.addResultsWithActionArray("Query Results", queryResults, "getName", "getDetails", new String[]{"zoom", "highlight", "clearGraphic"});
 

All results are wrapped in ResultNode objects. The WebResults internally maintains a tree of these ResultNode objects. The ResultNode is the one which actually invokes the appropriate methods on the actual results to retrieve the 4 pieces of information mentioned above.

The WebResultsObservers registered with WebResults using the addObserver(WebResultsObserver) method will be notified whenever results are added, modified, replaced or removed.

See Also:
Serialized Form

Constructor Summary
WebResults()
           
 
Method Summary
 ResultNode addAddressCandidates(List<? extends AddressCandidate> candidates, ResultDefinition definition)
           
 void addObserver(WebResultsObserver observer)
           Registers the observer as an observer of this instance of WebResults.
 ResultNode addQueryResults(List<? extends QueryResult> results, ResultDefinition definition)
           
 void addResultNode(ResultNode resultNode)
           Adds a ResultNode to this instance of WebResults.
 ResultNode addResults(String groupHeader, List<?> results)
           Adds a List of results to this WebResults object.
 ResultNode addResultsWithActionArray(String groupHeader, List<?> results, String displayNameMethodName, String detailsMethodName, String[] actionMethodNames)
           Adds a List of results to this WebResults object.
 ResultNode addResultsWithActionArray(String groupHeader, List<?> results, String displayNameMethodName, String detailsMethodName, String[] actionMethodNames, String onRemoveMethodName)
           Adds a List of results to this WebResults object.
 ResultNode addResultsWithActionMap(String groupHeader, List<?> results, String displayNameMethodName, String detailsMethodName, Map<String,String> actionMethodNames)
           Adds a List of results to this WebResults object.
 ResultNode addResultsWithActionMap(String groupHeader, List<?> results, String displayNameMethodName, String detailsMethodName, Map<String,String> actionMethodNames, String onRemoveMethodName)
           Adds a List of results to this WebResults object.
 void clearAll()
           Removes all results from this instance of WebResults.
static String formatDate(Date d)
           
static String formatValue(Object o)
           
 List<ResultNode> getResultNodes()
           Returns an unmodifiable List of top-level ResultNodes maintained by this instance of WebResults.
 boolean isShowOpenResultLink()
           Returns true if the renderer for this WebResults object should display a link to open results.
 void notifyObservers(int updateType, ResultNode affectedNode, Object args)
           Notifies all WebResultsObservers registered with this instance of WebResults.
 boolean removeObserver(WebResultsObserver observer)
           Removes the observer from the list of registered WebResultsObservers.
 boolean removeResultNode(ResultNode resultNode)
           Removes a ResultNode to this instance of WebResults.
 boolean replaceResultNode(ResultNode newNode, ResultNode oldNode)
           Replaces an existing ResultNode with a new node.
 void setShowOpenResultLink(boolean showOpenResultLink)
           Set to true if the renderer for this WebResults object should display a link to open results.
 String toString()
           
 boolean updateQueryResults(ResultNode updateNode, List<?> results)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WebResults

public WebResults()
Method Detail

addResults

public ResultNode addResults(String groupHeader,
                             List<?> results)

Adds a List of results to this WebResults object.

Calling this method is equivalent to:

 wresults.addResultsWithActionMap(groupHeader, results, "toString", null, null);
 

The registered WebResultsObservers will be notified with an update of type WebResultsObserver.RESULT_ADDED.

Parameters:
groupHeader - the header for this List of results
results - the List of results to be maintained by this instance of WebResults
Returns:
the ResultNode for the node representing this set of results

addResultsWithActionArray

public ResultNode addResultsWithActionArray(String groupHeader,
                                            List<?> results,
                                            String displayNameMethodName,
                                            String detailsMethodName,
                                            String[] actionMethodNames,
                                            String onRemoveMethodName)

Adds a List of results to this WebResults object.

Calling this method is equivalent to:

 Map actionMethodsMap = new LinkedHashMap();
 
 for (int i = 0; i < actionMethodNames.length; i++)
   actionMethodsMap.put(actionMethodNames[i], actionMethodNames[i]);
 
 wresults.addResultsWithActionMap(groupHeader, results, displayNameMethodName, detailsMethodName, actionMethodsMap);
 

The registered WebResultsObservers will be notified with an update of type WebResultsObserver.RESULT_ADDED.

Parameters:
groupHeader - the header for this List of results
results - the List of results to be maintained by this instance of WebResults
displayNameMethodName - the name of the method which returns the display text for the result
detailsMethodName - the name of the method which returns the result details as a java.util.Map of name-value pairs
actionMethodNames - an array of names of methods for performing actions on the result
onRemoveMethodName - the name of the method to be called when the result is removed
Returns:
the ResultNode for the node representing this set of results

addResultsWithActionArray

public ResultNode addResultsWithActionArray(String groupHeader,
                                            List<?> results,
                                            String displayNameMethodName,
                                            String detailsMethodName,
                                            String[] actionMethodNames)

Adds a List of results to this WebResults object.

Calling this method is equivalent to:

 Map actionMethodsMap = new LinkedHashMap();
 
 for (int i = 0; i < actionMethodNames.length; i++)
   actionMethodsMap.put(actionMethodNames[i], actionMethodNames[i]);
 
 wresults.addResultsWithActionMap(groupHeader, results, displayNameMethodName, detailsMethodName, actionMethodsMap);
 

The registered WebResultsObservers will be notified with an update of type WebResultsObserver.RESULT_ADDED.

Parameters:
groupHeader - the header for this List of results
results - the List of results to be maintained by this instance of WebResults
displayNameMethodName - the name of the method which returns the display text for the result
detailsMethodName - the name of the method which returns the result details as a java.util.Map of name-value pairs
actionMethodNames - an array of names of methods for performing actions on the result
Returns:
the ResultNode for the node representing this set of results

addResultsWithActionMap

public ResultNode addResultsWithActionMap(String groupHeader,
                                          List<?> results,
                                          String displayNameMethodName,
                                          String detailsMethodName,
                                          Map<String,String> actionMethodNames,
                                          String onRemoveMethodName)

Adds a List of results to this WebResults object.

The registered WebResultsObservers will be notified with an update of type WebResultsObserver.RESULT_ADDED.

The actionMethodNames is a java.util.Map of <action display name>-<action method name> pairs.

Parameters:
groupHeader - the header for this List of results
results - the List of results to be maintained by this instance of WebResults
displayNameMethodName - the name of the method which returns the display text for the result
detailsMethodName - the name of the method which returns the result details as a java.util.Map of name-value pairs
actionMethodNames - a java.util.Map of <action display name>-<action method name> pairs
onRemoveMethodName - the name of the method to be called when the result is removed
Returns:
the ResultNode for the node representing this set of results

addResultsWithActionMap

public ResultNode addResultsWithActionMap(String groupHeader,
                                          List<?> results,
                                          String displayNameMethodName,
                                          String detailsMethodName,
                                          Map<String,String> actionMethodNames)

Adds a List of results to this WebResults object.

The registered WebResultsObservers will be notified with an update of type WebResultsObserver.RESULT_ADDED.

The actionMethodNames is a java.util.Map of <action display name>-<action method name> pairs.

Parameters:
groupHeader - the header for this List of results
results - the List of results to be maintained by this instance of WebResults
displayNameMethodName - the name of the method which returns the display text for the result
detailsMethodName - the name of the method which returns the result details as a java.util.Map of name-value pairs
actionMethodNames - a java.util.Map of <action display name>-<action method name> pairs
Returns:
the ResultNode for the node representing this set of results

addResultNode

public void addResultNode(ResultNode resultNode)

Adds a ResultNode to this instance of WebResults.

Parameters:
resultNode - the ResultNode to be added to this instance of WebResults

removeResultNode

public boolean removeResultNode(ResultNode resultNode)

Removes a ResultNode to this instance of WebResults.

The onRemove methods of this result and its children will be called before the result is actually removed.

The registered WebResultsObservers will be notified with an update of type WebResultsObserver.RESULT_REMOVED.

Parameters:
resultNode - the ResultNode to be removed from this instance of WebResults
Returns:
true if the result was successfully removed

replaceResultNode

public boolean replaceResultNode(ResultNode newNode,
                                 ResultNode oldNode)

Replaces an existing ResultNode with a new node.

The newNode will not be added if the oldNode was not found.

The registered WebResultsObservers will be notified with an update of type WebResultsObserver.RESULT_REPLACED.

Parameters:
newNode - the new ResultNode which replaces the oldNode
oldNode - the ResultNode to be replaced with the newNode
Returns:
true if the result was sucessfully replaced

clearAll

public void clearAll()

Removes all results from this instance of WebResults.

The registered WebResultsObservers will be notified with an update of type WebResultsObserver.ALL_RESULTS_CLEARED.


getResultNodes

public List<ResultNode> getResultNodes()

Returns an unmodifiable List of top-level ResultNodes maintained by this instance of WebResults.

Returns:
an unmodifiable List of top-level ResultNodes

addObserver

public void addObserver(WebResultsObserver observer)

Registers the observer as an observer of this instance of WebResults.

This observer along with the other registered observers will be notified whenever results are added, modified, replaced or removed.

Parameters:
observer - the WebResultsObserver to be registered

removeObserver

public boolean removeObserver(WebResultsObserver observer)

Removes the observer from the list of registered WebResultsObservers.

Parameters:
observer - the WebResultsObserver to be removed
Returns:
true if the observer was successfully removed

notifyObservers

public void notifyObservers(int updateType,
                            ResultNode affectedNode,
                            Object args)

Notifies all WebResultsObservers registered with this instance of WebResults.

This method iterates through all the registered observers and calls their WebResultsObserver.webResultsUpdate(WebResults, int, ResultNode, Object) method.

Parameters:
updateType - the type of update (e.g. WebResultsObserver.RESULT_ADDED, WebResultsObserver.RESULT_REMOVED, etc.
affectedNode - the affected ResultNode (e.g. the node that was added, the node that was removed, etc.)
args - an arbitrary argument object for observers to fine tune their reactions to this notification

isShowOpenResultLink

public boolean isShowOpenResultLink()

Returns true if the renderer for this WebResults object should display a link to open results.

Certain results (such as GP results) can be downloaded to and then uploaded (opened) from the client. Clients can add an "Open Result" link to open such results. They can make that decision based on this property.

Returns:
true if the renderer for this WebResults object should display a link to open results

setShowOpenResultLink

public void setShowOpenResultLink(boolean showOpenResultLink)

Set to true if the renderer for this WebResults object should display a link to open results.

Certain results (such as GP results) can be downloaded to and then uploaded (opened) from the client. Clients can add an "Open Result" link to open such results. They can make that decision based on this property.

Parameters:
showOpenResultLink - true if the renderer for this WebResults object should display a link to open results

toString

public String toString()
Overrides:
toString in class Object

addQueryResults

public ResultNode addQueryResults(List<? extends QueryResult> results,
                                  ResultDefinition definition)

updateQueryResults

public boolean updateQueryResults(ResultNode updateNode,
                                  List<?> results)

addAddressCandidates

public ResultNode addAddressCandidates(List<? extends AddressCandidate> candidates,
                                       ResultDefinition definition)

formatValue

public static String formatValue(Object o)

formatDate

public static String formatDate(Date d)