public static PanelViewContainer Wrap(Widget widget) { var container = new PanelViewContainer(); container.Widget = widget; return(container); }
protected void OnContainerUnpinned(object sender, EventArgs args) { PanelViewContainer container = sender as PanelViewContainer; if (this.currentInfoProvider != container.InfoProvider) { content.Remove(container); } if (container.IsOrphan()) { container.Widget.Destroy(); container.Dispose(); } else { var maybePanelView = container.Widget as IPanelView; if (maybePanelView != null) { maybePanelView.Refresh(); container.Visible = container.VisibleOnPanel; } } UpdatePanelVisibility(); }
public void SetInfoProvider(IInfoProvider provider) { if (this.currentInfoProvider == provider) { return; } this.currentInfoProvider = provider; if (!providerToViewMap.ContainsKey(provider)) { var views = PanelViewFactory.CreateAll(provider.InfoWidgets) .Select(v => PanelViewContainer.Wrap(v)) .ToList(); views.ForEach(v => v.Unpinned += OnContainerUnpinned); views.ForEach(v => v.InfoProvider = provider); views.ForEach(v => (v.Widget as IPanelView)?.Refresh()); providerToViewMap.Add(provider, views); } var childrenToRemove = content.Children.Where(v => !(v as PanelViewContainer).Pinned); foreach (var child in childrenToRemove) { content.Remove(child); } List <PanelViewContainer> newViews; if (!providerToViewMap.TryGetValue(provider, out newViews)) { return; } foreach (var viewContainer in newViews) { bool alreadyOnPanel = viewContainer.Pinned; if (!alreadyOnPanel) { content.Add(viewContainer); content.SetChildPacking(viewContainer, false, false, 0, PackType.Start); viewContainer.Visible = viewContainer.VisibleOnPanel; } } UpdatePanelVisibility(); }