2004-05-22 Francisco Figueiredo Jr. <fxjrlists@yahoo.com.br>
[mono.git] / mcs / class / Npgsql / Npgsql / Design / ConnectionStringEditor.cs
1 using System;
2 using System.Drawing.Design;
3 using System.ComponentModel;
4 using System.Windows.Forms;
5 using System.Windows.Forms.Design;
6
7 namespace Npgsql.Design
8 {
9         /// <summary>
10         /// An UITypeEditor that simply initializes a
11         /// ConnectionStringEditorForm if possible
12         /// </summary>
13         internal class ConnectionStringEditor : UITypeEditor
14         {
15                 /// <summary>
16                 /// Edits the Value of the given Object using the EditSyle given by GetEditStyle.
17                 /// </summary>
18                 /// <param name="context">An ITypeDescriptorContext, through wich you can get additional context information.</param>
19                 /// <param name="provider">An IServiceProvider, through which this editor may order services.</param>
20                 /// <param name="value">The Object to edit</param>
21                 /// <returns>The new value of the Object</returns>
22                 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
23                 {
24                         if (context != null && context.Instance != null && provider != null) {
25                                 IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
26
27                                 if (edSvc != null) {
28                                         ConnectionStringEditorForm eform;
29
30                                         if(value != null && value.ToString() != String.Empty) {
31                                                 eform = new ConnectionStringEditorForm(value.ToString());
32                                         } else {
33                                                 eform = new ConnectionStringEditorForm();
34                                         }
35
36                                         if(edSvc.ShowDialog(eform) == DialogResult.OK) {
37                                                 return eform.ConnectionString;
38                                         } else {
39                                                 return value;
40                                         }
41                                 } else {
42                                         return value;
43                                 }
44                         }
45
46                         return value;
47                 }
48
49                 /// <summary>
50                 /// Requests the EditSyle to be used by EditValue
51                 /// </summary>
52                 /// <param name="context">An ITypeDescriptorContext, through wich you can get additional context information.</param>
53                 /// <returns>An UITypeEditorEditStyle-Value, indicating the EditStyle used by EditValue. If UITypeEditor doesn't support this method, GetEditStyle returns the value None.</returns>
54                 public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
55                 {
56                         if (context != null && context.Instance != null) {
57                                 return UITypeEditorEditStyle.Modal;
58                         }
59
60                         return base.GetEditStyle (context);
61                 }
62         }
63 }
64