Datei: SimpleMappingTool/MainForm.cs

Last Commit (443f0d3)
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 : Form
39 ····{
40 ········private IContainer components;
41 ········private MenuStrip mainMenu;
42 ········private ToolStripMenuItem fileToolStripMenuItem;
43 ········private ToolStripMenuItem menuOpen;
44 ········private ToolStripMenuItem menuSave;
45 ········private ToolStripMenuItem menuSaveAs;
46 ········private bool saveOnClose = false;
47 ········private Splitter splitter1;
48 ········private PropertyGrid propertyGrid1;
49 ········private TreeView allObjects;
50 ········private ImageList imageList1;
51
 
 
52 ········NDOMapping? mapping = null;
53
54 #pragma warning disable 8618
55 ········public MainForm( string[] args )
56 ········{
57 ············try
58 ············{
 
59 ················InitializeComponent();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60 ················ScanArgs( args );
61 ················Application.Idle += new EventHandler( OnIdle );
62 ············}
63 ············catch (Exception ex)
64 ············{
65 ················MessageBox.Show( ex.ToString(), "Mapping tool error" );
66 ············}
67 ········}
68 #pragma warning restore 8618
69
70 ········/// <summary>
71 ········/// Die verwendeten Ressourcen bereinigen.
72 ········/// </summary>
73 ········protected override void Dispose( bool disposing )
74 ········{
75 ············if (disposing)
76 ············{
77 ················if (components != null)
78 ················{
79 ····················components.Dispose();
80 ················}
81 ············}
82 ············base.Dispose( disposing );
83 ········}
84
85 ········#region Vom Windows Form-Designer generierter Code
86 ········/// <summary>
87 ········/// Erforderliche Methode für die Designerunterstützung.
88 ········/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
89 ········/// </summary>
90 ········private void InitializeComponent()
91 ········{
92 ············components = new Container();
93 ············ComponentResourceManager resources = new ComponentResourceManager(typeof(MainForm));
94 ············allObjects = new TreeView();
95 ············imageList1 = new ImageList( components );
96 ············splitter1 = new Splitter();
97 ············propertyGrid1 = new PropertyGrid();
98 ············mainMenu = new MenuStrip();
99 ············fileToolStripMenuItem = new ToolStripMenuItem();
100 ············menuOpen = new ToolStripMenuItem();
101 ············menuSave = new ToolStripMenuItem();
102 ············menuSaveAs = new ToolStripMenuItem();
 
 
103 ············mainMenu.SuspendLayout();
 
104 ············SuspendLayout();
105 ············//
106 ············// allObjects
107 ············//
108 ············allObjects.Dock = DockStyle.Left;
109 ············allObjects.ImageIndex = 0;
110 ············allObjects.ImageList = imageList1;
111 ············allObjects.Location = new Point( 0, 24 );
112 ············allObjects.Name = "allObjects";
113 ············allObjects.SelectedImageIndex = 0;
114 ············allObjects.Size = new Size( 464, 408 );
115 ············allObjects.TabIndex = 0;
116 ············allObjects.AfterSelect +=··allObjects_AfterSelect ;
117 ············allObjects.MouseUp +=··allObjects_MouseUp ;
118 ············//
119 ············// imageList1
120 ············//
121 ············imageList1.ColorDepth = ColorDepth.Depth8Bit;
122 imageList1. ImageStream = ( ImageListStreamer) resources. GetObject( "imageList1. ImageStream" ) !;
123 ············imageList1.TransparentColor = Color.Transparent;
124 ············imageList1.Images.SetKeyName( 0, "" );
125 ············imageList1.Images.SetKeyName( 1, "" );
126 ············imageList1.Images.SetKeyName( 2, "" );
127 ············imageList1.Images.SetKeyName( 3, "" );
128 ············imageList1.Images.SetKeyName( 4, "" );
129 ············imageList1.Images.SetKeyName( 5, "" );
130 ············imageList1.Images.SetKeyName( 6, "" );
131 ············imageList1.Images.SetKeyName( 7, "" );
132 ············imageList1.Images.SetKeyName( 8, "" );
133 ············imageList1.Images.SetKeyName( 9, "" );
134 ············imageList1.Images.SetKeyName( 10, "" );
135 ············imageList1.Images.SetKeyName( 11, "" );
136 ············imageList1.Images.SetKeyName( 12, "" );
137 ············imageList1.Images.SetKeyName( 13, "" );
138 ············//
139 ············// splitter1
140 ············//
141 ············splitter1.Location = new Point( 464, 24 );
142 ············splitter1.Name = "splitter1";
143 ············splitter1.Size = new Size( 3, 408 );
144 ············splitter1.TabIndex = 1;
145 ············splitter1.TabStop = false;
146 ············//
147 ············// propertyGrid1
148 ············//
149 ············propertyGrid1.Dock = DockStyle.Fill;
150 ············propertyGrid1.LineColor = SystemColors.ScrollBar;
151 ············propertyGrid1.Location = new Point( 467, 24 );
152 ············propertyGrid1.Name = "propertyGrid1";
153 ············propertyGrid1.Size = new Size( 317, 408 );
154 ············propertyGrid1.TabIndex = 2;
155 ············//
156 ············// mainMenu
157 ············//
158 ············mainMenu.Items.AddRange( new ToolStripItem[] { fileToolStripMenuItem } );
159 ············mainMenu.Location = new Point( 0, 0 );
160 ············mainMenu.Name = "mainMenu";
161 ············mainMenu.Size = new Size( 784, 24 );
162 ············mainMenu.TabIndex = 0;
163 ············mainMenu.Text = "mainMenu";
164 ············//
165 ············// fileToolStripMenuItem
166 ············//
167 ············fileToolStripMenuItem.DropDownItems.AddRange( new ToolStripItem[] { menuOpen, menuSave, menuSaveAs } );
168 ············fileToolStripMenuItem.Name = "fileToolStripMenuItem";
169 ············fileToolStripMenuItem.Size = new Size( 37, 20 );
170 ············fileToolStripMenuItem.Text = "&File";
171 ············//
172 ············// menuOpen
173 ············//
174 ············menuOpen.Name = "menuOpen";
175 menuOpen. Size = new Size( 180, 22 ) ;
176 ············menuOpen.Text = "&Open";
177 ············menuOpen.Click +=··menuOpen_Click ;
178 ············//
179 ············// menuSave
180 ············//
181 ············menuSave.Name = "menuSave";
182 menuSave. Size = new Size( 180, 22 ) ;
183 ············menuSave.Text = "&Save";
184 ············menuSave.Click +=··menuSave_Click ;
185 ············//
186 ············// menuSaveAs
187 ············//
188 ············menuSaveAs.Name = "menuSaveAs";
189 menuSaveAs. Size = new Size( 180, 22 ) ;
190 ············menuSaveAs.Text = "Save &as...";
191 ············menuSaveAs.Click +=··menuSaveAs_Click ;
192 ············//
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193 ············// MainForm
194 ············//
195 ············AutoScaleBaseSize = new Size( 6, 16 );
196 ············ClientSize = new Size( 784, 432 );
197 Controls. Add( propertyGrid1 ) ;
198 ············Controls.Add( splitter1 );
199 ············Controls.Add( allObjects );
200 ············Controls.Add( mainMenu );
201 ············Icon = (Icon) resources.GetObject( "$this.Icon" )!;
202 ············MainMenuStrip = mainMenu;
203 ············Name = "MainForm";
204 ············Text = "NDO Mapping Tool";
205 ············Closing +=··MainForm_Closing ;
206 ············Load +=··MainForm_Load ;
207 ············mainMenu.ResumeLayout( false );
208 ············mainMenu.PerformLayout();
 
209 ············ResumeLayout( false );
210 ············PerformLayout();
211 ········}
212 ········#endregion
213
214 ········/// <summary>
215 ········/// Der Haupteinstiegspunkt für die Anwendung.
216 ········/// </summary>
217 ········[STAThread]
218 ········static void Main( string[] args )
219 ········{
220 ············Application.Run( new MainForm( args ) );
221 ········}
222
223 ········private void LoadMapping( string fileName )
224 ········{
225 ············allObjects.Nodes.Clear();
226 ············try
227 ············{
228 ················mapping = new NDOMapping( fileName, null );
229 ················PrepareRelations();
230 ············}
231 ············catch (Exception ex)
232 ············{
233 ················mapping = null;
234 ················this.Text = string.Empty;
235 #if DEBUG
236 ················MessageBox.Show( ex.ToString(), "Error" );
237 #else
238 ················MessageBox.Show(ex.Message, "Error");
239 #endif
240 ················return;
241 ············}
242 ············this.Text = fileName;
243 ············if (mapping != null)
244 ················FillNodes();
245 ········}
246
247
248 ········private void FillNodes()
249 ········{
250 ············NDOMappingNode mn = new NDOMappingNode(this.mapping!);
251 ············allObjects.Nodes.Add( mn );
252 ········}
253
254 ········private void ScanArgs( string[] args )
255 ········{
256 ············Regex regexm = new Regex(@"-m:(.*)");
257 ············foreach (string arg in args)
258 ············{
259 ················Match matchm = regexm.Match(arg);
260 ················if (matchm.Success)
261 ················{
262 ····················LoadMapping( matchm.Groups[1].Value );
263 ····················saveOnClose = true;
264 ················}
265 ············}
266 ········}
267
268
269 ········private void MainForm_Load( object? sender, System.EventArgs e )
270 ········{
271 ········}
272
273 ········private void allObjects_AfterSelect( object? sender, TreeViewEventArgs e )
274 ········{
275 ············var tn = e.Node as NDOTreeNode;
276 ············if (tn != null)
277 ················this.propertyGrid1.SelectedObject = tn.Object;
278 ············else
279 ················this.propertyGrid1.SelectedObject = null;
280 ········}
281
282 ········private void MainForm_Closing( object? sender, System.ComponentModel.CancelEventArgs e )
283 ········{
284 ············if (saveOnClose && mapping != null)
285 ················mapping.Save();
286 ············else if (mapping != null && mapping.HasChanges)
287 ············{
288 ················if (MessageBox.Show( "Save changes?", "NDO Mapping Tool", MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.Yes)
289 ················{
290 ····················mapping.Save();
291 ················}
292 ············}
293 ········}
294
295 ········private void menuOpen_Click( object? sender, System.EventArgs e )
296 ········{
297 ············if (mapping != null && mapping.HasChanges)
298 ············{
299 ················if (MessageBox.Show( "Save changes?", "Mapping Tool", MessageBoxButtons.YesNo ) == DialogResult.Yes)
300 ················{
301 ····················mapping.Save();
302 ····················mapping = null;
303 ················}
304 ············}
305
306 ············OpenFileDialog ofd = new OpenFileDialog();
307 ············ofd.CheckFileExists = true;
308 ············ofd.DefaultExt = "xml";
309 ············ofd.Multiselect = false;
310 ············ofd.Filter = "Mapping Files (*.xml)|*.xml";
311 ············ofd.FileName = "NDOMapping.xml";
312 ············if (ofd.ShowDialog() == DialogResult.Cancel)
313 ················return;
314 ············LoadMapping( ofd.FileName );
315 ········}
316
317
318 ········bool PrepareRelations()
319 ········{
320 ············bool result = false;
321 ············if (mapping != null)
322 ············{
323 ················foreach (Class cl in mapping.Classes)
324 ················{
325 ····················foreach (Relation r in cl.Relations)
326 ····················{
327 ························// This computes the foreign relation, which is
328 ························// needed to avoid a null pointer exception
329 ························// while binding to the property grid.
330 ························result = result || r.Bidirectional;
331 ····················}
332 ················}
333 ············}
334
335 ············return result;··// Nobody reads this value, but we make shure, that the code won't get removed by the optimizer.
336 ········}
337
338
339 ········private void menuSave_Click( object? sender, System.EventArgs e )
340 ········{
341 ············if (mapping != null)
342 ················mapping.Save();
343 ········}
344
345 ········private void menuSaveAs_Click( object? sender, System.EventArgs e )
346 ········{
347 ············if (mapping != null)
348 ············{
349 ················SaveFileDialog sfd = new SaveFileDialog();
350 ················if (mapping.FileName != string.Empty)
351 ····················sfd.InitialDirectory = Path.GetDirectoryName( mapping.FileName );
352 ················sfd.CheckFileExists = false;
353 ················sfd.DefaultExt = "xml";
354 ················sfd.Filter = "Mapping Files (*.xml)|*.xml";
355 ················sfd.FileName = "NDOMapping.xml";
356 ················if (sfd.ShowDialog( this ) != DialogResult.OK)
357 ····················return;
358 ················mapping.SaveAs( sfd.FileName );
359 ················this.Text = sfd.FileName;
360 ············}
361 ········}
362
363 ········private void OnIdle( object? sender, EventArgs e )
364 ········{
365 ············menuSave.Enabled = mapping != null && mapping.HasChanges;
366 ············menuOpen.Enabled = !saveOnClose;
367 ········}
368
369 #if DEBUG
370 ········private void MainForm_KeyPress( object? sender, KeyPressEventArgs e )
371 ········{
372
373 ············if ((int) e.KeyChar == 27)
374 ················MessageBox.Show( "Escape" );
375 ········}
376 #endif
377
378 ········private void allObjects_MouseUp( object? sender, MouseEventArgs e )
379 ········{
380
381 ············if (e.Button == MouseButtons.Right)
382 ············{
383 ················var tn = this.allObjects.GetNodeAt(e.X, e.Y) as NDOTreeNode;
384 ················if (tn != null)
385 ················{
386 ····················allObjects.SelectedNode = tn;
387 ····················var menu = tn.GetContextMenu();
388 ····················if (menu.Items.Count > 0)
389 ························menu.Show(allObjects, new Point(e.X, e.Y));
390 ····················this.propertyGrid1.SelectedObject = tn.Object;
391 ················}
392 ············}
393 ········}
394 ····}
395 }
396
New Commit (a5a7f46)
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 NDO. Mapping;
24 using System. ComponentModel;
 
25 using System.Text.RegularExpressions;
 
 
 
 
 
26
27 namespace SimpleMappingTool
28 {
29 ····/// <summary>
30 ····/// Zusammenfassung für MainForm.
31 ····/// </summary>
32 ····internal class MainForm : Form
33 ····{
34 ········private IContainer components;
35 ········private MenuStrip mainMenu;
36 ········private ToolStripMenuItem fileToolStripMenuItem;
37 ········private ToolStripMenuItem menuOpen;
38 ········private ToolStripMenuItem menuSave;
39 ········private ToolStripMenuItem menuSaveAs;
40 ········private bool saveOnClose = false;
41 ········private Splitter splitter1;
 
42 ········private TreeView allObjects;
43 ········private ImageList imageList1;
44 private ComponentResourceManager resources;
45 ········private Panel panel1;
46 ········private PropertyGrid propertyGrid1;
47 ········NDOMapping? mapping = null;
48
49 #pragma warning disable 8618
50 ········public MainForm( string[] args )
51 ········{
52 ············try
53 ············{
54 ················this.resources = new ComponentResourceManager( typeof( MainForm ) );
55 ················InitializeComponent();
56 ················this.imageList1!.ImageStream = (ImageListStreamer) resources.GetObject( "imageList1.ImageStream" )!;
57 ················imageList1.Images.SetKeyName( 0, "" );
58 ················imageList1.Images.SetKeyName( 1, "" );
59 ················imageList1.Images.SetKeyName( 2, "" );
60 ················imageList1.Images.SetKeyName( 3, "" );
61 ················imageList1.Images.SetKeyName( 4, "" );
62 ················imageList1.Images.SetKeyName( 5, "" );
63 ················imageList1.Images.SetKeyName( 6, "" );
64 ················imageList1.Images.SetKeyName( 7, "" );
65 ················imageList1.Images.SetKeyName( 8, "" );
66 ················imageList1.Images.SetKeyName( 9, "" );
67 ················imageList1.Images.SetKeyName( 10, "" );
68 ················imageList1.Images.SetKeyName( 11, "" );
69 ················imageList1.Images.SetKeyName( 12, "" );
70 ················imageList1.Images.SetKeyName( 13, "" );
71 ················Icon = (Icon) resources.GetObject( "$this.Icon" )!;
72 ················ScanArgs( args );
73 ················Application.Idle += new EventHandler( OnIdle );
74 ············}
75 ············catch (Exception ex)
76 ············{
77 ················MessageBox.Show( ex.ToString(), "Mapping tool error" );
78 ············}
79 ········}
80 #pragma warning restore 8618
81
82 ········/// <summary>
83 ········/// Die verwendeten Ressourcen bereinigen.
84 ········/// </summary>
85 ········protected override void Dispose( bool disposing )
86 ········{
87 ············if (disposing)
88 ············{
89 ················if (components != null)
90 ················{
91 ····················components.Dispose();
92 ················}
93 ············}
94 ············base.Dispose( disposing );
95 ········}
96
97 ········#region Vom Windows Form-Designer generierter Code
98 ········/// <summary>
99 ········/// Erforderliche Methode für die Designerunterstützung.
100 ········/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
101 ········/// </summary>
102 ········private void InitializeComponent()
103 ········{
104 ············components = new Container();
 
105 ············allObjects = new TreeView();
106 ············imageList1 = new ImageList( components );
107 ············splitter1 = new Splitter();
 
108 ············mainMenu = new MenuStrip();
109 ············fileToolStripMenuItem = new ToolStripMenuItem();
110 ············menuOpen = new ToolStripMenuItem();
111 ············menuSave = new ToolStripMenuItem();
112 ············menuSaveAs = new ToolStripMenuItem();
113 ············panel1 = new Panel();
114 ············propertyGrid1 = new PropertyGrid();
115 ············mainMenu.SuspendLayout();
116 ············panel1.SuspendLayout();
117 ············SuspendLayout();
118 ············//
119 ············// allObjects
120 ············//
121 ············allObjects.Dock = DockStyle.Left;
122 ············allObjects.ImageIndex = 0;
123 ············allObjects.ImageList = imageList1;
124 ············allObjects.Location = new Point( 0, 24 );
125 ············allObjects.Name = "allObjects";
126 ············allObjects.SelectedImageIndex = 0;
127 ············allObjects.Size = new Size( 464, 408 );
128 ············allObjects.TabIndex = 0;
129 ············allObjects.AfterSelect +=··allObjects_AfterSelect ;
130 ············allObjects.MouseUp +=··allObjects_MouseUp ;
131 ············//
132 ············// imageList1
133 ············//
134 ············imageList1.ColorDepth = ColorDepth.Depth8Bit;
135 imageList1. ImageSize = new Size( 16, 16 ) ;
136 ············imageList1.TransparentColor = Color.Transparent;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137 ············//
138 ············// splitter1
139 ············//
140 ············splitter1.Location = new Point( 464, 24 );
141 ············splitter1.Name = "splitter1";
142 ············splitter1.Size = new Size( 3, 408 );
143 ············splitter1.TabIndex = 1;
144 ············splitter1.TabStop = false;
 
 
 
 
 
 
 
 
 
145 ············//
146 ············// mainMenu
147 ············//
148 ············mainMenu.Items.AddRange( new ToolStripItem[] { fileToolStripMenuItem } );
149 ············mainMenu.Location = new Point( 0, 0 );
150 ············mainMenu.Name = "mainMenu";
151 ············mainMenu.Size = new Size( 784, 24 );
152 ············mainMenu.TabIndex = 0;
153 ············mainMenu.Text = "mainMenu";
154 ············//
155 ············// fileToolStripMenuItem
156 ············//
157 ············fileToolStripMenuItem.DropDownItems.AddRange( new ToolStripItem[] { menuOpen, menuSave, menuSaveAs } );
158 ············fileToolStripMenuItem.Name = "fileToolStripMenuItem";
159 ············fileToolStripMenuItem.Size = new Size( 37, 20 );
160 ············fileToolStripMenuItem.Text = "&File";
161 ············//
162 ············// menuOpen
163 ············//
164 ············menuOpen.Name = "menuOpen";
165 menuOpen. Size = new Size( 121, 22 ) ;
166 ············menuOpen.Text = "&Open";
167 ············menuOpen.Click +=··menuOpen_Click ;
168 ············//
169 ············// menuSave
170 ············//
171 ············menuSave.Name = "menuSave";
172 menuSave. Size = new Size( 121, 22 ) ;
173 ············menuSave.Text = "&Save";
174 ············menuSave.Click +=··menuSave_Click ;
175 ············//
176 ············// menuSaveAs
177 ············//
178 ············menuSaveAs.Name = "menuSaveAs";
179 menuSaveAs. Size = new Size( 121, 22 ) ;
180 ············menuSaveAs.Text = "Save &as...";
181 ············menuSaveAs.Click +=··menuSaveAs_Click ;
182 ············//
183 ············// panel1
184 ············//
185 ············panel1.Controls.Add( propertyGrid1 );
186 ············panel1.Dock = DockStyle.Fill;
187 ············panel1.Location = new Point( 467, 24 );
188 ············panel1.Name = "panel1";
189 ············panel1.Padding = new Padding( 0, 0, 3, 3 );
190 ············panel1.Size = new Size( 317, 408 );
191 ············panel1.TabIndex = 2;
192 ············//
193 ············// propertyGrid1
194 ············//
195 ············propertyGrid1.Dock = DockStyle.Fill;
196 ············propertyGrid1.LineColor = SystemColors.ScrollBar;
197 ············propertyGrid1.Location = new Point( 0, 0 );
198 ············propertyGrid1.Name = "propertyGrid1";
199 ············propertyGrid1.Size = new Size( 314, 405 );
200 ············propertyGrid1.TabIndex = 3;
201 ············//
202 ············// MainForm
203 ············//
204 ············AutoScaleBaseSize = new Size( 6, 16 );
205 ············ClientSize = new Size( 784, 432 );
206 Controls. Add( panel1 ) ;
207 ············Controls.Add( splitter1 );
208 ············Controls.Add( allObjects );
209 ············Controls.Add( mainMenu );
 
210 ············MainMenuStrip = mainMenu;
211 ············Name = "MainForm";
212 ············Text = "NDO Mapping Tool";
213 ············Closing +=··MainForm_Closing ;
214 ············Load +=··MainForm_Load ;
215 ············mainMenu.ResumeLayout( false );
216 ············mainMenu.PerformLayout();
217 ············panel1.ResumeLayout( false );
218 ············ResumeLayout( false );
219 ············PerformLayout();
220 ········}
221 ········#endregion
222
223 ········/// <summary>
224 ········/// Der Haupteinstiegspunkt für die Anwendung.
225 ········/// </summary>
226 ········[STAThread]
227 ········static void Main( string[] args )
228 ········{
229 ············Application.Run( new MainForm( args ) );
230 ········}
231
232 ········private void LoadMapping( string fileName )
233 ········{
234 ············allObjects.Nodes.Clear();
235 ············try
236 ············{
237 ················mapping = new NDOMapping( fileName, null );
238 ················PrepareRelations();
239 ············}
240 ············catch (Exception ex)
241 ············{
242 ················mapping = null;
243 ················this.Text = string.Empty;
244 #if DEBUG
245 ················MessageBox.Show( ex.ToString(), "Error" );
246 #else
247 ················MessageBox.Show(ex.Message, "Error");
248 #endif
249 ················return;
250 ············}
251 ············this.Text = fileName;
252 ············if (mapping != null)
253 ················FillNodes();
254 ········}
255
256
257 ········private void FillNodes()
258 ········{
259 ············NDOMappingNode mn = new NDOMappingNode(this.mapping!);
260 ············allObjects.Nodes.Add( mn );
261 ········}
262
263 ········private void ScanArgs( string[] args )
264 ········{
265 ············Regex regexm = new Regex(@"-m:(.*)");
266 ············foreach (string arg in args)
267 ············{
268 ················Match matchm = regexm.Match(arg);
269 ················if (matchm.Success)
270 ················{
271 ····················LoadMapping( matchm.Groups[1].Value );
272 ····················saveOnClose = true;
273 ················}
274 ············}
275 ········}
276
277
278 ········private void MainForm_Load( object? sender, System.EventArgs e )
279 ········{
280 ········}
281
282 ········private void allObjects_AfterSelect( object? sender, TreeViewEventArgs e )
283 ········{
284 ············var tn = e.Node as NDOTreeNode;
285 ············if (tn != null)
286 ················this.propertyGrid1.SelectedObject = tn.Object;
287 ············else
288 ················this.propertyGrid1.SelectedObject = null;
289 ········}
290
291 ········private void MainForm_Closing( object? sender, System.ComponentModel.CancelEventArgs e )
292 ········{
293 ············if (saveOnClose && mapping != null)
294 ················mapping.Save();
295 ············else if (mapping != null && mapping.HasChanges)
296 ············{
297 ················if (MessageBox.Show( "Save changes?", "NDO Mapping Tool", MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.Yes)
298 ················{
299 ····················mapping.Save();
300 ················}
301 ············}
302 ········}
303
304 ········private void menuOpen_Click( object? sender, System.EventArgs e )
305 ········{
306 ············if (mapping != null && mapping.HasChanges)
307 ············{
308 ················if (MessageBox.Show( "Save changes?", "Mapping Tool", MessageBoxButtons.YesNo ) == DialogResult.Yes)
309 ················{
310 ····················mapping.Save();
311 ····················mapping = null;
312 ················}
313 ············}
314
315 ············OpenFileDialog ofd = new OpenFileDialog();
316 ············ofd.CheckFileExists = true;
317 ············ofd.DefaultExt = "xml";
318 ············ofd.Multiselect = false;
319 ············ofd.Filter = "Mapping Files (*.xml)|*.xml";
320 ············ofd.FileName = "NDOMapping.xml";
321 ············if (ofd.ShowDialog() == DialogResult.Cancel)
322 ················return;
323 ············LoadMapping( ofd.FileName );
324 ········}
325
326
327 ········bool PrepareRelations()
328 ········{
329 ············bool result = false;
330 ············if (mapping != null)
331 ············{
332 ················foreach (Class cl in mapping.Classes)
333 ················{
334 ····················foreach (Relation r in cl.Relations)
335 ····················{
336 ························// This computes the foreign relation, which is
337 ························// needed to avoid a null pointer exception
338 ························// while binding to the property grid.
339 ························result = result || r.Bidirectional;
340 ····················}
341 ················}
342 ············}
343
344 ············return result;··// Nobody reads this value, but we make shure, that the code won't get removed by the optimizer.
345 ········}
346
347
348 ········private void menuSave_Click( object? sender, System.EventArgs e )
349 ········{
350 ············if (mapping != null)
351 ················mapping.Save();
352 ········}
353
354 ········private void menuSaveAs_Click( object? sender, System.EventArgs e )
355 ········{
356 ············if (mapping != null)
357 ············{
358 ················SaveFileDialog sfd = new SaveFileDialog();
359 ················if (mapping.FileName != string.Empty)
360 ····················sfd.InitialDirectory = Path.GetDirectoryName( mapping.FileName );
361 ················sfd.CheckFileExists = false;
362 ················sfd.DefaultExt = "xml";
363 ················sfd.Filter = "Mapping Files (*.xml)|*.xml";
364 ················sfd.FileName = "NDOMapping.xml";
365 ················if (sfd.ShowDialog( this ) != DialogResult.OK)
366 ····················return;
367 ················mapping.SaveAs( sfd.FileName );
368 ················this.Text = sfd.FileName;
369 ············}
370 ········}
371
372 ········private void OnIdle( object? sender, EventArgs e )
373 ········{
374 ············menuSave.Enabled = mapping != null && mapping.HasChanges;
375 ············menuOpen.Enabled = !saveOnClose;
376 ········}
377
378 #if DEBUG
379 ········private void MainForm_KeyPress( object? sender, KeyPressEventArgs e )
380 ········{
381
382 ············if ((int) e.KeyChar == 27)
383 ················MessageBox.Show( "Escape" );
384 ········}
385 #endif
386
387 ········private void allObjects_MouseUp( object? sender, MouseEventArgs e )
388 ········{
389
390 ············if (e.Button == MouseButtons.Right)
391 ············{
392 ················var tn = this.allObjects.GetNodeAt(e.X, e.Y) as NDOTreeNode;
393 ················if (tn != null)
394 ················{
395 ····················allObjects.SelectedNode = tn;
396 ····················var menu = tn.GetContextMenu();
397 ····················if (menu.Items.Count > 0)
398 ························menu.Show(allObjects, new Point(e.X, e.Y));
399 ····················this.propertyGrid1.SelectedObject = tn.Object;
400 ················}
401 ············}
402 ········}
403 ····}
404 }
405