1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
7
using System.Collections;
10
using System.Windows.Controls;
11
using System.Windows.Data;
12
using System.Windows.Input;
13
using ICSharpCode.Data.EDMDesigner.Core.UI.Windows;
14
using ICSharpCode.Data.EDMDesigner.Core.UI.UserControls.Common;
15
using System.Windows.Media;
16
using ICSharpCode.Data.EDMDesigner.Core.UI.DisplayBinding;
17
using ICSharpCode.Data.EDMDesigner.Core.EDMObjects.Designer.CSDL;
18
using ICSharpCode.Data.EDMDesigner.Core.EDMObjects.Designer;
19
using ICSharpCode.Data.EDMDesigner.Core.EDMObjects.Designer.CSDL.Type;
20
using ICSharpCode.Data.EDMDesigner.Core.EDMObjects.Designer.CSDL.Association;
21
using ICSharpCode.Data.EDMDesigner.Core.EDMObjects.CSDL.Property;
25
namespace ICSharpCode.Data.EDMDesigner.Core.UI.UserControls
27
partial class DesignerCanvas
29
private const string CONTEXTMENU_RESOURCE_NAME = "ContextMenu";
30
private const string ZOOM_STACKPANEL = "zoomStackPanel";
31
private const string ZOOM_TEXTBOX = "zoomTextBox";
33
private static RoutedCommand _addEntityTypeCommand;
34
public static RoutedCommand AddEntityTypeCommand
38
if (_addEntityTypeCommand == null)
39
_addEntityTypeCommand = new RoutedCommand();
40
return _addEntityTypeCommand;
43
public static string AddEntityTypeText
47
return "Add entity type";
51
private static RoutedCommand _addComplexTypeCommand;
52
public static RoutedCommand AddComplexTypeCommand
56
if (_addComplexTypeCommand == null)
57
_addComplexTypeCommand = new RoutedCommand();
58
return _addComplexTypeCommand;
61
public static string AddComplexTypeText
65
return "Add complex type";
69
private static RoutedCommand _addAssociationCommand;
70
public static RoutedCommand AddAssociationCommand
74
if (_addAssociationCommand == null)
75
_addAssociationCommand = new RoutedCommand();
76
return _addAssociationCommand;
79
public static string AddAssociationText
83
return "Add association";
87
private static RoutedCommand _removeFromDesignerCommand;
88
public static RoutedCommand RemoveFromDesignerCommand
92
if (_removeFromDesignerCommand == null)
93
_removeFromDesignerCommand = new RoutedCommand();
94
return _removeFromDesignerCommand;
97
public static string RemoveFromDesignerText
101
return "Remove from designer";
105
private static RoutedCommand _selectAllCommand;
106
public static RoutedCommand SelectAllCommand
110
if (_selectAllCommand == null)
111
_selectAllCommand = new RoutedCommand();
112
return _selectAllCommand;
115
public static string SelectAllText
123
public static string ZoomText
132
get { return (int)GetValue(ZoomProperty); }
133
set { SetValue(ZoomProperty, value); }
135
public static readonly DependencyProperty ZoomProperty =
136
DependencyProperty.Register("Zoom", typeof(int), typeof(DesignerCanvas),
137
new UIPropertyMetadata(100,
140
var designerCanvas = (DesignerCanvas)sender;
141
if ((int)e.NewValue < 10)
142
designerCanvas.Zoom = 10;
143
else if ((int)e.NewValue > 1000)
144
designerCanvas.Zoom = 1000;
147
int zoom = (int)e.NewValue;
148
designerCanvas.DesignerView.Zoom = zoom;
149
var scale = (double)zoom / 100.0;
150
designerCanvas.LayoutTransform = new ScaleTransform(scale, scale);
151
designerCanvas.Resize();
155
public new InputBindingCollection InputBindings
157
get { return base.InputBindings; }
160
public static readonly DependencyProperty InputBindingsProperty = DependencyProperty.RegisterAttached("InputBindings", typeof(InputBindingCollection), typeof(DesignerCanvas), new PropertyMetadata((sender, e) => ((DesignerCanvas)sender).InputBindings.AddRange((InputBindingCollection)e.NewValue)));
162
private EDMDesignerViewContent _container;
163
internal EDMDesignerViewContent Container
171
private new ContextMenu.ContextMenu ContextMenu
175
return Style == null ? (ContextMenu.ContextMenu)null : (ContextMenu.ContextMenu)Style.Resources.OfType<DictionaryEntry>().FirstOrDefault(de => ((string)de.Key) == "ContextMenu").Value;
179
private void InitContextMenuCommandBindings()
184
ContextMenu.ContextMenu contextMenu;
185
StackPanel stackPanel;
187
if ((contextMenu = ContextMenu) != null && (stackPanel = contextMenu.Items.OfType<StackPanel>().FirstOrDefault(sp => sp.Name == ZOOM_STACKPANEL)) != null && (textBox = stackPanel.Children.OfType<TextBox>().FirstOrDefault(etb => etb.Name == ZOOM_TEXTBOX)) != null)
188
textBox.SetBinding(TextBox.TextProperty, new Binding { Source = this, Path = new PropertyPath("Zoom") });
191
CommandBindings.AddRange(
194
new CommandBinding(AddEntityTypeCommand,
197
var csdlView = EDMView.CSDL;
198
var addEntityTypeWindow = new AddEntityTypeWindow(csdlView) { Owner = Container.Window };
199
switch (addEntityTypeWindow.ShowDialog())
202
UITypeToAdd = csdlView.AddEntityType(addEntityTypeWindow.EntityTypeName, addEntityTypeWindow.BaseEntityType);
207
new CommandBinding(AddComplexTypeCommand,
210
var addComplexTypeWindow = new AddComplexTypeWindow { Owner = Container.Window };
211
switch (addComplexTypeWindow.ShowDialog())
214
UITypeToAdd = EDMView.CSDL.AddComplexType(addComplexTypeWindow.ComplexTypeName);
219
new CommandBinding(AddAssociationCommand,
220
AddAssociationExecuted(this, () => EDMView.CSDL, () => DesignerView, null, null)
222
new CommandBinding(RemoveFromDesignerCommand,
223
delegate { RemoveFromDesigner(); },
224
(sender, e) => e.CanExecute = TypesSelected.Any()
226
new CommandBinding(SelectAllCommand,
229
foreach(var types in TypesVisibles)
230
types.IsSelected = true;
232
(sender, e) => e.CanExecute = TypesVisibles.Any()
238
protected override void OnMouseDown(MouseButtonEventArgs e)
242
if (e.LeftButton == MouseButtonState.Pressed)
243
OnMouseLeftButtonDown(e);
245
OnMouseRightButtonDown(e);
249
public static ExecutedRoutedEventHandler AddAssociationExecuted(UIElement parent, Func<CSDLView> getCSDLView, Func<DesignerView> getDesignerView, UIEntityType defaultEntityType1, Action<UIAssociation> specialActionToDoWhenNewItemAdded)
251
return (object sender, ExecutedRoutedEventArgs e) =>
253
var csdlView = getCSDLView();
254
var designerView = getDesignerView();
255
var addAssociationWindow = new AddAssociationWindow { Owner = VisualTreeHelperUtil.GetControlAscendant<Window>(parent), DataContext = csdlView, NavigationProperty1EntityType = defaultEntityType1 };
256
switch (addAssociationWindow.ShowDialog())
259
var uiAssociation = csdlView.AddAssociation(addAssociationWindow.AssociationName, addAssociationWindow.NavigationProperty1Name, addAssociationWindow.NavigationProperty1EntityType, addAssociationWindow.NavigationProperty1Cardinality.Value, addAssociationWindow.NavigationProperty2Name, addAssociationWindow.NavigationProperty2EntityType, addAssociationWindow.NavigationProperty2Cardinality.Value);
260
SizeChangedEventHandler actionToDoWhenNewItemAdded = null;
261
bool drawAssociation = false;
262
DesignerCanvas designerCanvas = parent as DesignerCanvas;
263
if (designerCanvas == null)
264
designerCanvas = VisualTreeHelperUtil.GetControlAscendant<DesignerCanvas>(parent);
265
var navigationProperty1EntityTypeDesigner = designerCanvas.GetTypeDesigner(uiAssociation.NavigationProperty1.ParentType);
266
var navigationProperty2EntityTypeDesigner = designerCanvas.GetTypeDesigner(uiAssociation.NavigationProperty2.ParentType);
267
actionToDoWhenNewItemAdded =
268
(object o, SizeChangedEventArgs scea) =>
270
if (designerView.ContainsEntityType(uiAssociation.NavigationProperty1.ParentType) && designerView.ContainsEntityType(uiAssociation.NavigationProperty2.ParentType))
273
navigationProperty1EntityTypeDesigner.DrawAssociation(navigationProperty2EntityTypeDesigner, uiAssociation.NavigationProperty1.BusinessInstance as NavigationProperty);
275
drawAssociation = true;
277
if (specialActionToDoWhenNewItemAdded != null)
278
specialActionToDoWhenNewItemAdded(uiAssociation);
279
((ListView)o).SizeChanged -= actionToDoWhenNewItemAdded;
281
navigationProperty1EntityTypeDesigner.propertiesListView.SizeChanged += actionToDoWhenNewItemAdded;
282
if (navigationProperty2EntityTypeDesigner != null)
283
navigationProperty2EntityTypeDesigner.propertiesListView.SizeChanged += actionToDoWhenNewItemAdded;