/// <summary>
        /// Displays the dialog as a child of the specified parent window.
        /// </summary>
        /// <param name="parentWindow">
        /// The owner of the modal dialog.
        /// </param>
        /// <param name="domain">
        /// The domain object whose information is to be displayed in the dialog.
        /// </param>
        /// <returns>
        /// <c>true</c> if the end-user clicked the OK button to knock the dialog
        /// down. <c>false</c> if the end-user clicked the Cancel button.
        /// </returns>
        public virtual bool DoModal(Window parentWindow, Domain domain)
        {
            bool ok = false;

            // Construct a data context and register it...
            DataContext context = CreateDataContext();

            ScanControls();

            if (domain != null)
            {
                context.AddObject(domain);
            }

            TransientFor = parentWindow;

            int response = Run();
            if (response == (int) Gtk.ResponseType.Ok)
            {
                ok = true;
            }
            else if (response == (int) Gtk.ResponseType.Cancel)
            {
                if (domain != null)
                {
                    domain.Revert();
                }
                ok = false;
            }

            Destroy();

            return ok;
        }
        /// <summary>
        /// Display the dialog modally.
        /// </summary>
        /// <param name="parentWindow">
        /// The parent window to the dialog
        /// </param>
        /// <param name="domain">
        /// The DynamicProperty domain object to evaluate.
        /// </param>
        /// <returns>
        /// <c>true</c> if the user clicked OK.
        /// </returns>
        public virtual bool DoModal(Window parentWindow, Domain domain)
        {
            bool ok = false;

            dynProp = (DynamicProperty) domain;

            TransientFor = parentWindow;

            // DomainToControls(domain);
            tvDynPropCtl.Render(DomainRenderer.Render(domain, "Summary"));

            calSimEffectiveDate.Date = DateTime.Now;
            //            DateTime dtNow = DateTime.Now;
            //            calSimEffectiveDate.Date = dtNow;
            //            txtSimTime.Text = dtNow.ToString("HH:mm");

            int response = Run();
            if (response == Gtk.ResponseType.Ok.value__)
            {
                ok = true;
                // ControlsToDomain(domain);
            }

            Destroy();

            return ok;
        }
        public void SetUp()
        {
            cut = new Domain(null);

            // Set up one of each type of attribute.
            new LongAttribute(cut, "Id", true);
            new StringAttribute(cut, "Str", false);
        }
        public override string Build(Domain domain)
        {
            StringBuilder sb = new StringBuilder("INSERT INTO ");
            sb.Append(TableName);
            sb.Append(" (");
            int fieldCount = 0;

            // Loop thru all the attributes on the domain for the names
            // of the fields to insert.
            foreach (DomainCore.Attribute attr in domain.Attributes.Values)
            {
                if (attr.Dirty)
                {
                    if (fieldCount > 0)
                    {
                        sb.Append(",\n  ");
                    }
                    else
                    {
                        sb.Append("\n  ");
                    }
                    sb.Append(this[attr.Name]);
                    fieldCount++;
                }
            }

            if (fieldCount == 0)
            {
                throw new Exception("Nothing to insert on the domain! Really?");
            }

            sb.Append("\n) VALUES (");

            fieldCount = 0;
            // Loop thru all the attributes on the domain for the values
            // of the fields to insert.
            foreach (DomainCore.Attribute attr in domain.Attributes.Values)
            {
                if (attr.Dirty)
                {
                    if (fieldCount > 0)
                    {
                        sb.Append(",\n  ");
                    }
                    else
                    {
                        sb.Append("\n  ");
                    }
                    sb.Append(DAOUtils.ConvertValue(attr.Value));
                    fieldCount++;
                }
            }

            sb.Append("\n)");

            return sb.ToString();
        }
 /// <summary>
 /// Constructs a new BaseAttribute object.
 /// </summary>
 /// <param name="domain">
 /// A reference to the domain object that owns this attribute.
 /// </param>
 /// <param name="name">
 /// The name of the attribute.
 /// </param>
 /// <param name="id">
 /// If <c>true</c>, indicates that this attribute is the ID attribute of the
 /// domain object.
 /// </param>
 public BaseAttribute(Domain domain, string name, bool id)
 {
     this.name = name;
     this.id = id;
     if (domain != null)
     {
         domain.AddAttribute(this);
     }
 }
        public void SetUp()
        {
            DomainFactorySetup();

            Dictionary<string,string> mappings = new Dictionary<string, string>();
            mappings["Id"] = "DOMAIN_ID";
            mappings["StringAttr"] = "STRING_COLUMN";

            cut = new DeleteBuilder("DOMAIN_TABLE", mappings);

            domain = DomainFactory.Create("DeleteDomain", false);
        }
        public void SetUp()
        {
            DomainFactorySetup();

            Dictionary<string,string> mappings = new Dictionary<string, string>();
            mappings["Id"] = "DOMAIN_ID";
            mappings["StringAttr"] = "STRING_COLUMN";
            mappings["LongAttr"] = "LONG_COLUMN";

            cut = new UpdateBuilder("UPDATE_TABLE", mappings);

            domain = DomainFactory.Create("UpdateDomain", true);
        }
        /// <summary>
        /// Constructs a new Collection relationship.
        /// </summary>
        /// <param name="domain">
        /// The domain object that owns the relationship (parent).
        /// </param>
        /// <param name="name">
        /// The name of the relationship.
        /// </param>
        /// <param name="domainName">
        /// The name of the domain objects stored in the relationship
        /// </param>
        /// <param name="parentIdAttribute">
        /// The name of the attribute on the child objects that hold the
        /// unique identifier of the parent.
        /// </param>
        public CollectionRelationship(Domain domain, 
                                      string name, 
                                      string domainName, 
                                      string parentIdAttribute)
        {
            this.name = name;
            this.domainName = domainName;
            this.parentIdAttribute = parentIdAttribute;

            domains = new List<Domain>();

            if (domain != null)
            {
                domain.AddRelationship(this);
            }
        }
        public override string Build(Domain domain)
        {
            StringBuilder sb = new StringBuilder("UPDATE ");
            sb.Append(TableName);
            sb.Append(" SET");
            int fieldCount = 0;

            // Loop thru all the attributes on the domain for the names
            // of the fields to insert.
            foreach (DomainCore.Attribute attr in domain.Attributes.Values)
            {
                if (! attr.Id && attr.Dirty)
                {
                    if (fieldCount > 0)
                    {
                        sb.Append(",\n  ");
                    }
                    else
                    {
                        sb.Append("\n  ");
                    }
                    sb.Append(String.Format("{0} = {1}",
                                            this[attr.Name],
                                            DAOUtils.ConvertValue(attr.Value)));
                    fieldCount++;
                }
            }

            if (fieldCount == 0)
            {
                throw new Exception("Nothing to update on the domain! Really?");
            }

            sb.Append("\nWHERE\n");

            DomainCore.Attribute idAttribute = domain.IdAttribute;
            sb.Append(String.Format("  {0} = {1}",
                                    this[idAttribute.Name],
                                    DAOUtils.ConvertValue(idAttribute.Value)));

            return sb.ToString();
        }
        /// <summary>
        /// Displays the dialog as modal and populates the text view
        /// with the SQL generated by the domain object.
        /// </summary>
        /// <param name="parentWindow">
        /// The parent of the window.
        /// </param>
        /// <param name="domain">
        /// The domain object to display the SQL for.
        /// </param>
        /// <returns>
        /// <c>true</c> if the OK button was pressed.
        /// </returns>
        public bool DoModal(Window parentWindow, Domain domain)
        {
            bool ok = false;

            TransientFor = parentWindow;

            string sql = domain.SaveSQL();

            textview.TagText("Monospaced", sql);

            int response = Run();
            if (response == Gtk.ResponseType.Ok.value__)
            {
                ok = true;
            }

            Destroy();

            return ok;
        }
 /// <summary>
 /// Adds a new domain object to the data context.
 /// </summary>
 /// <remarks>
 /// The name with which the domain object is registered is the Class
 /// name of the domain object (not fully qualified).
 /// </remarks>
 /// <param name="obj">
 /// Reference to the domain object to be registered in the context.
 /// </param>
 public void AddObject(Domain obj)
 {
     AddObject(obj.GetType().Name, obj);
 }
 public override string Build(Domain domain)
 {
     DomainCore.Attribute idAttr = domain.IdAttribute;
     return String.Format(SQL_TEMPLATE, TableName, this[idAttr.Name], DAOUtils.ConvertValue(idAttr.Value));
 }
        public void AddDomain(Domain domain)
        {
            // Get the iter for the owner of this new domain object.
            long applicationId = (long) domain.GetValue("ApplicationId");
            long propertyId = (long) domain.GetValue("PropertyId");

            DomainDAO dao = DomainFactory.GetDAO("PropertyDefinition");
            Domain propDef = dao.GetObject(propertyId);

            string category = (string) propDef.GetValue("Category");

            domain.SetValue("Category", category);
            domain.SetValue("PropertyName", propDef.GetValue("Name"));

            TreeIter appIter = FindApplicationIter(applicationId);
            if (! appIter.Equals(TreeIter.Zero))
            {
                // Found the application, now find the category to
                // hook up to...
                TreeIter catIter = FindCategoryIter(appIter, category);
                TreeIter propIter = TreeIter.Zero;
                if (! catIter.Equals(TreeIter.Zero))
                {
                    propIter = treeStore.AppendValues(catIter,
                                           RenderLabel(domain),
                                           domain.IdAttribute.Value,
                                           domain.GetType().Name);
                }
                else
                {
                    // The category isn't there; need to create one.
                    catIter = treeStore.AppendValues(appIter,
                                                     Render(domain, "CategoryLabel"),
                                                     domain.IdAttribute.Value,
                                                     domain.GetType().Name);

                    propIter = treeStore.AppendValues(catIter,
                                           RenderLabel(domain),
                                           domain.IdAttribute.Value,
                                           domain.GetType().Name);
                }

                // Now highlight the specified row
                SelectRow(propIter);
            }
            else
            {
                log.ErrorFormat("Unable to find application Id ({0}) to add domain", applicationId);
            }
        }
        /// <summary>
        /// Adds a new domain object to the TreeView.
        /// </summary>
        /// <param name="domain">
        /// The domain object to add.
        /// </param>
        public void AddDomain(Domain domain)
        {
            object category = domain.GetValue("Category");

            // Find the correct category to add the new domain into
            TreeIter iter = TreeIter.Zero;
            bool more = treeStore.GetIterFirst(out iter);
            while (more)
            {
                string label = (string) treeStore.GetValue(iter, LABEL_CELL);
                if (label.Equals(category))
                {
                    // Found the right category
                    TreeIter propIter = TreeIter.Zero;
                    propIter = treeStore.AppendValues(iter,
                                                      RenderLabel(domain),
                                                      domain.IdAttribute.Value,
                                                      domain.GetType().Name);
                    SelectRow(propIter);
                    break;
                }
                more = treeStore.IterNext(ref iter);
            }

            if (! more)
            {
                // This means that we didn't find the category; add
                // a category and property
                TreeIter catIter = treeStore.AppendValues(Render(domain, "CategoryLabel"),
                                                          domain.IdAttribute.Value,
                                                          domain.GetType().Name);
                TreeIter propIter = treeStore.AppendValues(catIter,
                                                           RenderLabel(domain),
                                                           domain.IdAttribute.Value,
                                                           domain.GetType().Name);
                SelectRow(propIter);
            }
        }
 public string DeleteSQL(Domain obj)
 {
     return deleteBuilder.Build(obj);
 }
 /// <summary>
 /// A delegate which indicates which of the domain objects in
 /// a collection should be removed.
 /// </summary>
 /// <param name="domain">
 /// The domain object to test for removal.
 /// </param>
 /// <returns>
 /// If <c>true</c>, the domain object should be removed from the
 /// collection.
 /// </returns>
 private bool RemoveNewObject(Domain domain)
 {
     return domain.NewObject;
 }
 /// <summary>
 /// Constructs a new StringAttribute object.
 /// </summary>
 /// <param name="domain">
 /// Reference to the domain object that owns this attribute.
 /// </param>
 /// <param name="name">
 /// The name of the attribute.
 /// </param>
 /// <param name="id">
 /// <c>true</c> if this attribute represents the unique identifier for the
 /// domain object.
 /// </param>
 public StringAttribute(Domain domain, string name, bool id)
     : base(domain, name, id)
 {
 }
 public string UpdateSQL(Domain obj)
 {
     return updateBuilder.Build(obj);
 }
 public void TearDown()
 {
     cut = null;
 }
        public void Update(Domain obj)
        {
            IDbCommand cmd = Connection.CreateCommand();
            cmd.CommandText = UpdateSQL(obj);

            int numRows = cmd.ExecuteNonQuery();
            if (numRows <= 0)
            {
                throw new Exception("Should have updated at least one row");
            }

            CloseConnection();
        }
 public string InsertSQL(Domain obj)
 {
     return insertBuilder.Build(obj);
 }
        public void Insert(Domain obj)
        {
            IDbCommand cmd = Connection.CreateCommand();
            cmd.CommandText = InsertSQL(obj);

            int numRows = cmd.ExecuteNonQuery();
            if (numRows <= 0)
            {
                throw new Exception("Should have inserted at least one row");
            }

            if (PopulateId)
            {
                // Now, get the ID of the newly inserted record
                cmd.CommandText = "SELECT last_insert_id()";
                object oid = cmd.ExecuteScalar();
                long id = Convert.ToInt64(oid);
                obj.IdAttribute.Value = id;
            }

            obj.Clean();
            obj.NewObject = false;

            CloseConnection();
        }
 /// <summary>
 /// Renders information associated with the specified domain object.
 /// </summary>
 /// <remarks>
 /// Uses the <c>renderType</c> parameter to determine what type of information
 /// is to be rendered for the domain. In general, the <c>renderType</c> parameter
 /// is the name of a template in the StringTemplate macro file.
 /// </remarks>
 /// <param name="domain">
 /// The domain object to be rendered.
 /// </param>
 /// <param name="renderType">
 /// The rendering type to be applied to the domain object.
 /// </param>
 /// <returns>
 /// The string rendering of the domain object. The content of the string is dictated
 /// by the <c>renderType</c> parameter and the values within the domain object itself.
 /// </returns>
 public string Render(Domain domain, string renderType)
 {
     return DomainRenderer.Render(domain, renderType);
 }
        /// <summary>
        /// Adds a ValueCriteria domain object to the TreeView.
        /// </summary>
        /// <param name="valueCriteria">
        /// The ValueCriteria domain object to add.
        /// </param>
        public void AddValueCriteria(Domain valueCriteria)
        {
            // Get the iterator of the select item (effective date)
            TreeModel model = null;
            TreeIter edIter = TreeIter.Zero;

            if (GetSelected(out model, out edIter))
            {
                TreeIter vcIter = treeStore.AppendValues(edIter,
                                                         RenderLabel(valueCriteria),
                                                         valueCriteria.IdAttribute.Value,
                                                         valueCriteria.GetType().Name);

                SelectRow(vcIter);
            }
        }
 /// <summary>
 /// Renders the label to be used for the specified domain object.
 /// </summary>
 /// <param name="domain">
 /// The domain object from which the label information is to be determined.
 /// </param>
 /// <returns>
 /// The label to be used for this domain object.
 /// </returns>
 public string RenderLabel(Domain domain)
 {
     return Render(domain, "Label");
 }
        /// <summary>
        /// Adds a new effective date domain object to the TreeView.
        /// </summary>
        /// <param name="effectiveDate">
        /// The EffectiveValue domain object to add to the TreeView.
        /// </param>
        public void AddEffectiveDate(Domain effectiveDate)
        {
            // Get the iterator for the top of the tree...
            TreeIter topIter = TreeIter.Zero;

            if (treeStore.GetIterFirst(out topIter))
            {
                TreeIter edIter = treeStore.AppendValues(topIter,
                                                         RenderLabel(effectiveDate),
                                                         effectiveDate.IdAttribute.Value,
                                                         effectiveDate.GetType().Name);

                SelectRow(edIter);
            }
        }
 /// <summary>
 /// Removes the specified domain object from the collection.
 /// </summary>
 /// <param name="domain">
 /// The domain object to remove from the collection.
 /// </param>
 public void RemoveObject(Domain domain)
 {
     if (domains.IndexOf(domain) >= 0)
     {
         if (domain.NewObject)
         {
             domains.Remove(domain);
         }
         else
         {
             domain.ForDelete = true;
         }
     }
 }
        /// <summary>
        /// Populates the tree with the contents of the specified DynamicProperty.
        /// </summary>
        /// <param name="dynamicProperty">
        /// The DynamicProperty from which to populate the TreeView.
        /// </param>
        public void Populate(Domain dynamicProperty)
        {
            treeStore.Clear();

            TreeIter topIter = treeStore.AppendValues("Effective Values", -1L, "Nothing");

            List<Domain> effectiveValues = dynamicProperty.GetCollection("EffectiveValues");
            foreach (Domain effectiveValue in effectiveValues)
            {
                TreeIter evIter = TreeIter.Zero;
                evIter = treeStore.AppendValues(topIter,
                                                RenderLabel(effectiveValue),
                                                effectiveValue.IdAttribute.Value,
                                                effectiveValue.GetType().Name);

                List<Domain> valueCriterias = effectiveValue.GetCollection("ValueCriteria");
                foreach (Domain vc in valueCriterias)
                {
                    treeStore.AppendValues(evIter,
                                           RenderLabel(vc),
                                           vc.IdAttribute.Value,
                                           vc.GetType().Name);
                }
            }
        }
 /// <summary>
 /// Constructs a new DateTime attribute.
 /// </summary>
 /// <param name="domain">
 /// Reference to the domain object that owns this attribute.
 /// </param>
 /// <param name="name">
 /// The name of the attribute.
 /// </param>
 public DateTimeAttribute(Domain domain, string name)
     : base(domain, name, false)
 {
 }
 /// <summary>
 /// Adds an object to the relationship.
 /// </summary>
 /// <param name="domain">
 /// The domain object to add to the relationship
 /// </param>
 public void AddObject(Domain domain)
 {
     domains.Add(domain);
 }