public MapperTreeNode(IModelMapper mapper) : base() { Mapper = mapper; FNamed = mapper.Map <INamed>(); Text = FNamed.Name; Tag = mapper.Model; FNamed.Renamed += Item_Renamed; if (mapper.CanMap <IParent>()) { var items = mapper.Map <IParent>(); if (items.Childs != null) { // Keep Nodes and items in sync FSynchronizer = Nodes.SyncWith(items.Childs, CreateChildNode); FSynchronizer.Synced += synchronizer_Synced; } } if (mapper.CanMap <ISelectable>()) { FSelectable = mapper.Map <ISelectable>(); Checked = FSelectable.Selected; FSelectable.SelectionChanged += Item_SelectionChanged; } }
public bool CanMap <TTo>() { if (FMapper == null) { throw new InvalidOperationException("ModelMapper must be set before CanMap can be invoked on LazyModelMapper."); } return(FMapper.CanMap <TTo>()); }
public DefaultDecoratableProvider(IModelMapper mapper) { FMapper = mapper; if (FMapper.CanMap <INamed>()) { Text = FMapper.Map <INamed>().Name; } else { Text = FMapper.Model.ToString(); } }
public DefaultParentProvider(IModelMapper mapper) { if (mapper.CanMap <IEnumerable>()) { Childs = mapper.Map <IEnumerable>(); } else if (mapper.Model is IEnumerable) { Childs = mapper.Model as IEnumerable; } else { Childs = null; } }
public ProjectViewProvider(IProject project, IModelMapper mapper) { FProject = project; FDocumentsMapper = mapper.CreateChildMapper(FProject.Documents); if (FDocumentsMapper.CanMap <IDroppable>()) { FDroppable = FDocumentsMapper.Map <IDroppable>(); } // Create a fake model, which shows documents in folders FFolderMap = new Dictionary <string, Folder>(); // First create our root folder. FRootFolder = new Folder(string.Empty); FFolderMap[FRootFolder.Name] = FRootFolder; // Now create all folders. foreach (var doc in FProject.Documents) { FProject_Documents_Added(FProject.Documents, doc); } FProject.Loaded += HandleProjectLoaded; FProject.Unloaded += HandleProjectUnloaded; // Keep changes in project in sync with our folder model. FProject.Documents.Added += FProject_Documents_Added; FProject.Documents.Removed += FProject_Documents_Removed; FProject.Documents.ItemRenamed += FProject_ItemRenamed; // Keep us in sync with the root folder. FRootFolder.Added += FRootFolder_Added; FRootFolder.Removed += FRootFolder_Removed; FRootFolder.OrderChanged += FRootFolder_OrderChanged; }
public MapperHierarchyNode(IModelMapper mapper, ICanvas canvas, IGraphElement parent, HierarchyViewer viewer) : base() { Mapper = mapper; FCanvas = canvas; FViewer = viewer; MouseClick += FViewer.MouseClickHandler; MouseDoubleClick += FViewer.MouseDoubleClickHandler; Tag = mapper.Model; //graphelements FBackground = canvas.CreateRectangle(this); FPoly = canvas.CreatePoly(this); FText = canvas.CreateText(null, ""); FIcon = FCanvas.CreateRectangle(null); parent.Add(FBackground); FBackground.Add(FPoly); FBackground.Add(FText); FBackground.Add(FIcon); //compute level of depth IGraphElement p = FBackground; while (p.Parent != null) { FDepth++; p = p.Parent; } FDepth -= 1; //init static properties via Mapper if (Mapper.CanMap <ISelectable>()) { FSelectable = Mapper.Map <ISelectable>(); FSelectable.SelectionChanged += selectable_SelectionChanged; Selected = FSelectable.Selected; } if (Mapper.CanMap <IDecoratable>()) { FDecoratable = Mapper.Map <IDecoratable>(); FDecoratable.DecorationChanged += decorated_DecorationChanged; } if (Mapper.CanMap <ILinkSource>()) { FLinkSource = Mapper.Map <ILinkSource>(); FLinkSourceRectangle = FCanvas.CreateRectangle(null); FBackground.Add(FLinkSourceRectangle); FLinkOffset = FTextOffset; } if (Mapper.CanMap <ILinkSink>()) { FLinkSink = Mapper.Map <ILinkSink>(); FLinkSinkRectangle = FCanvas.CreateRectangle(null); FBackground.Add(FLinkSinkRectangle); } if (Mapper.CanMap <INamed>()) { FNamed = Mapper.Map <INamed>(); FNamed.Renamed += named_Renamed; SetCaption(FNamed.Name); } if (Mapper.CanMap <IParent>()) { var node = Mapper.Map <IParent>(); if (node.Childs != null) { // Keep Nodes and items in sync FSynchronizer = FSubTree.SyncWith(node.Childs, CreateChildNode); FSynchronizer.Synced += synchronizer_Synced; } } //init dynamic properties via Mapper UpdateColors(); UpdateIcon(); UpdateLinkSink(); UpdateLinkSource(); }
public override void Reload() { FDataGridView.Rows.Clear(); FDataGridView.Columns.Clear(); if (FMapper != null) { FMapper.Dispose(); } if (FRowSynchronizer != null) { FRowSynchronizer.Dispose(); } FMapper = new ModelMapper(Input, Registry); if (FMapper.CanMap <IEnumerable <Column> >()) { try { var columns = FMapper.Map <IEnumerable <Column> >(); foreach (var col in columns) { var column = new DataGridViewColumn(new DataGridViewTextBoxCell()); column.Name = col.Name; switch (col.AutoSizeMode) { case AutoSizeColumnMode.AllCells: column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; break; case AutoSizeColumnMode.ColumnHeader: column.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader; break; case AutoSizeColumnMode.DisplayedCells: column.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; break; case AutoSizeColumnMode.Fill: column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; break; default: column.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet; break; } FDataGridView.Columns.Add(column); } if (FDataGridView.Columns.Count > 0) { var entries = FMapper.Map <IEnumerable>(); FRowSynchronizer = FDataGridView.Rows.SyncWith(entries, CreateRow, (r) => {}); } } catch (Exception e) { Shell.Instance.Logger.Log(e); } } }