* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / EditCommandColumn.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Authors:
23 //      Peter Bartok    (pbartok@novell.com)
24 //
25 //
26
27 using System.ComponentModel;
28 using System.Security.Permissions;
29
30 namespace System.Web.UI.WebControls {
31
32         // CAS
33         [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
34         [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
35         public class EditCommandColumn : DataGridColumn {
36                 #region Public Constructors
37                 public EditCommandColumn() {
38                 }
39                 #endregion      // Public Constructors
40
41                 #region Public Instance Properties
42                 public virtual ButtonColumnType ButtonType {
43                         get {
44                                 object obj;
45
46                                 obj = ViewState["ButtonType"];
47                                 if (obj != null) {
48                                         return (ButtonColumnType)obj;
49                                 }
50                                 return ButtonColumnType.LinkButton;
51                         }
52
53                         set {
54                                 ViewState["ButtonType"] = value;
55                         }
56                 }
57
58 #if NET_2_0
59                 [DefaultValue ("")]
60                 [Localizable (true)]
61 #endif
62                 public virtual string CancelText {
63                         get {
64                                 return ViewState.GetString("CancelText", string.Empty);
65                         }
66
67                         set {
68                                 ViewState["CancelText"] = value;
69                         }
70                 }
71
72 #if NET_2_0
73                 [DefaultValue ("")]
74                 [Localizable (true)]
75 #endif
76                 public virtual string EditText {
77                         get {
78                                 return ViewState.GetString("EditText", string.Empty);
79                         }
80
81                         set {
82                                 ViewState["EditText"] = value;
83                         }
84                 }
85
86 #if NET_2_0
87                 [DefaultValue ("")]
88                 [Localizable (true)]
89 #endif
90                 public virtual string UpdateText {
91                         get {
92                                 return ViewState.GetString("UpdateText", string.Empty);
93                         }
94
95                         set {
96                                 ViewState["UpdateText"] = value;
97                         }
98                 }
99                 #endregion      // Public Instance Properties
100
101                 #region Public Instance Methods
102
103                 // Modeled after Ben's CommandField.InitializeCell. Saved me a lot of figuring-out time :-)
104                 public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) {
105                         base.InitializeCell (cell, columnIndex, itemType);
106
107                         switch(itemType) {
108                                 case ListItemType.Separator: 
109                                 case ListItemType.Pager:
110                                 case ListItemType.Footer:
111                                 case ListItemType.Header: {
112                                         // Base handles header and footer, dunno about the others
113                                         return;
114                                 }
115
116                                 case ListItemType.Item:
117                                 case ListItemType.SelectedItem:
118                                 case ListItemType.AlternatingItem:{
119                                         cell.Controls.Add(CreateButton(ButtonType, EditText, "Edit", false));
120                                         break;
121                                 }
122
123                                 case ListItemType.EditItem: {
124                                         cell.Controls.Add(CreateButton(ButtonType, UpdateText, "Update", true));
125                                         cell.Controls.Add(new LiteralControl(" "));
126                                         cell.Controls.Add(CreateButton(ButtonType, CancelText, "Cancel", false));
127                                         break;
128                                 }
129                         }
130                 }
131                 #endregion      // Public Instance Methods
132
133                 #region Private Methods
134                 private Control CreateButton(ButtonColumnType type, string text, string command, bool valid) {
135                         Button b;
136                         LinkButton d;
137
138                         if (type == ButtonColumnType.LinkButton) {
139                                 d = new ForeColorLinkButton();
140                                 d.Text = text;
141                                 d.CommandName = command;
142                                 d.CausesValidation = valid;
143                                 return d;
144                         }
145
146                         b = new Button();
147                         b.Text = text;
148                         b.CommandName = command;
149                         b.CausesValidation = valid;
150                         return b;
151                 }
152                 #endregion      // Private Methods
153         }
154 }