|
|
|
@ -31,57 +31,57 @@ using ICSharpCode.SharpDevelop.Project;
@@ -31,57 +31,57 @@ using ICSharpCode.SharpDevelop.Project;
|
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.Data.EDMDesigner.Core.UI.DisplayBinding |
|
|
|
|
{ |
|
|
|
|
public class EDMDesignerViewContent : AbstractViewContent, IHasPropertyContainer, IToolsHost, IEDMDesignerChangeWatcherObserver |
|
|
|
|
{ |
|
|
|
|
#region Fields
|
|
|
|
|
|
|
|
|
|
private ScrollViewer _scrollViewer = new ScrollViewer() { HorizontalScrollBarVisibility = ScrollBarVisibility.Auto, VerticalScrollBarVisibility = ScrollBarVisibility.Auto }; |
|
|
|
|
private DesignerCanvas _designerCanvas = null; |
|
|
|
|
private PropertyContainer _propertyContainer = new PropertyContainer(); |
|
|
|
|
private EDMView _edmView = null; |
|
|
|
|
private object _selection = null; |
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
public object Selection |
|
|
|
|
{ |
|
|
|
|
get { return _selection; } |
|
|
|
|
set |
|
|
|
|
{ |
|
|
|
|
if (_selection == null) |
|
|
|
|
_propertyContainer.Clear(); |
|
|
|
|
else |
|
|
|
|
_propertyContainer.SelectedObject = value; |
|
|
|
|
|
|
|
|
|
_selection = value; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Window Window |
|
|
|
|
{ |
|
|
|
|
get { return Application.Current.MainWindow; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public EDMView EDMView |
|
|
|
|
{ |
|
|
|
|
get { return _edmView; } |
|
|
|
|
} |
|
|
|
|
public class EDMDesignerViewContent : AbstractViewContent, IHasPropertyContainer, IToolsHost, IEDMDesignerChangeWatcherObserver |
|
|
|
|
{ |
|
|
|
|
#region Fields
|
|
|
|
|
|
|
|
|
|
private ScrollViewer _scrollViewer = new ScrollViewer() { HorizontalScrollBarVisibility = ScrollBarVisibility.Auto, VerticalScrollBarVisibility = ScrollBarVisibility.Auto }; |
|
|
|
|
private DesignerCanvas _designerCanvas = null; |
|
|
|
|
private PropertyContainer _propertyContainer = new PropertyContainer(); |
|
|
|
|
private EDMView _edmView = null; |
|
|
|
|
private object _selection = null; |
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
public object Selection |
|
|
|
|
{ |
|
|
|
|
get { return _selection; } |
|
|
|
|
set |
|
|
|
|
{ |
|
|
|
|
if (_selection == null) |
|
|
|
|
_propertyContainer.Clear(); |
|
|
|
|
else |
|
|
|
|
_propertyContainer.SelectedObject = value; |
|
|
|
|
|
|
|
|
|
_selection = value; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Window Window |
|
|
|
|
{ |
|
|
|
|
get { return Application.Current.MainWindow; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public EDMView EDMView |
|
|
|
|
{ |
|
|
|
|
get { return _edmView; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override object Control |
|
|
|
|
{ |
|
|
|
|
get { return _scrollViewer; } |
|
|
|
|
public override object Control |
|
|
|
|
{ |
|
|
|
|
get { return _scrollViewer; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public DesignerCanvas DesignerCanvas |
|
|
|
|
{ |
|
|
|
|
get { return _designerCanvas; } |
|
|
|
|
public DesignerCanvas DesignerCanvas |
|
|
|
|
{ |
|
|
|
|
get { return _designerCanvas; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
|
#region Constructor
|
|
|
|
|
|
|
|
|
|
public EDMDesignerViewContent(OpenedFile primaryFile) |
|
|
|
|
: base(primaryFile) |
|
|
|
@ -94,137 +94,134 @@ namespace ICSharpCode.Data.EDMDesigner.Core.UI.DisplayBinding
@@ -94,137 +94,134 @@ namespace ICSharpCode.Data.EDMDesigner.Core.UI.DisplayBinding
|
|
|
|
|
EDMDesignerChangeWatcher.AddEDMDesignerViewContent(this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
#region Methods
|
|
|
|
|
|
|
|
|
|
public override void Load(OpenedFile file, Stream stream) |
|
|
|
|
public override void Load(OpenedFile file, Stream stream) |
|
|
|
|
{ |
|
|
|
|
Debug.Assert(file == this.PrimaryFile); |
|
|
|
|
|
|
|
|
|
EDMDesignerChangeWatcher.Init = true; |
|
|
|
|
|
|
|
|
|
// Load EDMX from stream
|
|
|
|
|
XElement edmxElement = null; |
|
|
|
|
Action<XElement> readMoreAction = edmxElt => edmxElement = edmxElt; |
|
|
|
|
_edmView = new EDMView(stream, readMoreAction); |
|
|
|
|
|
|
|
|
|
// If EDMX is empty run EDM Wizard
|
|
|
|
|
if (_edmView.EDM.IsEmpty) |
|
|
|
|
{ |
|
|
|
|
edmxElement = null; |
|
|
|
|
|
|
|
|
|
string ns = String.Empty; |
|
|
|
|
if (ProjectService.CurrentProject == null) |
|
|
|
|
{ |
|
|
|
|
ns = ICSharpCode.Core.MessageService.ShowInputBox("EDMDesigner","Enter NameSpace","DefaultNamespace"); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
ns = ProjectService.CurrentProject.RootNamespace; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
EDMWizardWindow wizard = RunWizard(file, ns); |
|
|
|
|
|
|
|
|
|
if (wizard.DialogResult == true) |
|
|
|
|
_edmView = new EDMView(wizard.EDMXDocument, readMoreAction); |
|
|
|
|
else |
|
|
|
|
throw new WizardCancelledException(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Load or generate DesignerView and EntityTypeDesigners
|
|
|
|
|
EntityTypeDesigner.Init = true; |
|
|
|
|
|
|
|
|
|
XElement designerViewsElement = null; |
|
|
|
|
|
|
|
|
|
if (edmxElement == null || (designerViewsElement = EDMXIO.ReadSection(edmxElement, EDMXIO.EDMXSection.DesignerViews)) == null) |
|
|
|
|
{ |
|
|
|
|
designerViewsElement = DesignerIO.GenerateNewDesignerViewsFromCSDLView(_edmView); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (edmxElement != null && designerViewsElement != null) |
|
|
|
|
DesignerIO.Read(_edmView, designerViewsElement, entityType => new EntityTypeDesigner(entityType), complexType => new ComplexTypeDesigner(complexType)); |
|
|
|
|
|
|
|
|
|
EntityTypeDesigner.Init = false; |
|
|
|
|
|
|
|
|
|
// Call DoEvents, otherwise drawing associations can fail
|
|
|
|
|
VisualHelper.DoEvents(); |
|
|
|
|
|
|
|
|
|
// Gets the designer canvas
|
|
|
|
|
_designerCanvas = DesignerCanvas.GetDesignerCanvas(this, _edmView, _edmView.DesignerViews.FirstOrDefault()); |
|
|
|
|
EDMDesignerChangeWatcher.Init = true; |
|
|
|
|
|
|
|
|
|
// Load EDMX from stream
|
|
|
|
|
XElement edmxElement = null; |
|
|
|
|
Action<XElement> readMoreAction = edmxElt => edmxElement = edmxElt; |
|
|
|
|
_edmView = new EDMView(stream, readMoreAction); |
|
|
|
|
|
|
|
|
|
// If EDMX is empty run EDM Wizard
|
|
|
|
|
if (_edmView.EDM.IsEmpty) |
|
|
|
|
{ |
|
|
|
|
edmxElement = null; |
|
|
|
|
|
|
|
|
|
string ns = String.Empty; |
|
|
|
|
if (ProjectService.CurrentProject == null) |
|
|
|
|
{ |
|
|
|
|
ns = ICSharpCode.Core.MessageService.ShowInputBox("EDMDesigner","Enter NameSpace","DefaultNamespace"); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
ns = ProjectService.CurrentProject.RootNamespace; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
EDMWizardWindow wizard = RunWizard(file, ns); |
|
|
|
|
|
|
|
|
|
if (wizard.DialogResult == true) |
|
|
|
|
_edmView = new EDMView(wizard.EDMXDocument, readMoreAction); |
|
|
|
|
else |
|
|
|
|
throw new WizardCancelledException(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Load or generate DesignerView and EntityTypeDesigners
|
|
|
|
|
EntityTypeDesigner.Init = true; |
|
|
|
|
|
|
|
|
|
XElement designerViewsElement = null; |
|
|
|
|
|
|
|
|
|
if (edmxElement == null || (designerViewsElement = EDMXIO.ReadSection(edmxElement, EDMXIO.EDMXSection.DesignerViews)) == null) |
|
|
|
|
{ |
|
|
|
|
designerViewsElement = DesignerIO.GenerateNewDesignerViewsFromCSDLView(_edmView); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (edmxElement != null && designerViewsElement != null) |
|
|
|
|
DesignerIO.Read(_edmView, designerViewsElement, entityType => new EntityTypeDesigner(entityType), complexType => new ComplexTypeDesigner(complexType)); |
|
|
|
|
|
|
|
|
|
EntityTypeDesigner.Init = false; |
|
|
|
|
|
|
|
|
|
// Gets the designer canvas
|
|
|
|
|
_designerCanvas = DesignerCanvas.GetDesignerCanvas(this, _edmView, _edmView.DesignerViews.FirstOrDefault()); |
|
|
|
|
_scrollViewer.Content = _designerCanvas; |
|
|
|
|
|
|
|
|
|
// Register CSDL of EDMX in CSDL DatabaseTreeView
|
|
|
|
|
CSDLDatabaseTreeViewAdditionalNode.Instance.CSDLViews.Add(_edmView.CSDL); |
|
|
|
|
|
|
|
|
|
EDMDesignerChangeWatcher.Init = false; |
|
|
|
|
|
|
|
|
|
// Register CSDL of EDMX in CSDL DatabaseTreeView
|
|
|
|
|
CSDLDatabaseTreeViewAdditionalNode.Instance.CSDLViews.Add(_edmView.CSDL); |
|
|
|
|
|
|
|
|
|
EDMDesignerChangeWatcher.Init = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override void Save(OpenedFile file, Stream stream) |
|
|
|
|
{ |
|
|
|
|
EDMXIO.WriteXDocument(_edmView).Save(stream); |
|
|
|
|
EDMXIO.WriteXDocument(_edmView).Save(stream); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private EDMWizardWindow RunWizard(OpenedFile file, string projectStandardNamespace) |
|
|
|
|
{ |
|
|
|
|
EDMWizardWindow wizard = new EDMWizardWindow(file, projectStandardNamespace); |
|
|
|
|
wizard.Owner = Application.Current.MainWindow; |
|
|
|
|
wizard.WindowStartupLocation = WindowStartupLocation.CenterOwner; |
|
|
|
|
wizard.ShowDialog(); |
|
|
|
|
|
|
|
|
|
return wizard; |
|
|
|
|
EDMWizardWindow wizard = new EDMWizardWindow(file, projectStandardNamespace); |
|
|
|
|
wizard.Owner = Application.Current.MainWindow; |
|
|
|
|
wizard.WindowStartupLocation = WindowStartupLocation.CenterOwner; |
|
|
|
|
wizard.ShowDialog(); |
|
|
|
|
|
|
|
|
|
return wizard; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override void Dispose() |
|
|
|
|
{ |
|
|
|
|
if (CSDLDatabaseTreeViewAdditionalNode.Instance.CSDLViews.Contains(_edmView.CSDL)) |
|
|
|
|
CSDLDatabaseTreeViewAdditionalNode.Instance.CSDLViews.Remove(_edmView.CSDL); |
|
|
|
|
public override void Dispose() |
|
|
|
|
{ |
|
|
|
|
if (CSDLDatabaseTreeViewAdditionalNode.Instance.CSDLViews.Contains(_edmView.CSDL)) |
|
|
|
|
CSDLDatabaseTreeViewAdditionalNode.Instance.CSDLViews.Remove(_edmView.CSDL); |
|
|
|
|
|
|
|
|
|
EDMDesignerChangeWatcher.RemoveEDMDesignerViewContent(this); |
|
|
|
|
} |
|
|
|
|
EDMDesignerChangeWatcher.RemoveEDMDesignerViewContent(this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void ShowMappingTab(IUIType uiType) |
|
|
|
|
{ } |
|
|
|
|
public void ShowMappingTab(IUIType uiType) |
|
|
|
|
{ } |
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region IHasPropertyContainer
|
|
|
|
|
#region IHasPropertyContainer
|
|
|
|
|
|
|
|
|
|
public PropertyContainer PropertyContainer |
|
|
|
|
{ |
|
|
|
|
public PropertyContainer PropertyContainer |
|
|
|
|
{ |
|
|
|
|
get { return _propertyContainer; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region IToolsHost
|
|
|
|
|
#region IToolsHost
|
|
|
|
|
|
|
|
|
|
object IToolsHost.ToolsContent |
|
|
|
|
{ |
|
|
|
|
object IToolsHost.ToolsContent |
|
|
|
|
{ |
|
|
|
|
get { return null; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region IEDMDesignerChangeWatcherObserver Member
|
|
|
|
|
|
|
|
|
|
public bool ObjectChanged(object changedObject) |
|
|
|
|
{ |
|
|
|
|
foreach (DesignerView designerView in _edmView.DesignerViews) |
|
|
|
|
{ |
|
|
|
|
foreach (ITypeDesigner uiType in designerView) |
|
|
|
|
{ |
|
|
|
|
if (uiType == changedObject || uiType.UIType.BusinessInstance == changedObject) |
|
|
|
|
{ |
|
|
|
|
PrimaryFile.IsDirty = true; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region IEDMDesignerChangeWatcherObserver Member
|
|
|
|
|
|
|
|
|
|
public bool ObjectChanged(object changedObject) |
|
|
|
|
{ |
|
|
|
|
foreach (DesignerView designerView in _edmView.DesignerViews) |
|
|
|
|
{ |
|
|
|
|
foreach (ITypeDesigner uiType in designerView) |
|
|
|
|
{ |
|
|
|
|
if (uiType == changedObject || uiType.UIType.BusinessInstance == changedObject) |
|
|
|
|
{ |
|
|
|
|
PrimaryFile.IsDirty = true; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|