context: /*************************************************************************
   *
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
   * 
   * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
   * 
   * Use is subject to license terms.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
   * use this file except in compliance with the License. You may obtain a copy
   * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
   * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * 
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   ************************************************************************/
  
  using System;
  using AODL.Document;
  using AODL.Document.Forms;
  using System.Xml;
  using AODL.Document.Content;
  
  namespace AODL.Document.Forms.Controls
  {
  	public class ODFListBox: ODFFormControl
  	{
  		private ODFOptionCollection _options;
  
  		/// <summary>
  		/// The collection of the ODFOptions (each option stand for a list box element)
  		/// </summary>
  		public ODFOptionCollection Options
  		{
  			get
  			{
  				return _options;
  			}
  			set
  			{
  				_options = value;
  			}
  		}
  
  		public override string Type
  		{
  			get
  			{
  				return "listbox";
  			}
  		}
  
  		/// <summary>
  		/// Specifies whether or not a control can accept user input
  		/// </summary>
  		public XmlBoolean Disabled
  		{
  			get
  			{
  				XmlNode xn = this._node.SelectSingleNode("@form:disabled",
  				                                         this._document.NamespaceManager);
  				if (xn == null) return XmlBoolean.NotSet;
  
  				string s = xn.InnerText;
  				XmlBoolean at;
  				switch (s)
  				{
  						case "true": at = XmlBoolean.True; break;
  						case "false": at = XmlBoolean.False; break;
  						default: at = XmlBoolean.NotSet; break;
  				}
  				return at;
  			}
  			set
  			{
  				string s;
  				switch (value)
  				{
  						case XmlBoolean.True: s = "true"; break;
  						case XmlBoolean.False: s = "false"; break;
  						default: return;
  				}
  				XmlNode nd = this._node.SelectSingleNode("@form:disabled",
  				                                         this._document.NamespaceManager);
  				if (nd == null)
  					nd = this.Node.Attributes.Append(this._document.CreateAttribute("disabled", "form"));
  				nd.InnerText = s;
  			}
  		}
  
  		/// <summary>
  		/// Contains additional information about a control.
  		/// </summary>
  		public string Title
  		{
  			get
  			{
  				XmlNode xn = this._node.SelectSingleNode("@form:title",
  				                                         this._document.NamespaceManager);
  				if (xn == null) return null;
  				return xn.InnerText;
  			}
  			set
  			{
  				XmlNode nd = this._node.SelectSingleNode("@form:title",
  				                                         this._document.NamespaceManager);
  				if (nd == null)
  					nd = this.Node.Attributes.Append(this._document.CreateAttribute("title", "form"));
  				nd.InnerText = value;
  			}
  		}
  
  		/// <summary>
  		/// Specifies the source used to populate the list in a list box or
  		/// combo box. The first column of the list source result set populates the list.
  		/// </summary>
  		public string ListSource
  		{
  			get
  			{
  				XmlNode xn = this._node.SelectSingleNode("@form:list-source",
  				                                         this._document.NamespaceManager);
  				if (xn == null) return null;
  				return xn.InnerText;
  			}
  			set
  			{
  				XmlNode nd = this._node.SelectSingleNode("@form:list-source",
  				                                         this._document.NamespaceManager);
  				if (nd == null)
  					nd = this.Node.Attributes.Append(this._document.CreateAttribute("list-source", "form"));
  				nd.InnerText = value;
  			}
  		}
  		
  		/// <summary>
  		/// Specifies the column values of the list source result set that
  		/// are used to fill the data field values
  		/// </summary>
  		public string BoundColumn
  		{
  			get
  			{
  				XmlNode xn = this._node.SelectSingleNode("@form:bound-column",
  				                                         this._document.NamespaceManager);
  				if (xn == null) return null;
  				return xn.InnerText;
  			}
  			set
  			{
  				XmlNode nd = this._node.SelectSingleNode("@form:bound-column",
  				                                         this._document.NamespaceManager);
  				if (nd == null)
  					nd = this.Node.Attributes.Append(this._document.CreateAttribute("bound-column", "form"));
  				nd.InnerText = value;
  			}
  		}
  
  		/// <summary>
  		/// Specifies the name of a result set column. The result set is
  		/// determined by the form which the control belongs to
  		/// </summary>
  		public string DataField
  		{
  			get
  			{
  				XmlNode xn = this._node.SelectSingleNode("@form:data-field",
  				                                         this._document.NamespaceManager);
  				if (xn == null) return null;
  				return xn.InnerText;
  			}
  			set
  			{
  				XmlNode nd = this._node.SelectSingleNode("@form:data-field",
  				                                         this._document.NamespaceManager);
  				if (nd == null)
  					nd = this.Node.Attributes.Append(this._document.CreateAttribute("title", "form"));
  				nd.InnerText = value;
  			}
  		}
  
  		/// <summary>
  		/// Specifies the type of data source that is used to
  		/// populate the list data in a list box or combo box
  		/// </summary>
  		public ListSourceType ListSourceType
  		{
  			get
  			{
  				XmlNode xn = this._node.SelectSingleNode("@form:list-source-type",
  				                                         this._document.NamespaceManager);
  				if (xn == null) return ListSourceType.NotSet;
  
  				string s = xn.InnerText;
  				ListSourceType at;
  				switch (s)
  				{
  						case "table": at = ListSourceType.Table; break;
  						case "query": at = ListSourceType.Query; break;
  						case "sql": at = ListSourceType.Sql; break;
  						case "sql-pass-through": at = ListSourceType.SqlPassThrough; break;
  						case "value-list": at = ListSourceType.ValueList; break;
  						case "table-fields": at = ListSourceType.TableFields; break;
  						default: at = ListSourceType.NotSet; break;
  				}
  				return at;
  			}
  			set
  			{
  				string s;
  				switch (value)
  				{
  						case ListSourceType.Table: s = "table"; break;
  						case ListSourceType.Query: s = "query"; break;
  						case ListSourceType.Sql: s = "sql"; break;
  						case ListSourceType.SqlPassThrough: s = "sql-pass-through"; break;
  
gt: 						case ListSourceType.ValueList: s = "value-list"; break;