private static void AddComplicatedStyleInnerStyles(StyleLayerListItem item)
        {
            bool isValueStyle = item.ConcreteObject is ValueStyle;

            foreach (var innerStyleItem in item.Children.OfType <StyleLayerListItem>())
            {
                innerStyleItem.DoubleClicked = () =>
                {
                    GisEditor.LayerListManager.SelectedLayerListItem = innerStyleItem;
                    EditStyle(innerStyleItem);
                };
                innerStyleItem.PreviewImage = new Image {
                    Source = innerStyleItem.GetPreviewSource(23, 23)
                };
                if (isValueStyle)
                {
                    innerStyleItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetZoomToExtentMenuItem());
                }

                AddMenuItems(innerStyleItem, false);
                foreach (var subItem in innerStyleItem.Children.OfType <StyleLayerListItem>())
                {
                    AddSubEntitiesToComponentStyleEntity(subItem);
                }
            }
        }
 public StyleItemViewModel(StyleLayerListItem styleItem, StyleBuilderArguments styleArguments)
 {
     this.styleItem      = styleItem;
     this.styleArguments = styleArguments;
     this.InitializeSubViewModels();
     this.InitializeContextMenuItems();
 }
 private void RefreshUI(StyleLayerListItem styleItem)
 {
     if (styleItem != null)
     {
         styleItem.UpdateConcreteObject();
         var styleItemUI = styleItem.GetUI(styleArguments);
         if (styleItemUI != null)
         {
             styleItem.UpdateUI(styleItemUI);
         }
     }
 }
        private void TreeViewItemMouseMove(object sender, MouseEventArgs e)
        {
            e.Handled = true;
            Grid item = sender as Grid;

            if (item != null && !item.IsMouseCaptured && e.LeftButton == MouseButtonState.Pressed)
            {
                var itemViewModel = (StyleItemViewModel)item.DataContext;
                if (!itemViewModel.IsRenaming)
                {
                    draggingItemParent = itemViewModel.StyleItem.Parent as StyleLayerListItem;
                    DragDrop.DoDragDrop(item, (itemViewModel), DragDropEffects.Move);
                    itemViewModel.IsSelected = true;
                }
            }
        }
        /// <summary>
        /// Determines whether the specified source item is parent.
        /// </summary>
        /// <param name="sourceItem">The source item.</param>
        /// <param name="parent">The parent.</param>
        /// <returns>
        ///   <c>true</c> if the specified source item is parent; otherwise, <c>false</c>.
        /// </returns>
        private bool IsParent(StyleLayerListItem sourceItem, StyleLayerListItem parent)
        {
            bool isParent = false;

            while (sourceItem.Parent != null)
            {
                if (sourceItem.Parent == parent)
                {
                    isParent = true;
                    break;
                }
                else
                {
                    sourceItem = sourceItem.Parent as StyleLayerListItem;
                }
            }

            return(isParent);
        }
 private static void AddSubEntitiesToComponentStyleEntity(StyleLayerListItem item)
 {
     //var subEntity = new LayerListItem();
     //subEntity.Parent = componentStyleEntity;
     //subEntity.ConcreteObject = item;
     //subEntity.Name = item.Name;
     //item.CheckBoxVisibility = System.Windows.Visibility.Collapsed;
     item.PreviewImage = new Image {
         Source = item.GetPreviewSource(23, 23)
     };
     AddMenuItems(item);
     item.DoubleClicked = () =>
     {
         GisEditor.LayerListManager.SelectedLayerListItem = item;
         EditStyle(item);
     };
     if (item.Children.Count > 0)
     {
         AddComplicatedStyleInnerStyles(item);
     }
     //componentStyleEntity.Children.Add(subEntity);
 }
        private void DuplicateClick(object sender, RoutedEventArgs e)
        {
            StyleLayerListItem duplicateStyleItem = StyleItem.CloneDeep();

            if (duplicateStyleItem == null)
            {
                return;
            }

            var parent = StyleItem.Parent as StyleLayerListItem;

            if (parent == null)
            {
                return;
            }

            parent.Children.Insert(0, duplicateStyleItem);
            parent.UpdateConcreteObject();
            if (ParentViewModel.StyleItemViewModels.Count > 0)
            {
                ParentViewModel.StyleItemViewModels[0].IsSelected = true;
            }
        }
 private static void AddMenuItems(StyleLayerListItem styleItem, bool isMovementEnabled = true)
 {
     styleItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.Up, isMovementEnabled));
     styleItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.Down, isMovementEnabled));
     styleItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.ToTop, isMovementEnabled));
     styleItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.ToBottom, isMovementEnabled));
     styleItem.ContextMenuItems.Add(new MenuItem()
     {
         Header = "--"
     });
     styleItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetInsertFromLibraryMenuItem());
     styleItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetReplaceFromLibraryMenuItem());
     styleItem.ContextMenuItems.Add(new MenuItem()
     {
         Header = "--"
     });
     styleItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetDuplicateMenuItem());
     if (styleItem.CanRename)
     {
         styleItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetRenameMenuItem());
     }
     styleItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetEditStyleMenuItem());
     styleItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetRemoveStyleMenuItem());
 }
        private static void CreateComponentStyleEntity(StyleLayerListItem styleItem)
        {
            var bitmapSource = styleItem.GetPreviewSource(23, 23);

            styleItem.PreviewImage = new Image {
                Source = bitmapSource
            };
            styleItem.IsExpanded = false;

            styleItem.DoubleClicked = () =>
            {
                GisEditor.LayerListManager.SelectedLayerListItem = styleItem;
                GisEditor.ActiveMap.ActiveLayer = GisEditor.LayerListManager.SelectedLayerListItem.Parent.ConcreteObject as Layer;
                EditStyle(styleItem);
            };

            AddMenuItems(styleItem);
            styleItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetSaveStyleMenuItem());

            foreach (var item in styleItem.Children.OfType <StyleLayerListItem>())
            {
                AddSubEntitiesToComponentStyleEntity(item);
            }
        }
Esempio n. 10
0
        private void InitializeCommands()
        {
            #region load from lib

            loadFromLibraryCommand = new RelayCommand(() =>
            {
                StyleLibraryWindow libraryWindow = new StyleLibraryWindow();
                if (libraryWindow.ShowDialog().Value)
                {
                    var componentStyle = libraryWindow.Result.CompositeStyle;
                    if (componentStyle != null)
                    {
                        FromZoomLevelIndex = libraryWindow.Result.FromZoomLevelIndex;
                        ToZoomLevelIndex   = libraryWindow.Result.ToZoomLevelIndex;
                        RootStyleItem.StyleItem.Children.Clear();
                        componentStyle.Styles.Reverse().ForEach(s => LoadStyle(s));
                        RootStyleItem.StyleItem.Name = componentStyle.Name;
                        RootStyleItem.StyleItem.UpdateConcreteObject();
                        UpdatePreviewSource();
                        SelectedStyleItem = RootStyleItem.StyleItemViewModels.FirstOrDefault();
                        if (SelectedStyleItem != null)
                        {
                            SelectedStyleItem.IsSelected = true;
                        }
                    }
                }
            }, () => !styleArguments.IsSubStyleReadonly);

            #endregion load from lib

            #region save to lib

            saveToLibraryCommand = new RelayCommand(() =>
            {
                var innerStyles = StyleItems.Select(s => s.StyleItem.ConcreteObject).Reverse().OfType <Styles.Style>();
                CompositeStyle componentStyle = new CompositeStyle(innerStyles)
                {
                    Name = Name
                };
                GisEditor.StyleManager.SaveStyleToLibrary(componentStyle, SelectedToZoomLevelModel.Scale, SelectedFromZoomLevelModel.Scale);
            });

            #endregion save to lib

            #region clear styles

            clearStylesCommand = new RelayCommand(() =>
            {
                System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show(GisEditor.LanguageManager.GetStringResource("StyleBuilderViewModelEraseAllStylesText")
                                                                                                , GisEditor.LanguageManager.GetStringResource("StyleBuilderViewModelClearStylesCaption")
                                                                                                , System.Windows.Forms.MessageBoxButtons.YesNo
                                                                                                , System.Windows.Forms.MessageBoxIcon.Warning);

                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    RootStyleItem.StyleItem.Children.Clear();
                    RootStyleItem.StyleItem.UpdateConcreteObject();
                    UpdatePreviewSource();
                    SelectRootNodeIfEmpty();
                }
            }, () => !styleArguments.IsSubStyleReadonly);

            #endregion clear styles

            #region duplicate style

            duplicateCommand = new RelayCommand(() =>
            {
                StyleLayerListItem duplicateStyleItem = SelectedStyleItem.StyleItem.CloneDeep();
                if (duplicateStyleItem != null)
                {
                    var parent = SelectedStyleItem.StyleItem.Parent as StyleLayerListItem;
                    if (parent != null)
                    {
                        parent.Children.Insert(0, duplicateStyleItem);
                        parent.UpdateConcreteObject();
                        if (StyleItems.Count > 0)
                        {
                            StyleItems.FirstOrDefault().IsSelected = true;
                        }
                        UpdatePreviewSource();
                    }
                }
            }, () => !styleArguments.IsSubStyleReadonly && SelectedStyleItem != null && SelectedStyleItem.StyleItem.Parent != null);

            #endregion duplicate style

            #region delete style

            deleteStyleCommand = new RelayCommand(() =>
            {
                var parentItem = SelectedStyleItem.StyleItem.Parent as StyleLayerListItem;
                if (parentItem != null && parentItem.Children.Contains(SelectedStyleItem.StyleItem))
                {
                    parentItem.Children.Remove(SelectedStyleItem.StyleItem);
                    parentItem.UpdateConcreteObject();
                    UpdatePreviewSource();
                    SelectRootNodeIfEmpty();
                }
            }, () => !styleArguments.IsSubStyleReadonly && SelectedStyleItem != null && SelectedStyleItem.StyleItem.Parent != null && SelectedStyleItem.StyleItem.ConcreteObject is Styles.Style);

            #endregion delete style

            #region rename

            renameCommand = new RelayCommand(() =>
            {
                if (IsRootNodeSelected)
                {
                    RootStyleItem.IsRenaming = true;
                }
                else
                {
                    SelectedStyleItem.IsRenaming = true;
                }
            }, () => !styleArguments.IsSubStyleReadonly && (IsRootNodeSelected || (SelectedStyleItem != null && SelectedStyleItem.StyleItem.CanRename)));

            #endregion rename
        }
 protected override bool CanContainStyleItemCore(StyleLayerListItem styleItem)
 {
     return(styleItem.ConcreteObject is Style);
 }
 /// <summary>
 /// Determines whether this instance [can contain style item core] the specified style item.
 /// </summary>
 /// <param name="styleItem">The style item.</param>
 /// <returns>
 ///   <c>true</c> if this instance [can contain style item core] the specified style item; otherwise, <c>false</c>.
 /// </returns>
 protected virtual bool CanContainStyleItemCore(StyleLayerListItem styleItem)
 {
     return(false);
 }
 /// <summary>
 /// Determines whether this instance [can contain style item] the specified style item.
 /// </summary>
 /// <param name="styleItem">The style item.</param>
 /// <returns>
 ///   <c>true</c> if this instance [can contain style item] the specified style item; otherwise, <c>false</c>.
 /// </returns>
 public bool CanContainStyleItem(StyleLayerListItem styleItem)
 {
     return(CanContainStyleItemCore(styleItem));
 }
        private static void AddSubMenuItemsForStyle(StyleBuilderArguments styleArguments, StyleCategories styleCategories
                                                    , string categoryName
                                                    , MenuItem rootMenuItem
                                                    , StyleItemViewModel currentStyleItemViewModel
                                                    , bool hasCompositedStyle)
        {
            if (hasCompositedStyle &&
                styleCategories != StyleCategories.None &&
                !styleCategories.HasFlag(StyleCategories.Label))
            {
                styleCategories = styleCategories | StyleCategories.Composite;
            }

            var plugins = GisEditor.StyleManager.GetStylePlugins(styleCategories);

            if (plugins.Count > 0)
            {
                var menuItems = plugins.Select(plugin =>
                {
                    if (plugin.RequireColumnNames && styleArguments.ColumnNames.Count == 0)
                    {
                        return(null);
                    }

                    MenuItem subMenuItem = new MenuItem();
                    subMenuItem.Header   = plugin.Name;
                    subMenuItem.Icon     = new Image {
                        Source = plugin.SmallIcon, Width = 16, Height = 16
                    };
                    subMenuItem.CommandParameter = new Tuple <StylePlugin, StyleCategories>(plugin, styleCategories);
                    subMenuItem.Command          = new RelayCommand <Tuple <StylePlugin, StyleCategories> >(commandParameter =>
                    {
                        StylePlugin tmpStylePlugin = commandParameter.Item1;
                        Styles.Style style         = tmpStylePlugin.GetDefaultStyle();
                        style.Name = tmpStylePlugin.Name;

                        StyleLayerListItem styleItem = GisEditor.StyleManager.GetStyleLayerListItem(style);
                        if (styleItem != null)
                        {
                            currentStyleItemViewModel.StyleItem.Children.Insert(0, styleItem);
                            currentStyleItemViewModel.StyleItem.UpdateConcreteObject();
                            var styleItemUI = currentStyleItemViewModel.StyleItem.GetUI(GetDuplicateStyleArguments(styleCategories, styleArguments));
                            if (styleItemUI != null)
                            {
                                currentStyleItemViewModel.StyleItem.UpdateUI(styleItemUI);
                            }

                            var addedStyleItemViewModel = currentStyleItemViewModel.StyleItemViewModels.FirstOrDefault(vm => vm.StyleItem == styleItem);
                            if (addedStyleItemViewModel != null)
                            {
                                if (commandParameter.Item2 == StyleCategories.Label)
                                {
                                    addedStyleItemViewModel.IsSelected = true;
                                }
                                else
                                {
                                    StyleItemViewModel rootStyleItemViewModel = GetRootViewModel(currentStyleItemViewModel);

                                    tmpStyleCategories    = commandParameter.Item2;
                                    var tmpStyleArguments = rootStyleItemViewModel.StyleBuilder.StyleArguments;
                                    rootStyleItemViewModel.StyleBuilder.PropertyChanged -= StyleBuilder_PropertyChanged;
                                    rootStyleItemViewModel.StyleBuilder.PropertyChanged += StyleBuilder_PropertyChanged;

                                    addedStyleItemViewModel.IsSelected = true;

                                    rootStyleItemViewModel.StyleBuilder.PropertyChanged -= StyleBuilder_PropertyChanged;
                                    rootStyleItemViewModel.StyleBuilder.StyleArguments   = tmpStyleArguments;
                                }
                            }
                        }
                    });
                    return(subMenuItem);
                }).Where(i => i != null).ToArray();

                foreach (var item in menuItems)
                {
                    rootMenuItem.Items.Add(item);
                }
            }
        }
        public static StyleItemViewModel FindStyleItemViewModel(Collection <StyleItemViewModel> itemViewModels, StyleLayerListItem itemToFind)
        {
            foreach (var vm in itemViewModels)
            {
                if (vm.StyleItem == itemToFind)
                {
                    return(vm);
                }
                else if (vm.StyleItemViewModels.Count > 0)
                {
                    var subVM = FindStyleItemViewModel(vm.StyleItemViewModels, itemToFind);
                    if (subVM != null)
                    {
                        return(subVM);
                    }
                }
            }

            return(null);
        }