📄 webattributeselection.java
字号:
package com.esri.solutions.jitk.web.tasks.query.location;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebContextInitialize;
import com.esri.adf.web.data.query.QueryResult;
import com.esri.adf.web.data.results.ResultNode;
import com.esri.adf.web.data.results.WebResults;
import com.esri.adf.web.data.results.WebResultsObserver;
/**
# Use the WebQuery methods addDisplayGeometry/containsDisplayGeometry/clearGraphic to handle the display of selected features
# Clear selection should basically call WebQuery.clearGraphics.
There is, however, a complication: I’d like to see the same selection behavior as in ArcMap where
the tabular results and the map share the same selection set. Clearing the map selection should
therefore also clear the (WebResults) selection displayed in the results table and vice versa. This needs
some form of observer/observable patter or eventing mechanism. A WebSelection container paired
with a WebSelectionbObserver interface could be a good idea.
# Finally, there should be some interaction between the WebResults and the WebSelection.
In detail,
>> members of WebSelection should always be in WebResults, while the opposite is not necessarily true. <<
That implies that if a selected feature is removed from the WebResults, it
should be automatically removed from the WebSelection as well.
This class is tied to WebResults as an observer because it needs to be aware of results added/removed etc actions.
*/
public class WebAttributeSelection implements WebResultsObserver, WebContextInitialize {
private static final Logger logger = Logger.getLogger(WebAttributeSelection.class);
private List<WebAttributeSelectionObserver> observers = new ArrayList<WebAttributeSelectionObserver>();
private List<QueryResult> results = new ArrayList<QueryResult>();
private WebContext webContext;
//members of WebSelection should always be in WebResults, while the opposite is not necessarily true.
public void addResults(String groupHeader, List<QueryResult> results) {
this.results.addAll(results);
notifyObservers(WebAttributeSelectionObserver.added, null);
//TODO
webContext.getWebResults().addResults(groupHeader, results);
}
public void removeResults(List<QueryResult> results) {
this.results.retainAll(results);
notifyObservers(WebAttributeSelectionObserver.removed, null);
}
public void clearAll() {
this.results.clear();
notifyObservers(WebAttributeSelectionObserver.cleared_all, null);
}
public void replaceResults() {
//TODO
}
public void notifyObservers(int updateType, Object arbitrary) {
for(WebAttributeSelectionObserver observer: observers) {
observer.update(this, updateType, arbitrary);
}
}
public void addObserver(WebAttributeSelectionObserver observer) {
if (!observers.contains(observer))
observers.add(observer);
}
public boolean removeObserver(WebAttributeSelectionObserver observer) {
return observers.remove(observer);
}
//TODO
public void webResultsUpdate(WebResults results, int updateType, ResultNode resultNode, Object arbitrary) {
switch (updateType) {
case (WebResultsObserver.ALL_RESULTS_CLEARED):
break;
case (WebResultsObserver.RESULT_ADDED):
break;
case (WebResultsObserver.RESULT_MODIFIED):
break;
case (WebResultsObserver.RESULT_REMOVED):
//That implies that if a selected feature is removed from the WebResults, it should be automatically removed from the WebSelection as well.
//TODO remove results contained in the affected ResultNode from WebSelection
break;
case(WebResultsObserver.RESULT_REPLACED):
break;
default:
logger.warn("Invalid updateType received: " + updateType);
break;
}
}
public void destroy() {
}
//NOTE: adding this class as an observer to WebResults can also be done declaratively
public void init(WebContext webContext) {
this.webContext = webContext;
this.webContext.getWebResults().addObserver(this);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -