public ConfigureEditorCommand()
        {
            if (ToolPanels.Current["EditorToolbarContainer"] == null)
            {
                _panel = new ToolPanel();
                _panel.ContainerName = "EditorToolbarContainer";
                _panel.Name = "EditorToolbar";
                _panel.CanSerialize = false;

                ToolPanels.Current.Add(_panel);
            }
        }
Exemplo n.º 2
0
        public void loadToolPanels(string toolPanelsXml)
        {
            FrameworkElement layoutFileElement = this.Content as FrameworkElement;
            if (layoutFileElement != null)
            {
                if (!string.IsNullOrWhiteSpace(toolPanelsXml))
                {
                    XDocument xDoc = XDocument.Parse(toolPanelsXml);
                    XElement rootElement = xDoc.FirstNode as XElement;

                    ToolPanels.Current.PopulateToolPanelsFromXml(rootElement);
                }

                if (ToolPanels.Current != null && ToolPanels.Current.Count > 0)
                {
                    foreach (ToolPanel toolPanel in ToolPanels.Current)
                    {
                        // Add to UI
                        ContentControl toolPanelContainer = layoutFileElement.FindName(toolPanel.ContainerName) as ContentControl;
                        if (toolPanelContainer != null)
                            toolPanelContainer.Content = toolPanel;

                        // Hook to state change method to refresh other toolPanelss when the state of one changes
                        toolPanel.ToolStateChanged += toolPanel_ToolStateChanged;

                        foreach (var item in toolPanel.ToolPanelItems)
                        {
                            if (item is ButtonBase && ((ButtonBase)item).Command is INotifyInitialized)
                            {
                                var notifyInit = (INotifyInitialized)((ButtonBase)item).Command;
                                if (!notifyInit.IsInitialzed && notifyInit.InitializationError == null)
                                {
                                    m_toolsPendingInitCount++;

                                    EventHandler initHandler = null;
                                    initHandler = (o, e) =>
                                    {
                                        var n = (INotifyInitialized)o;
                                        n.Initialized -= initHandler;
                                        n.InitializationFailed -= initHandler;
                                        m_toolsPendingInitCount--;

                                        if (n.InitializationError != null)
                                            Logger.Instance.LogError(n.InitializationError);

                                        OnInitialized();
                                    };

                                    notifyInit.Initialized += initHandler;
                                    notifyInit.InitializationFailed += initHandler;
                                }
                                else if (notifyInit.InitializationError != null)
                                {
                                    Logger.Instance.LogError(notifyInit.InitializationError);
                                }
                            }
                        }
                    }
                }
            }

            // Also add toolPanel containers which are configurable controls 
            // This code will eventually go away once we make the toolPanel control public
            if (IsEditMode)
            {
                IApplicationAdmin appAdmin = MapApplication.Current as IApplicationAdmin;
                if (appAdmin != null && appAdmin.ConfigurableControls != null)
                {
                    foreach (FrameworkElement control in appAdmin.ConfigurableControls)
                    {
                        ContentControl ctrl = control as ContentControl;
                        if (ctrl != null && ctrl.Content == null && !string.IsNullOrWhiteSpace(ctrl.Name) &&
                            !(ctrl is EsriMapContents.MapContents)) //do this to temporary ensure that MapContents won't show in the list of toolpanels
                        {
                            if (ToolPanels.Current[ctrl.Name] != null)
                                continue;

                            ToolPanel newToolPanel = new ToolPanel()
                            {
                                ContainerName = ctrl.Name,
                                Name = ctrl.Name + "ToolPanel",
                            };
                            ToolPanels.Current.Add(newToolPanel);
                            try
                            {
                                ctrl.Content = newToolPanel;
                                // Hook to state change method to refresh other toolPanels when the state of one changes
                                newToolPanel.ToolStateChanged += toolPanel_ToolStateChanged;
                            }
                            catch { }
                        }
                    }
                }
            }
        }
        private void Wizard_Completed(object sender, EventArgs e)
        {
            // Get tool properties UI
            EditToolbarItemControl toolPropsUI = null;
            if (sender is EditToolbarItemControl)
                toolPropsUI = sender as EditToolbarItemControl;
            else
            {
                Wizard wizard = sender as Wizard;
                foreach (WizardPage page in wizard.Pages)
                {
                    toolPropsUI = page.Content as EditToolbarItemControl;
                    if (toolPropsUI != null)
                        break;
                }
            }
                
            // Update command properties with the configured values
            ToolPanel = toolPropsUI.SelectedToolPanel;
            DisplayInfo = DisplayInfo ?? new ButtonDisplayInfo();
            DisplayInfo.Label = toolPropsUI.Label;
            DisplayInfo.Description = toolPropsUI.Description;
            DisplayInfo.Icon = toolPropsUI.IconUrl;

            // Set completed flag so window closed handler knows that window was closed as a 
            // result of configuration being completed
            completed = true;
            // Hide configuration UI and fire the completed event
            BuilderApplication.Instance.HideWindow(configurationUI);
            ISupportsWizardConfiguration wizardConfigInterface = Class as ISupportsWizardConfiguration;
            if (wizardConfigInterface != null)
                wizardConfigInterface.OnCompleted();
            if (Completed != null)
                Completed(this, EventArgs.Empty);
        }
 private static void addAttributesForToolPanel(XElement toolPanelElement, ToolPanel toolPanel)
 {
     if (toolPanel != null && toolPanelElement != null)
     {
         if (!string.IsNullOrEmpty(toolPanel.ContainerName))
             toolPanelElement.Add(new XAttribute(Constants.TOOLPANEL_CONTAINER_NAME, toolPanel.ContainerName));
         if (!string.IsNullOrEmpty(toolPanel.Name))
             toolPanelElement.Add(new XAttribute(Constants.TOOLPANEL_NAME, toolPanel.Name));
         if (toolPanel.Orientation != Orientation.Horizontal)
             toolPanelElement.Add(new XAttribute(Constants.TOOLPANEL_ORIENTATION, toolPanel.Orientation.ToString()));
     }
 }
        public override void OnApplyTemplate()
        {
            MapContentControlContainer = GetTemplateChild(PART_MAP_CONTENT_CONTAINER_CONTROL) as ContentControl;
            if (MapContentControlContainer != null)
            {
                MapContentControl = new MapContents();
                MapContentControl.Name = PART_MAP_CONTENT_CONTROL;
                MapContentControl.Map = View.Map;
                MapContentControl.Configuration = new MapContentsConfiguration { ContextMenuToolPanelName = "EditModeLayerConfigurationContextMenu", Mode=Mode.TopLevelLayersOnly };

                if (MapContentControlContainer.Resources != null)
                {
                    MapContentControl.ScrollViewerStyle = MapContentControlContainer.Resources["BuilderMapContentsScrollViewerStyle"] as Style;
                    MapContentControl.SelectionColorBrush = MapContentControlContainer.Resources["BuilderSelectedLayerColorBrush"] as Brush;
                    MapContentControl.SelectionOutlineColorBrush = MapContentControlContainer.Resources["BuilderSelectedLayerOutlineColorBrush"] as Brush;
                    MapContentControl.ToggleButtonStyle = MapContentControlContainer.Resources["MapContentsControlNodeToggleButton"] as Style;
                }

                // Push foreground and background to map contents
                Binding b = new Binding("Foreground") { Source = this };
                MapContentControl.SetBinding(MapContents.ForegroundProperty, b);
                b = new Binding("Background") { Source = this };
                MapContentControl.SetBinding(MapContents.BackgroundProperty, b);

                MapContentControlContainer.Content = MapContentControl;
            }

            layerConfigurationLayout = GetTemplateChild(PART_CONFIGURE_LAYER_CONTROL_LAYOUT) as Grid;
            LayerConfiguration = GetTemplateChild("LayerConfigurationDialog") as LayerConfiguration;
            if (LayerConfiguration != null)
                LayerConfiguration.View = View.Instance;

            mapContentLayerConfigurationLayout = GetTemplateChild(PART_MAP_CONTENTS_LAYER_CONFIGURATION_LAYOUT) as Grid;
            if (mapContentLayerConfigurationLayout != null)
            {
                mapContentLayerConfigurationLayout.Loaded -= mapContentLayerConfigurationLayout_Loaded;
                mapContentLayerConfigurationLayout.Loaded += mapContentLayerConfigurationLayout_Loaded;
                mapContentLayerConfigurationLayout.SizeChanged -= mapContentLayerConfigurationLayout_SizeChanged;
                mapContentLayerConfigurationLayout.SizeChanged += mapContentLayerConfigurationLayout_SizeChanged;
            }

            mapContentsLayout = GetTemplateChild(PART_MAP_CONTENT_CONTROL_LAYOUT) as Grid;
            btnConfigurationComplete = GetTemplateChild(PART_CONFIGURE_COMPLETE_BUTTON) as Button;
            _layerConfigToolbar = GetTemplateChild(PART_TOOLPANEL) as ToolPanel;
            _allLayersConfigToolbar = GetTemplateChild(PART_ALLLAYERSTOOLPANEL) as ToolPanel;
            _mapContentsContenxtMenuToolbar = GetTemplateChild(PART_EDIT_MODE_LAYER_CONFIGURATION_CONTEXT_MENU) as ToolPanel;
            _layerConfigPanel = GetTemplateChild(PART_LAYERCONFIGPANEL) as FrameworkElement;
            InitializeToolbars();

            // hide the layer configuration elements until we need them
            RemoveLayerConfigurationVisualElements();
        }