Datei: SimpleMappingTool/MainForm.cs
Last Commit (add8490)
1 | // |
2 | // Copyright (c) 2002-2025 Mirko Matytschak |
3 | // (www.netdataobjects.de) |
4 | // |
5 | // Author: Mirko Matytschak |
6 | // |
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
11 | // conditions: |
12 | |
13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
14 | // of the Software. |
15 | // |
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. |
21 | |
22 | |
23 | using System; |
24 | using System.Reflection; |
25 | using System.IO; |
26 | using System.Text.RegularExpressions; |
27 | using System.Drawing; |
28 | using System.Collections; |
29 | using System.ComponentModel; |
30 | using System.Windows.Forms; |
31 | using NDO.Mapping; |
32 | |
33 | namespace SimpleMappingTool |
34 | { |
35 | ····/// <summary> |
36 | ····/// Zusammenfassung für MainForm. |
37 | ····/// </summary> |
38 | ····internal class MainForm : System.Windows.Forms.Form |
39 | ····{ |
40 | ········private System.ComponentModel.IContainer components; |
41 | private System. Windows. Forms. MainMenu mainMenu; |
42 | private System. Windows. Forms. MenuItem menuItem1; |
43 | ········private System.Windows.Forms.MenuItem menuOpen; |
44 | ········private System.Windows.Forms.MenuItem menuSave; |
45 | ········private System.Windows.Forms.MenuItem menuSaveAs; |
46 | |
47 | ········private bool saveOnClose = false; |
48 | |
49 | ········public MainForm(string[] args) |
50 | ········{ |
51 | ············try |
52 | ············{ |
53 | ················InitializeComponent(); |
54 | ················ScanArgs(args); |
55 | ················Application.Idle += new EventHandler(OnIdle); |
56 | ············} |
57 | ············catch (Exception ex) |
58 | ············{ |
59 | ················MessageBox.Show(ex.ToString(), "Mapping tool error"); |
60 | ············} |
61 | ········} |
62 | |
63 | ········/// <summary> |
64 | ········/// Die verwendeten Ressourcen bereinigen. |
65 | ········/// </summary> |
66 | ········protected override void Dispose( bool disposing ) |
67 | ········{ |
68 | ············if( disposing ) |
69 | ············{ |
70 | ················if (components != null) |
71 | ················{ |
72 | ····················components.Dispose(); |
73 | ················} |
74 | ············} |
75 | ············base.Dispose( disposing ); |
76 | ········} |
77 | |
78 | ········#region Vom Windows Form-Designer generierter Code |
79 | ········/// <summary> |
80 | ········/// Erforderliche Methode für die Designerunterstützung. |
81 | ········/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. |
82 | ········/// </summary> |
83 | ········private void InitializeComponent() |
84 | ········{ |
85 | ············this.components = new System.ComponentModel.Container(); |
86 | ············System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); |
87 | ············this.allObjects = new System.Windows.Forms.TreeView(); |
88 | ············this.imageList1 = new System.Windows.Forms.ImageList(this.components); |
89 | ············this.splitter1 = new System.Windows.Forms.Splitter(); |
90 | ············this.propertyGrid1 = new System.Windows.Forms.PropertyGrid(); |
91 | ············this.mainMenu = new System.Windows.Forms.MainMenu(this.components); |
92 | ············this.menuItem1 = new System.Windows.Forms.MenuItem(); |
93 | ············this.menuOpen = new System.Windows.Forms.MenuItem(); |
94 | ············this.menuSave = new System.Windows.Forms.MenuItem(); |
95 | ············this.menuSaveAs = new System.Windows.Forms.MenuItem(); |
96 | ············this.SuspendLayout(); |
97 | ············// |
98 | ············// allObjects |
99 | ············// |
100 | ············this.allObjects.Dock = System.Windows.Forms.DockStyle.Left; |
101 | ············this.allObjects.ImageIndex = 0; |
102 | ············this.allObjects.ImageList = this.imageList1; |
103 | ············this.allObjects.Location = new System.Drawing.Point(0, 0); |
104 | ············this.allObjects.Name = "allObjects"; |
105 | ············this.allObjects.SelectedImageIndex = 0; |
106 | ············this.allObjects.Size = new System.Drawing.Size(387, 432); |
107 | ············this.allObjects.TabIndex = 0; |
108 | ············this.allObjects.MouseUp += new System.Windows.Forms.MouseEventHandler(this.allObjects_MouseUp); |
109 | ············this.allObjects.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.allObjects_AfterSelect); |
110 | ············// |
111 | ············// imageList1 |
112 | ············// |
113 | ············this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream"))); |
114 | ············this.imageList1.TransparentColor = System.Drawing.Color.Transparent; |
115 | ············this.imageList1.Images.SetKeyName(0, ""); |
116 | ············this.imageList1.Images.SetKeyName(1, ""); |
117 | ············this.imageList1.Images.SetKeyName(2, ""); |
118 | ············this.imageList1.Images.SetKeyName(3, ""); |
119 | ············this.imageList1.Images.SetKeyName(4, ""); |
120 | ············this.imageList1.Images.SetKeyName(5, ""); |
121 | ············this.imageList1.Images.SetKeyName(6, ""); |
122 | ············this.imageList1.Images.SetKeyName(7, ""); |
123 | ············this.imageList1.Images.SetKeyName(8, ""); |
124 | ············this.imageList1.Images.SetKeyName(9, ""); |
125 | ············this.imageList1.Images.SetKeyName(10, ""); |
126 | ············this.imageList1.Images.SetKeyName(11, ""); |
127 | ············this.imageList1.Images.SetKeyName(12, ""); |
128 | ············this.imageList1.Images.SetKeyName(13, ""); |
129 | ············// |
130 | ············// splitter1 |
131 | ············// |
132 | ············this.splitter1.Location = new System.Drawing.Point(387, 0); |
133 | ············this.splitter1.Name = "splitter1"; |
134 | ············this.splitter1.Size = new System.Drawing.Size(2, 432); |
135 | ············this.splitter1.TabIndex = 1; |
136 | ············this.splitter1.TabStop = false; |
137 | ············// |
138 | ············// propertyGrid1 |
139 | ············// |
140 | ············this.propertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill; |
141 | ············this.propertyGrid1.LineColor = System.Drawing.SystemColors.ScrollBar; |
142 | ············this.propertyGrid1.Location = new System.Drawing.Point(389, 0); |
143 | ············this.propertyGrid1.Name = "propertyGrid1"; |
144 | ············this.propertyGrid1.Size = new System.Drawing.Size(395, 432); |
145 | ············this.propertyGrid1.TabIndex = 2; |
146 | ············// |
147 | ············// mainMenu |
148 | ············// |
149 | ············this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { |
150 | ············this.menuItem1}); |
151 | ············// |
152 | ············// menuItem1 |
153 | ············// |
154 | ············this.menuItem1.Index = 0; |
155 | ············this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { |
156 | ············this.menuOpen, |
157 | ············this.menuSave, |
158 | ············this.menuSaveAs}); |
159 | ············this.menuItem1.Text = "&File"; |
160 | ············// |
161 | ············// menuOpen |
162 | ············// |
163 | ············this.menuOpen.Index = 0; |
164 | ············this.menuOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO; |
165 | ············this.menuOpen.Text = "&Open..."; |
166 | ············this.menuOpen.Click += new System.EventHandler(this.menuOpen_Click); |
167 | ············// |
168 | ············// menuSave |
169 | ············// |
170 | ············this.menuSave.Index = 1; |
171 | ············this.menuSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS; |
172 | ············this.menuSave.Text = "&Save"; |
173 | ············this.menuSave.Click += new System.EventHandler(this.menuSave_Click); |
174 | ············// |
175 | ············// menuSaveAs |
176 | ············// |
177 | ············this.menuSaveAs.Index = 2; |
178 | ············this.menuSaveAs.Text = "Save &as..."; |
179 | ············this.menuSaveAs.Click += new System.EventHandler(this.menuSaveAs_Click); |
180 | ············// |
181 | ············// MainForm |
182 | ············// |
183 | ············this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); |
184 | ············this.ClientSize = new System.Drawing.Size(784, 432); |
185 | ············this.Controls.Add(this.propertyGrid1); |
186 | ············this.Controls.Add(this.splitter1); |
187 | ············this.Controls.Add(this.allObjects); |
188 | ············this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); |
189 | ············this.Menu = this.mainMenu; |
190 | ············this.Name = "MainForm"; |
191 | ············this.Text = "NDO Mapping Tool"; |
192 | ············this.Load += new System.EventHandler(this.MainForm_Load); |
193 | ············this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing); |
194 | ············this.ResumeLayout(false); |
195 | |
196 | ········} |
197 | ········#endregion |
198 | |
199 | ········/// <summary> |
200 | ········/// Der Haupteinstiegspunkt für die Anwendung. |
201 | ········/// </summary> |
202 | ········[STAThread] |
203 | ········static void Main(string[] args) |
204 | ········{ |
205 | ············Application.Run(new MainForm(args)); |
206 | ········} |
207 | ········private System.Windows.Forms.Splitter splitter1; |
208 | ········private System.Windows.Forms.PropertyGrid propertyGrid1; |
209 | ········private System.Windows.Forms.TreeView allObjects; |
210 | |
211 | ········private System.Windows.Forms.ImageList imageList1; |
212 | ········NDOMapping mapping = null;············ |
213 | |
214 | |
215 | |
216 | ········private void LoadMapping(string fileName) |
217 | ········{ |
218 | ············allObjects.Nodes.Clear(); |
219 | ············try |
220 | ············{ |
221 | ················mapping = new NDOMapping(fileName); |
222 | ················PrepareRelations(); |
223 | ············} |
224 | ············catch (Exception ex) |
225 | ············{ |
226 | ················mapping = null; |
227 | ················this.Text = string.Empty; |
228 | #if DEBUG |
229 | ················MessageBox.Show(ex.ToString(), "Error"); |
230 | #else |
231 | ················MessageBox.Show(ex.Message, "Error"); |
232 | #endif |
233 | ················return; |
234 | ············} |
235 | ············this.Text = fileName; |
236 | ············FillNodes(); |
237 | ········} |
238 | |
239 | |
240 | ········private void FillNodes() |
241 | ········{ |
242 | ············NDOMappingNode mn = new NDOMappingNode(this.mapping); |
243 | ············allObjects.Nodes.Add(mn); |
244 | ········} |
245 | |
246 | ········private void ScanArgs(string[] args) |
247 | ········{ |
248 | ············Regex regexm = new Regex(@"-m:(.*)"); |
249 | ············foreach (string arg in args) |
250 | ············{ |
251 | ················Match matchm = regexm.Match(arg); |
252 | ················if (matchm.Success) |
253 | ················{ |
254 | ····················LoadMapping(matchm.Groups[1].Value); |
255 | ····················saveOnClose = true; |
256 | ················} |
257 | ············} |
258 | ········} |
259 | |
260 | |
261 | ········private void MainForm_Load(object sender, System.EventArgs e) |
262 | ········{ |
263 | ············//ScanArgs(new string[] {@"-m:C:\Projekte\Persistenz\v4\TestEnhancerVersion4\PureBusinessClasses\NDOMapping.xml"}); |
264 | ········} |
265 | |
266 | ········private void allObjects_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) |
267 | ········{ |
268 | ············NDOTreeNode tn = e.Node as NDOTreeNode; |
269 | ············if (tn != null) |
270 | ················this.propertyGrid1.SelectedObject = tn.Object; |
271 | ············else |
272 | ················this.propertyGrid1.SelectedObject = null; |
273 | ········} |
274 | |
275 | ········private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e) |
276 | ········{ |
277 | ············if (saveOnClose && mapping != null) |
278 | ················mapping.Save(); |
279 | ············else if (mapping != null && mapping.HasChanges) |
280 | ············{ |
281 | ················if (MessageBox.Show("Save changes?", "NDO Mapping Tool", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) |
282 | ················{ |
283 | ····················mapping.Save(); |
284 | ················}················ |
285 | ············} |
286 | ········} |
287 | |
288 | ········private void menuOpen_Click(object sender, System.EventArgs e) |
289 | ········{ |
290 | ············if (mapping != null && mapping.HasChanges) |
291 | ············{ |
292 | ················if (MessageBox.Show("Save changes?", "Mapping Tool", MessageBoxButtons.YesNo) == DialogResult.Yes) |
293 | ················{ |
294 | ····················mapping.Save(); |
295 | ····················mapping = null; |
296 | ················} |
297 | ············} |
298 | |
299 | ············OpenFileDialog ofd = new OpenFileDialog(); |
300 | ············ofd.CheckFileExists = true; |
301 | ············ofd.DefaultExt = "xml"; |
302 | ············ofd.Multiselect = false; |
303 | ············ofd.Filter = "Mapping Files (*.xml)|*.xml"; |
304 | ············ofd.FileName = "NDOMapping.xml"; |
305 | ············if (ofd.ShowDialog() == DialogResult.Cancel) |
306 | ················return; |
307 | ············LoadMapping(ofd.FileName); |
308 | ········} |
309 | |
310 | |
311 | ········bool PrepareRelations() |
312 | ········{ |
313 | ············bool result = false; |
314 | ············foreach (Class cl in mapping.Classes) |
315 | ············{ |
316 | ················foreach (Relation r in cl.Relations) |
317 | ················{ |
318 | ····················// This computes the foreign relation, which is |
319 | ····················// needed to avoid a null pointer exception |
320 | ····················// while binding to the property grid. |
321 | ····················result = result || r.Bidirectional; |
322 | ················} |
323 | ············} |
324 | ············return result;··// Nobody reads this value, but we make shure, that the code won't get removed by the optimizer. |
325 | ········} |
326 | |
327 | |
328 | ········private void menuSave_Click(object sender, System.EventArgs e) |
329 | ········{ |
330 | ············mapping.Save(); |
331 | ········} |
332 | |
333 | ········private void menuSaveAs_Click(object sender, System.EventArgs e) |
334 | ········{ |
335 | ············SaveFileDialog sfd = new SaveFileDialog(); |
336 | ············if (mapping != null && mapping.FileName != string.Empty) |
337 | ················sfd.InitialDirectory = Path.GetDirectoryName(mapping.FileName); |
338 | ············sfd.CheckFileExists = false; |
339 | ············sfd.DefaultExt = "xml"; |
340 | ············sfd.Filter = "Mapping Files (*.xml)|*.xml"; |
341 | ············sfd.FileName = "NDOMapping.xml"; |
342 | ············if (sfd.ShowDialog(this) != DialogResult.OK) |
343 | ················return; |
344 | ············mapping.SaveAs(sfd.FileName); |
345 | ············this.Text = sfd.FileName; |
346 | ········} |
347 | |
348 | ········private void OnIdle(object sender, EventArgs e) |
349 | ········{ |
350 | ············menuSave.Enabled = mapping != null && mapping.HasChanges; |
351 | ············menuOpen.Enabled = !saveOnClose; |
352 | ········} |
353 | |
354 | #if DEBUG |
355 | ········private void MainForm_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) |
356 | ········{ |
357 | |
358 | ············if ((int) e.KeyChar == 27) |
359 | ················MessageBox.Show("Escape"); |
360 | ········} |
361 | #endif |
362 | |
363 | ········private void allObjects_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) |
364 | ········{ |
365 | ············ |
366 | ············if (e.Button == MouseButtons.Right) |
367 | ············{ |
368 | ················NDOTreeNode tn = this.allObjects.GetNodeAt(e.X, e.Y) as NDOTreeNode; |
369 | ················if (tn != null) |
370 | ················{ |
371 | ····················allObjects.SelectedNode = tn; |
372 | ····················ContextMenu menu = tn.GetContextMenu(); |
373 | ····················if (menu.MenuItems.Count > 0) |
374 | ························menu.Show(allObjects, new Point(e.X, e.Y)); |
375 | ····················this.propertyGrid1.SelectedObject = tn.Object; |
376 | ················} |
377 | ············} |
378 | ········} |
379 | |
380 | ····} |
381 | } |
382 |
New Commit (2ee4f7f)
1 | // |
2 | // Copyright (c) 2002-2025 Mirko Matytschak |
3 | // (www.netdataobjects.de) |
4 | // |
5 | // Author: Mirko Matytschak |
6 | // |
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
11 | // conditions: |
12 | |
13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
14 | // of the Software. |
15 | // |
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. |
21 | |
22 | |
23 | using System; |
24 | using System.Reflection; |
25 | using System.IO; |
26 | using System.Text.RegularExpressions; |
27 | using System.Drawing; |
28 | using System.Collections; |
29 | using System.ComponentModel; |
30 | using System.Windows.Forms; |
31 | using NDO.Mapping; |
32 | |
33 | namespace SimpleMappingTool |
34 | { |
35 | ····/// <summary> |
36 | ····/// Zusammenfassung für MainForm. |
37 | ····/// </summary> |
38 | ····internal class MainForm : System.Windows.Forms.Form |
39 | ····{ |
40 | ········private System.ComponentModel.IContainer components; |
41 | private MainMenu mainMenu; |
42 | private MenuItem menuItem1; |
43 | ········private System.Windows.Forms.MenuItem menuOpen; |
44 | ········private System.Windows.Forms.MenuItem menuSave; |
45 | ········private System.Windows.Forms.MenuItem menuSaveAs; |
46 | |
47 | ········private bool saveOnClose = false; |
48 | |
49 | ········public MainForm(string[] args) |
50 | ········{ |
51 | ············try |
52 | ············{ |
53 | ················InitializeComponent(); |
54 | ················ScanArgs(args); |
55 | ················Application.Idle += new EventHandler(OnIdle); |
56 | ············} |
57 | ············catch (Exception ex) |
58 | ············{ |
59 | ················MessageBox.Show(ex.ToString(), "Mapping tool error"); |
60 | ············} |
61 | ········} |
62 | |
63 | ········/// <summary> |
64 | ········/// Die verwendeten Ressourcen bereinigen. |
65 | ········/// </summary> |
66 | ········protected override void Dispose( bool disposing ) |
67 | ········{ |
68 | ············if( disposing ) |
69 | ············{ |
70 | ················if (components != null) |
71 | ················{ |
72 | ····················components.Dispose(); |
73 | ················} |
74 | ············} |
75 | ············base.Dispose( disposing ); |
76 | ········} |
77 | |
78 | ········#region Vom Windows Form-Designer generierter Code |
79 | ········/// <summary> |
80 | ········/// Erforderliche Methode für die Designerunterstützung. |
81 | ········/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. |
82 | ········/// </summary> |
83 | ········private void InitializeComponent() |
84 | ········{ |
85 | ············this.components = new System.ComponentModel.Container(); |
86 | ············System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); |
87 | ············this.allObjects = new System.Windows.Forms.TreeView(); |
88 | ············this.imageList1 = new System.Windows.Forms.ImageList(this.components); |
89 | ············this.splitter1 = new System.Windows.Forms.Splitter(); |
90 | ············this.propertyGrid1 = new System.Windows.Forms.PropertyGrid(); |
91 | ············this.mainMenu = new System.Windows.Forms.MainMenu(this.components); |
92 | ············this.menuItem1 = new System.Windows.Forms.MenuItem(); |
93 | ············this.menuOpen = new System.Windows.Forms.MenuItem(); |
94 | ············this.menuSave = new System.Windows.Forms.MenuItem(); |
95 | ············this.menuSaveAs = new System.Windows.Forms.MenuItem(); |
96 | ············this.SuspendLayout(); |
97 | ············// |
98 | ············// allObjects |
99 | ············// |
100 | ············this.allObjects.Dock = System.Windows.Forms.DockStyle.Left; |
101 | ············this.allObjects.ImageIndex = 0; |
102 | ············this.allObjects.ImageList = this.imageList1; |
103 | ············this.allObjects.Location = new System.Drawing.Point(0, 0); |
104 | ············this.allObjects.Name = "allObjects"; |
105 | ············this.allObjects.SelectedImageIndex = 0; |
106 | ············this.allObjects.Size = new System.Drawing.Size(387, 432); |
107 | ············this.allObjects.TabIndex = 0; |
108 | ············this.allObjects.MouseUp += new System.Windows.Forms.MouseEventHandler(this.allObjects_MouseUp); |
109 | ············this.allObjects.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.allObjects_AfterSelect); |
110 | ············// |
111 | ············// imageList1 |
112 | ············// |
113 | ············this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream"))); |
114 | ············this.imageList1.TransparentColor = System.Drawing.Color.Transparent; |
115 | ············this.imageList1.Images.SetKeyName(0, ""); |
116 | ············this.imageList1.Images.SetKeyName(1, ""); |
117 | ············this.imageList1.Images.SetKeyName(2, ""); |
118 | ············this.imageList1.Images.SetKeyName(3, ""); |
119 | ············this.imageList1.Images.SetKeyName(4, ""); |
120 | ············this.imageList1.Images.SetKeyName(5, ""); |
121 | ············this.imageList1.Images.SetKeyName(6, ""); |
122 | ············this.imageList1.Images.SetKeyName(7, ""); |
123 | ············this.imageList1.Images.SetKeyName(8, ""); |
124 | ············this.imageList1.Images.SetKeyName(9, ""); |
125 | ············this.imageList1.Images.SetKeyName(10, ""); |
126 | ············this.imageList1.Images.SetKeyName(11, ""); |
127 | ············this.imageList1.Images.SetKeyName(12, ""); |
128 | ············this.imageList1.Images.SetKeyName(13, ""); |
129 | ············// |
130 | ············// splitter1 |
131 | ············// |
132 | ············this.splitter1.Location = new System.Drawing.Point(387, 0); |
133 | ············this.splitter1.Name = "splitter1"; |
134 | ············this.splitter1.Size = new System.Drawing.Size(2, 432); |
135 | ············this.splitter1.TabIndex = 1; |
136 | ············this.splitter1.TabStop = false; |
137 | ············// |
138 | ············// propertyGrid1 |
139 | ············// |
140 | ············this.propertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill; |
141 | ············this.propertyGrid1.LineColor = System.Drawing.SystemColors.ScrollBar; |
142 | ············this.propertyGrid1.Location = new System.Drawing.Point(389, 0); |
143 | ············this.propertyGrid1.Name = "propertyGrid1"; |
144 | ············this.propertyGrid1.Size = new System.Drawing.Size(395, 432); |
145 | ············this.propertyGrid1.TabIndex = 2; |
146 | ············// |
147 | ············// mainMenu |
148 | ············// |
149 | ············this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { |
150 | ············this.menuItem1}); |
151 | ············// |
152 | ············// menuItem1 |
153 | ············// |
154 | ············this.menuItem1.Index = 0; |
155 | ············this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { |
156 | ············this.menuOpen, |
157 | ············this.menuSave, |
158 | ············this.menuSaveAs}); |
159 | ············this.menuItem1.Text = "&File"; |
160 | ············// |
161 | ············// menuOpen |
162 | ············// |
163 | ············this.menuOpen.Index = 0; |
164 | ············this.menuOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO; |
165 | ············this.menuOpen.Text = "&Open..."; |
166 | ············this.menuOpen.Click += new System.EventHandler(this.menuOpen_Click); |
167 | ············// |
168 | ············// menuSave |
169 | ············// |
170 | ············this.menuSave.Index = 1; |
171 | ············this.menuSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS; |
172 | ············this.menuSave.Text = "&Save"; |
173 | ············this.menuSave.Click += new System.EventHandler(this.menuSave_Click); |
174 | ············// |
175 | ············// menuSaveAs |
176 | ············// |
177 | ············this.menuSaveAs.Index = 2; |
178 | ············this.menuSaveAs.Text = "Save &as..."; |
179 | ············this.menuSaveAs.Click += new System.EventHandler(this.menuSaveAs_Click); |
180 | ············// |
181 | ············// MainForm |
182 | ············// |
183 | ············this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); |
184 | ············this.ClientSize = new System.Drawing.Size(784, 432); |
185 | ············this.Controls.Add(this.propertyGrid1); |
186 | ············this.Controls.Add(this.splitter1); |
187 | ············this.Controls.Add(this.allObjects); |
188 | ············this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); |
189 | ············this.Menu = this.mainMenu; |
190 | ············this.Name = "MainForm"; |
191 | ············this.Text = "NDO Mapping Tool"; |
192 | ············this.Load += new System.EventHandler(this.MainForm_Load); |
193 | ············this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing); |
194 | ············this.ResumeLayout(false); |
195 | |
196 | ········} |
197 | ········#endregion |
198 | |
199 | ········/// <summary> |
200 | ········/// Der Haupteinstiegspunkt für die Anwendung. |
201 | ········/// </summary> |
202 | ········[STAThread] |
203 | ········static void Main(string[] args) |
204 | ········{ |
205 | ············Application.Run(new MainForm(args)); |
206 | ········} |
207 | ········private System.Windows.Forms.Splitter splitter1; |
208 | ········private System.Windows.Forms.PropertyGrid propertyGrid1; |
209 | ········private System.Windows.Forms.TreeView allObjects; |
210 | |
211 | ········private System.Windows.Forms.ImageList imageList1; |
212 | ········NDOMapping mapping = null;············ |
213 | |
214 | |
215 | |
216 | ········private void LoadMapping(string fileName) |
217 | ········{ |
218 | ············allObjects.Nodes.Clear(); |
219 | ············try |
220 | ············{ |
221 | ················mapping = new NDOMapping(fileName); |
222 | ················PrepareRelations(); |
223 | ············} |
224 | ············catch (Exception ex) |
225 | ············{ |
226 | ················mapping = null; |
227 | ················this.Text = string.Empty; |
228 | #if DEBUG |
229 | ················MessageBox.Show(ex.ToString(), "Error"); |
230 | #else |
231 | ················MessageBox.Show(ex.Message, "Error"); |
232 | #endif |
233 | ················return; |
234 | ············} |
235 | ············this.Text = fileName; |
236 | ············FillNodes(); |
237 | ········} |
238 | |
239 | |
240 | ········private void FillNodes() |
241 | ········{ |
242 | ············NDOMappingNode mn = new NDOMappingNode(this.mapping); |
243 | ············allObjects.Nodes.Add(mn); |
244 | ········} |
245 | |
246 | ········private void ScanArgs(string[] args) |
247 | ········{ |
248 | ············Regex regexm = new Regex(@"-m:(.*)"); |
249 | ············foreach (string arg in args) |
250 | ············{ |
251 | ················Match matchm = regexm.Match(arg); |
252 | ················if (matchm.Success) |
253 | ················{ |
254 | ····················LoadMapping(matchm.Groups[1].Value); |
255 | ····················saveOnClose = true; |
256 | ················} |
257 | ············} |
258 | ········} |
259 | |
260 | |
261 | ········private void MainForm_Load(object sender, System.EventArgs e) |
262 | ········{ |
263 | ············//ScanArgs(new string[] {@"-m:C:\Projekte\Persistenz\v4\TestEnhancerVersion4\PureBusinessClasses\NDOMapping.xml"}); |
264 | ········} |
265 | |
266 | ········private void allObjects_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) |
267 | ········{ |
268 | ············NDOTreeNode tn = e.Node as NDOTreeNode; |
269 | ············if (tn != null) |
270 | ················this.propertyGrid1.SelectedObject = tn.Object; |
271 | ············else |
272 | ················this.propertyGrid1.SelectedObject = null; |
273 | ········} |
274 | |
275 | ········private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e) |
276 | ········{ |
277 | ············if (saveOnClose && mapping != null) |
278 | ················mapping.Save(); |
279 | ············else if (mapping != null && mapping.HasChanges) |
280 | ············{ |
281 | ················if (MessageBox.Show("Save changes?", "NDO Mapping Tool", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) |
282 | ················{ |
283 | ····················mapping.Save(); |
284 | ················}················ |
285 | ············} |
286 | ········} |
287 | |
288 | ········private void menuOpen_Click(object sender, System.EventArgs e) |
289 | ········{ |
290 | ············if (mapping != null && mapping.HasChanges) |
291 | ············{ |
292 | ················if (MessageBox.Show("Save changes?", "Mapping Tool", MessageBoxButtons.YesNo) == DialogResult.Yes) |
293 | ················{ |
294 | ····················mapping.Save(); |
295 | ····················mapping = null; |
296 | ················} |
297 | ············} |
298 | |
299 | ············OpenFileDialog ofd = new OpenFileDialog(); |
300 | ············ofd.CheckFileExists = true; |
301 | ············ofd.DefaultExt = "xml"; |
302 | ············ofd.Multiselect = false; |
303 | ············ofd.Filter = "Mapping Files (*.xml)|*.xml"; |
304 | ············ofd.FileName = "NDOMapping.xml"; |
305 | ············if (ofd.ShowDialog() == DialogResult.Cancel) |
306 | ················return; |
307 | ············LoadMapping(ofd.FileName); |
308 | ········} |
309 | |
310 | |
311 | ········bool PrepareRelations() |
312 | ········{ |
313 | ············bool result = false; |
314 | ············foreach (Class cl in mapping.Classes) |
315 | ············{ |
316 | ················foreach (Relation r in cl.Relations) |
317 | ················{ |
318 | ····················// This computes the foreign relation, which is |
319 | ····················// needed to avoid a null pointer exception |
320 | ····················// while binding to the property grid. |
321 | ····················result = result || r.Bidirectional; |
322 | ················} |
323 | ············} |
324 | ············return result;··// Nobody reads this value, but we make shure, that the code won't get removed by the optimizer. |
325 | ········} |
326 | |
327 | |
328 | ········private void menuSave_Click(object sender, System.EventArgs e) |
329 | ········{ |
330 | ············mapping.Save(); |
331 | ········} |
332 | |
333 | ········private void menuSaveAs_Click(object sender, System.EventArgs e) |
334 | ········{ |
335 | ············SaveFileDialog sfd = new SaveFileDialog(); |
336 | ············if (mapping != null && mapping.FileName != string.Empty) |
337 | ················sfd.InitialDirectory = Path.GetDirectoryName(mapping.FileName); |
338 | ············sfd.CheckFileExists = false; |
339 | ············sfd.DefaultExt = "xml"; |
340 | ············sfd.Filter = "Mapping Files (*.xml)|*.xml"; |
341 | ············sfd.FileName = "NDOMapping.xml"; |
342 | ············if (sfd.ShowDialog(this) != DialogResult.OK) |
343 | ················return; |
344 | ············mapping.SaveAs(sfd.FileName); |
345 | ············this.Text = sfd.FileName; |
346 | ········} |
347 | |
348 | ········private void OnIdle(object sender, EventArgs e) |
349 | ········{ |
350 | ············menuSave.Enabled = mapping != null && mapping.HasChanges; |
351 | ············menuOpen.Enabled = !saveOnClose; |
352 | ········} |
353 | |
354 | #if DEBUG |
355 | ········private void MainForm_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) |
356 | ········{ |
357 | |
358 | ············if ((int) e.KeyChar == 27) |
359 | ················MessageBox.Show("Escape"); |
360 | ········} |
361 | #endif |
362 | |
363 | ········private void allObjects_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) |
364 | ········{ |
365 | ············ |
366 | ············if (e.Button == MouseButtons.Right) |
367 | ············{ |
368 | ················NDOTreeNode tn = this.allObjects.GetNodeAt(e.X, e.Y) as NDOTreeNode; |
369 | ················if (tn != null) |
370 | ················{ |
371 | ····················allObjects.SelectedNode = tn; |
372 | ····················ContextMenu menu = tn.GetContextMenu(); |
373 | ····················if (menu.MenuItems.Count > 0) |
374 | ························menu.Show(allObjects, new Point(e.X, e.Y)); |
375 | ····················this.propertyGrid1.SelectedObject = tn.Object; |
376 | ················} |
377 | ············} |
378 | ········} |
379 | |
380 | ····} |
381 | } |
382 |