Common Custom EditorTaskCommon_CustomEditorTask_CSharp\CustomEditorTask_CSharp\PolygonToLineLayerEditorPanel.cs
// Copyright 2007 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.
//
using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.ADF.ArcGISServer.Editor;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;
using ESRI.ArcGIS.ADF.ArcGISServer;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
namespace CustomEditorTask_CSharp
{
class PolygonToLineLayerEditorPanel : EditorPanel
{
// Reference to the drop down list in the custom panel
private DropDownList dropDownListLayers;
public PolygonToLineLayerEditorPanel(string title, EditorTask task, string ID) : base(title, task, ID) { }
// The layer id for the selected layer in the drop down list
public int TargetLayerID
{
get
{
return int.Parse(dropDownListLayers.SelectedValue);
}
}
protected override void CreateChildControls()
{
base.CreateChildControls();
Label label = new Label();
label.Text = "Target layer: ";
Controls.Add(label);
dropDownListLayers = new DropDownList();
dropDownListLayers.ID = "targetLayers";
Controls.Add(dropDownListLayers);
// Add editable polyline layers to the drop down list
AddPolylineLayers();
}
protected override void Render(HtmlTextWriter writer)
{
// When item selected (changed) in the drop down list, trigger a callback to this control.
// Process in GetCallbackResult()
string jsOnChange = string.Format("javascript:var context;var argument='EventArg=targetChanged' + '&layer=' + document.getElementById('{0}').value; eval(\"{1}\");",
dropDownListLayers.ClientID, CallbackFunctionString);
dropDownListLayers.Attributes.Add("onchange", jsOnChange);
base.Render(writer);
}
public override string GetCallbackResult()
{
// Parse callback arguments using the CallbackUtility included with Web ADF.
// The _callbackArg is a protected string member variable inherited from
// ESRI.ArcGIS.ADF.Web.UI.WebControls.CompositeControl. Upon a callback, it
// contains the string argument passed to RaiseCallbackEvent().
NameValueCollection nameValueCollection =
CallbackUtility.ParseStringIntoNameValueCollection(_callbackArg);
int polylineLayerID;
if (int.TryParse(nameValueCollection["layer"], out polylineLayerID))
{
// Set property on custom Editor
CustomEditor editor = (CustomEditor)ParentEditor;
editor.PolylineLayerID = polylineLayerID;
}
return null;
}
// Add editable polyline layers to drop down list
private void AddPolylineLayers()
{
// Retrieve polyline layer names and ids from session
NameValueCollection nameValueCollection =
Page.Session["polygonLayers"] as NameValueCollection;
if (nameValueCollection == null)
{
nameValueCollection = new NameValueCollection();
// EditorTask maintains a string list of editable layer ids
foreach (string stringLayerID in Task.EditableLayers)
{
int layerID = int.Parse(stringLayerID);
foreach (MapLayerInfo layerInfo in ParentEditor.MapFunctionality.MapResource.MapServerInfo.MapLayerInfos)
{
if (layerInfo.LayerID == layerID)
{
foreach (Field field in layerInfo.Fields.FieldArray)
{
if (field.GeometryDef != null && field.GeometryDef.GeometryType == esriGeometryType.esriGeometryPolyline)
{
// If editable layer is of type polyline, add to the collection
nameValueCollection.Add(stringLayerID, layerInfo.Name);
break;
}
}
break;
}
}
}
Page.Session["polygonLayers"] = nameValueCollection;
}
// Add list items to drop down list
foreach (string layerID in nameValueCollection.Keys)
dropDownListLayers.Items.Add(new ListItem(nameValueCollection[layerID], layerID));
// Set custom Editor PolylineLayerID property
CustomEditor editor = (CustomEditor)ParentEditor;
if (editor.PolylineLayerID == -1 && nameValueCollection.Count > 0)
editor.PolylineLayerID = int.Parse(nameValueCollection.Keys[0]);
}
}
}