com\esri\arcgis\sample\layerattributes\ShowAGSLayerAttributes.java
/* Copyright 2010 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * * See the use restrictions. * */ package com.esri.arcgis.sample.layerattributes; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.faces.model.SelectItem; import com.esri.adf.web.ags.data.AGSMapFunctionality; import com.esri.adf.web.ags.data.AGSMapResource; import com.esri.adf.web.ags.data.AGSTocLayerContent; import com.esri.adf.web.ags.util.AGSUtil; import com.esri.adf.web.faces.event.TocEvent; import com.esri.arcgisws.EsriSearchOrder; import com.esri.arcgisws.EsriSpatialRelEnum; import com.esri.arcgisws.QueryFilter; import com.esri.arcgisws.RecordSet; import com.esri.arcgisws.SpatialFilter; /** * This class adds a 'Show Layer Attributes' toc context menu item and processes * the request when a user selected this menu item. */ public class ShowAGSLayerAttributes extends AGSTocLayerContent { private static final Logger logger = Logger.getLogger(ShowAGSLayerAttributes.class.getName()); private static SelectItem showLayerAttributes = new SelectItem("showLayerAttributes", "Show Layer Attributes", "Show Layer Attributes"); private List items = new ArrayList(); private boolean showAttributes = false; /** * Initialize context menu item */ public ShowAGSLayerAttributes() { items.addAll(super.getContextMenuItems()); items.add(showLayerAttributes); } /** * Return context menu items */ public List getContextMenuItems() { return items; } /** * Handle context menu event */ public void handleContextMenuEvent(String string, TocEvent tocEvent) { try { if(string.equals("showLayerAttributes")) { logger.fine("Context menu executed"); //get resource & map functionality AGSMapResource agssrc = (AGSMapResource) tocFunc.getResource(); AGSMapFunctionality mfunc = (AGSMapFunctionality)tocFunc.getMapFunctionality(); //create and populate spatial filter for executing query SpatialFilter filter = new SpatialFilter(); filter.setFilterGeometry(mfunc.getCurrentAGSExtent()); filter.setSpatialRel(EsriSpatialRelEnum.esriSpatialRelIntersects); filter.setGeometryFieldName(""); filter.setWhereClause(""); filter.setSpatialReferenceFieldName(""); filter.setSpatialRelDescription(""); filter.setSearchOrder(EsriSearchOrder.esriSearchOrderSpatial); //execute query & store serialized record set in web context RecordSet recordSet = agssrc.getMapServer().queryFeatureData(agssrc.getMapName(), layerDesc.getLayerID(), (QueryFilter)filter); String str = AGSUtil.serializeStub(recordSet); agssrc.getWebContext().setAttribute("myattr",str); } else super.handleContextMenuEvent(string, tocEvent); } catch (Exception ex) { ex.printStackTrace(); } } }