Exemple #1
0
        /// <summary>
        /// Sets up common functionality for an RDMPCollectionUI
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="tree">The main tree in the collection UI</param>
        /// <param name="activator">The current activator, used to launch objects, register for refresh events etc </param>
        /// <param name="iconColumn">The column of tree view which should contain the icon for each row object</param>
        /// <param name="renameableColumn">Nullable field for specifying which column supports renaming on F2</param>
        /// <param name="settings">Customise which common behaviorurs are turned on</param>
        public void SetUp(RDMPCollection collection, TreeListView tree, IActivateItems activator, OLVColumn iconColumn, OLVColumn renameableColumn, RDMPCollectionCommonFunctionalitySettings settings)
        {
            Settings    = settings;
            _collection = collection;
            IsSetup     = true;
            _activator  = activator;
            _activator.RefreshBus.Subscribe(this);

            RepositoryLocator = _activator.RepositoryLocator;

            Tree = tree;
            Tree.FullRowSelect = true;
            Tree.HideSelection = false;
            Tree.KeyPress     += Tree_KeyPress;

            Tree.RevealAfterExpand = true;

            if (!Settings.SuppressChildrenAdder)
            {
                Tree.CanExpandGetter += CanExpandGetter;
                Tree.ChildrenGetter  += ChildrenGetter;
            }

            if (!Settings.SuppressActivate)
            {
                Tree.ItemActivate += CommonItemActivation;
            }

            Tree.CellRightClick   += CommonRightClick;
            Tree.SelectionChanged += (s, e) => RefreshContextMenuStrip();

            if (iconColumn != null)
            {
                iconColumn.ImageGetter += ImageGetter;
            }

            if (Tree.RowHeight != 19)
            {
                Tree.RowHeight = 19;
            }

            //add colour indicator bar
            Tree.Location = new Point(Tree.Location.X, tree.Location.Y + 3);
            Tree.Height  -= 3;

            CreateColorIndicator(Tree, collection);

            //what does this do to performance?
            Tree.UseNotifyPropertyChanged = true;

            ParentFinder = new TreeNodeParentFinder(Tree);

            DragDropProvider = new DragDropProvider(
                _activator.CommandFactory,
                _activator.CommandExecutionFactory,
                tree);

            if (renameableColumn != null)
            {
                RenameProvider = new RenameProvider(_activator, tree, renameableColumn);
                RenameProvider.RegisterEvents();
            }

            if (Settings.AddFavouriteColumn)
            {
                FavouriteColumnProvider = new FavouriteColumnProvider(_activator, tree);
                FavouriteColumn         = FavouriteColumnProvider.CreateColumn();
            }

            if (settings.AddIDColumn)
            {
                IDColumnProvider = new IDColumnProvider(tree);
                IDColumn         = IDColumnProvider.CreateColumn();

                Tree.AllColumns.Add(IDColumn);
                Tree.RebuildColumns();
            }

            if (Settings.AddCheckColumn)
            {
                CheckColumnProvider = new CheckColumnProvider(tree, _activator.CoreIconProvider);
                CheckColumn         = CheckColumnProvider.CreateColumn();

                Tree.AllColumns.Add(CheckColumn);
                Tree.RebuildColumns();
            }
            CoreIconProvider = activator.CoreIconProvider;

            CopyPasteProvider = new CopyPasteProvider();
            CopyPasteProvider.RegisterEvents(tree);

            CoreChildProvider = _activator.CoreChildProvider;

            _activator.Emphasise += _activator_Emphasise;

            Tree.TreeFactory = TreeFactoryGetter;
            Tree.RebuildAll(true);

            Tree.FormatRow         += Tree_FormatRow;
            Tree.CellToolTipGetter += Tree_CellToolTipGetter;

            if (Settings.AllowSorting)
            {
                if (Tree.PrimarySortColumn == null)
                {
                    Tree.PrimarySortColumn = Tree.AllColumns.FirstOrDefault(c => c.IsVisible && c.Sortable);
                }

                //persist user sort orders
                if (TreeGuids.ContainsKey(_collection))
                {
                    //if we know the sort order fo this collection last time
                    var lastSort = UserSettings.GetLastColumnSortForCollection(TreeGuids[_collection]);

                    //reestablish that sort order
                    if (lastSort != null && Tree.AllColumns.Any(c => c.Text == lastSort.Item1))
                    {
                        Tree.PrimarySortColumn = Tree.GetColumn(lastSort.Item1);
                        Tree.PrimarySortOrder  = lastSort.Item2 ? SortOrder.Ascending : SortOrder.Descending;
                    }

                    //and track changes to the sort order
                    Tree.AfterSorting += TreeOnAfterSorting;
                }
            }
            else
            {
                foreach (OLVColumn c in Tree.AllColumns)
                {
                    c.Sortable = false;
                }
            }
        }
        /// <summary>
        /// Sets up common functionality for an RDMPCollectionUI
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="tree">The main tree in the collection UI</param>
        /// <param name="activator">The current activator, used to launch objects, register for refresh events etc </param>
        /// <param name="iconColumn">The column of tree view which should contain the icon for each row object</param>
        /// <param name="renameableColumn">Nullable field for specifying which column supports renaming on F2</param>
        /// <param name="settings">Customise which common behaviorurs are turned on</param>
        public void SetUp(RDMPCollection collection, TreeListView tree, IActivateItems activator, OLVColumn iconColumn, OLVColumn renameableColumn, RDMPCollectionCommonFunctionalitySettings settings)
        {
            Settings    = settings;
            _collection = collection;
            IsSetup     = true;
            _activator  = activator;
            _activator.RefreshBus.Subscribe(this);

            RepositoryLocator = _activator.RepositoryLocator;

            Tree = tree;
            Tree.FullRowSelect = true;
            Tree.HideSelection = false;
            Tree.KeyPress     += Tree_KeyPress;

            Tree.CellToolTip.InitialDelay = UserSettings.TooltipAppearDelay;
            Tree.CellToolTipShowing      += Tree_CellToolTipShowing;

            Tree.RevealAfterExpand = true;

            if (!Settings.SuppressChildrenAdder)
            {
                Tree.CanExpandGetter += CanExpandGetter;
                Tree.ChildrenGetter  += ChildrenGetter;
            }

            if (!Settings.SuppressActivate)
            {
                Tree.ItemActivate += CommonItemActivation;
            }

            Tree.CellRightClick += CommonRightClick;
            Tree.KeyUp          += CommonKeyPress;

            if (iconColumn != null)
            {
                iconColumn.ImageGetter += ImageGetter;
            }

            if (Tree.RowHeight != 19)
            {
                Tree.RowHeight = 19;
            }

            //add colour indicator bar
            Tree.Location = new Point(Tree.Location.X, tree.Location.Y + 3);
            Tree.Height  -= 3;

            CreateColorIndicator(Tree, collection);

            //what does this do to performance?
            Tree.UseNotifyPropertyChanged = true;

            ParentFinder = new TreeNodeParentFinder(Tree);

            DragDropProvider = new DragDropProvider(
                _activator.CommandFactory,
                _activator.CommandExecutionFactory,
                tree);

            if (renameableColumn != null)
            {
                RenameProvider = new RenameProvider(_activator, tree, renameableColumn);
                RenameProvider.RegisterEvents();
            }

            if (Settings.AddFavouriteColumn)
            {
                FavouriteColumnProvider = new FavouriteColumnProvider(_activator, tree);
                FavouriteColumn         = FavouriteColumnProvider.CreateColumn();

                SetupColumnTracking(FavouriteColumn, new Guid("ab25aa56-957c-4d1b-b395-48299be8e467"));
            }

            if (settings.AddIDColumn)
            {
                IDColumnProvider = new IDColumnProvider(tree);
                IDColumn         = IDColumnProvider.CreateColumn();

                Tree.AllColumns.Add(IDColumn);
                SetupColumnTracking(IDColumn, new Guid("9d567d9c-06f5-41b6-9f0d-e630a0e23f3a"));
                Tree.RebuildColumns();
            }

            if (Settings.AddCheckColumn)
            {
                CheckColumnProvider = new CheckColumnProvider(tree, _activator.CoreIconProvider);
                CheckColumn         = CheckColumnProvider.CreateColumn();

                SetupColumnTracking(CheckColumn, new Guid("8d9c6a0f-82a8-4f4e-b058-e3017d8d60e0"));

                Tree.AllColumns.Add(CheckColumn);
                Tree.RebuildColumns();
            }
            CoreIconProvider = activator.CoreIconProvider;

            CopyPasteProvider = new CopyPasteProvider();
            CopyPasteProvider.RegisterEvents(tree);

            CoreChildProvider = _activator.CoreChildProvider;

            _activator.Emphasise += _activator_Emphasise;

            Tree.TreeFactory = TreeFactoryGetter;
            Tree.RebuildAll(true);

            Tree.FormatRow += Tree_FormatRow;
            Tree.KeyDown   += Tree_KeyDown;

            if (Settings.AllowSorting)
            {
                SetupColumnSortTracking(Tree, TreeGuids.ContainsKey(collection) ? TreeGuids[collection] : Guid.Empty);
            }
            else
            {
                foreach (OLVColumn c in Tree.AllColumns)
                {
                    c.Sortable = false;
                }
            }
        }