private void UpdateVisibleButtons()
{
bool isVisible = System.ComponentModel.DesignerProperties.GetIsInDesignMode(this);
bool hasPolygonOrPolyline = isVisible;
bool addPolygonOrPolyline = isVisible;
bool atLeastOneLayerNotAutoSave = isVisible;
bool atLeastOneLayerCanAdd = isVisible;
bool atLeastOneLayerCanUpdate = isVisible;
bool atLeastOneLayerCanDelete = isVisible;
bool atLeastOneLayer = isVisible;
bool atLeastOneFeatureLayer = isVisible;
foreach (GraphicsLayer layer in this.editor.GraphicsLayers)
{
if (layer == null || string.IsNullOrEmpty(layer.ID))
continue;
if (!atLeastOneLayer && layer.Visible)
atLeastOneLayer = true;
if (layer is FeatureLayer)
{
if (!atLeastOneFeatureLayer && layer.Visible)
atLeastOneFeatureLayer = true;
FeatureLayer flayer = layer as FeatureLayer;
if (flayer.LayerInfo == null) continue;
if ((!hasPolygonOrPolyline || !addPolygonOrPolyline) && (flayer.LayerInfo.IsAddAllowed || flayer.LayerInfo.IsUpdateAllowed) && flayer.Visible && flayer.LayerInfo != null &&
(flayer.LayerInfo.GeometryType == GeometryType.Polygon || flayer.LayerInfo.GeometryType == GeometryType.Polyline))
{
if (!hasPolygonOrPolyline && (flayer.LayerInfo.IsUpdateAllowed || (!flayer.AutoSave && flayer.LayerInfo.IsAddAllowed)))
hasPolygonOrPolyline = true;
if (!addPolygonOrPolyline && flayer.LayerInfo.IsAddAllowed)
addPolygonOrPolyline = true;
}
if (!atLeastOneLayerNotAutoSave && !flayer.AutoSave && !flayer.IsReadOnly)
atLeastOneLayerNotAutoSave = true;
if (!atLeastOneLayerCanAdd && flayer.LayerInfo.IsAddAllowed && flayer.Visible)
atLeastOneLayerCanAdd = true;
if (!atLeastOneLayerCanUpdate && (flayer.LayerInfo.IsUpdateAllowed || (!flayer.AutoSave && flayer.LayerInfo.IsAddAllowed)) && flayer.Visible)
atLeastOneLayerCanUpdate = true;
if (!atLeastOneLayerCanDelete && (flayer.LayerInfo.IsDeleteAllowed || (!flayer.AutoSave && flayer.LayerInfo.IsAddAllowed)) && flayer.Visible)
atLeastOneLayerCanDelete = true;
}
else if (layer.Visible)
hasPolygonOrPolyline = true; //GraphicsLayer may contain polygon or polyline
}
bool allButtonsDisabled = !hasPolygonOrPolyline && !atLeastOneLayerNotAutoSave && !addPolygonOrPolyline &&
!atLeastOneLayerCanAdd && !atLeastOneLayerCanUpdate && atLeastOneLayerCanDelete
&& !atLeastOneLayer && !atLeastOneFeatureLayer;
DisableOrHideElement(TemplatePicker, atLeastOneLayerCanAdd, allButtonsDisabled);
DisableOrHideElement(EditGeometry, hasPolygonOrPolyline || atLeastOneLayerCanUpdate, allButtonsDisabled);
DisableOrHideElement(Reshape, hasPolygonOrPolyline, allButtonsDisabled);
DisableOrHideElement(NewSelect, atLeastOneLayer, allButtonsDisabled);
DisableOrHideElement(AddSelect, atLeastOneLayer, allButtonsDisabled);
DisableOrHideElement(RemoveSelect, atLeastOneLayer, allButtonsDisabled);
DisableOrHideElement(ClearSelect, atLeastOneLayer, allButtonsDisabled);
DisableOrHideElement(DeleteSelect, atLeastOneLayerCanDelete, allButtonsDisabled);
DisableOrHideElement(Cut, hasPolygonOrPolyline, allButtonsDisabled);
DisableOrHideElement(Union, hasPolygonOrPolyline, allButtonsDisabled);
DisableOrHideElement(Save, atLeastOneLayerNotAutoSave, allButtonsDisabled);
DisableOrHideElement(DisplayAttribute, atLeastOneFeatureLayer, allButtonsDisabled);
DisableOrHideElement(Options, addPolygonOrPolyline, allButtonsDisabled);
}