#region Disclaimer / License // Copyright (C) 2012, Jackie Ng // http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie@gmail.com // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // #endregion using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using OSGeo.MapGuide.ObjectModels.Common; using OSGeo.MapGuide.MaestroAPI.Services; using OSGeo.MapGuide.MaestroAPI; using OSGeo.MapGuide.MaestroAPI.Resource; namespace Maestro.Editors.Common { /// /// A control that provides a tree-based view of the repository /// public partial class RepositoryView : UserControl { /// /// Initializes a new instance /// public RepositoryView() { InitializeComponent(); this.SelectOnDrag = false; } /// /// Determines whether a node that is dragged causes it to be selected /// public bool SelectOnDrag { get; set; } /// /// Raises the Load event /// /// protected override void OnLoad(EventArgs e) { base.OnLoad(e); RepositoryIcons.PopulateImageList(resImageList); } /// /// Navigates to the given folder, expanding any parent nodes along the way /// /// public void NavigateTo(string folderId) { if (_model != null) _model.NavigateTo(folderId); } /// /// Initializes this view /// /// /// /// public void Init(IResourceService resSvc, bool bFoldersOnly, bool bOmitEmptyFolders) { if (_model != null) { _model.ItemSelected -= OnItemSelectedInternal; } _model = new RepositoryFolderTreeModel(resSvc, trvRepository, bFoldersOnly, bOmitEmptyFolders); _model.ItemSelected += OnItemSelectedInternal; } void OnItemSelectedInternal(object sender, EventArgs e) { var h = this.ItemSelected; if (h != null) h(this, EventArgs.Empty); } private RepositoryFolderTreeModel _model; /// /// Gets the currently selected item /// public IRepositoryItem SelectedItem { get { if (_model != null) { var it = _model.SelectedItem; if (it != null) return it.Instance; } return null; } } /// /// Raised when a repository item is selected /// public event EventHandler ItemSelected; /// /// Adds a resource type to filter on /// /// public void AddResourceTypeFilter(ResourceTypes rt) { if (_model != null) _model.AddResourceTypeFilter(rt); } /// /// Clears all applied resource type filters /// public void ClearResourceTypeFilters() { if (_model != null) _model.ClearResourceTypeFilters(); } /// /// Gets whether this view has resource type filters applied /// /// public bool HasFilteredTypes() { if (_model != null) return _model.HasFilteredTypes(); else return false; } /// /// Refreshes the model of the repostiory from the specified folder id /// /// public void RefreshModel(string folderId) { if (_model != null) { if (string.IsNullOrEmpty(folderId)) { _model.Refresh(null); } else { if (!ResourceIdentifier.IsFolderResource(folderId)) throw new ArgumentException(Strings.ErrNotAFolder); _model.Refresh(folderId); } } } public event ItemDragEventHandler ItemDrag; private void trvRepository_ItemDrag(object sender, ItemDragEventArgs e) { var node = e.Item as TreeNode; if (node != null) { if (node != trvRepository.SelectedNode && this.SelectOnDrag) { trvRepository.SelectedNode = node; } } var h = this.ItemDrag; if (h != null) h(this, e); } } }