Exemplo n.º 1
0
        public void DBObjectInstantiation()
        {
            CheckDisposed();

            // Putting persons in the UsageTypes doesn't really make sense, but for testing purposes
            // it doesn't matter what we store there as long as it is derived from CmPossibility
            CmPerson      person = new CmPerson();
            CmPossibility pos    = new CmPossibility();

            Cache.LangProject.LexDbOA.UsageTypesOA.PossibilitiesOS.Append(person);
            Cache.LangProject.LexDbOA.UsageTypesOA.PossibilitiesOS.Append(pos);

            int khvoAPossibiltyObject = pos.Hvo;
            int khvoAPersonObject     = person.Hvo;

            Assert.AreEqual("CmPerson", CmPossibility.CreateFromDBObject(Cache, khvoAPersonObject).GetType().Name);
            Assert.AreEqual("CmPossibility", CmPossibility.CreateFromDBObject(Cache, khvoAPossibiltyObject).GetType().Name);

            // Now try it not assuming anything about the class type (use the method on CmObject)
            // CmObject uses a different, less efficient method.
            Assert.AreEqual("CmPerson", CmObject.CreateFromDBObject(Cache, khvoAPersonObject).GetType().Name);

            // trying to turn a possibility into a person should throw an exception
            CmPerson.CreateFromDBObject(Cache, khvoAPossibiltyObject);
        }
Exemplo n.º 2
0
        /// <summary>
        /// add any subitems to the tree. Note! This assumes that the list has been preloaded
        /// (e.g., using PreLoadList), so it bypasses normal load operations for speed purposes.
        /// Withoug preloading, it took almost 19,000 queries to start FW showing semantic domain
        /// list. With preloading it reduced the number to 200 queries.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="parentsCollection"></param>
        protected override void AddSubNodes(ICmObject obj, TreeNodeCollection parentsCollection)
        {
            ICmPossibility pss = obj as ICmPossibility;

            foreach (int hvoSub in pss.SubPossibilities())
            {
                // Assume its basic information has already been loaded using PreLoadList.
                CmPossibility sub = CmPossibility.CreateFromDBObject(obj.Cache, hvoSub, false) as CmPossibility;
                AddTreeNode(sub, parentsCollection);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a List of ColumnMenuItems for ComboBox based on an array of column hvos.
        /// </summary>
        /// <param name="hvoArray"></param>
        internal void CollectColumnsToCombo(int[] hvoArray)
        {
            int ccols = hvoArray.Length;

            ColumnMenuItem[] cols = new ColumnMenuItem[ccols];
            for (int i = 0; i < ccols; i++)
            {
                cols[i] = new ColumnMenuItem(CmPossibility.CreateFromDBObject(Cache,
                                                                              hvoArray[i]));
            }
            SentElem.ComboCols = cols;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks for and reports any disallowed discourse template moves.
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="movingColumn">The proposed possibility item (template column) to move.</param>
        /// <param name="hvoTemplate">The hvo of the affected Chart Template (only 'default' exists so far).</param>
        /// <param name="hvoTemplateList">The hvo of the Template List.</param>
        /// <param name="hvoDest">The hvo of the destination item.</param>
        /// <returns>true means we found and reported a bad move.</returns>
        private bool CheckAndReportBadDiscourseTemplateMove(FdoCache cache, CmPossibility movingColumn, int hvoTemplate,
                                                            int hvoTemplateList, int hvoDest)
        {
            // First, check whether we're allowed to manipulate this column at all. This is the same check as
            // whether we're allowed to delete it.
            if (movingColumn.CheckAndReportProtectedChartColumn())
            {
                return(true);
            }
            // Other things being equal, we now need to make sure we aren't messing up the chart levels
            // Unless something is badly wrong, the destination is either the root template,
            // a column group one level down from the root template, a column two levels down,
            // or the base list.
            if (hvoDest == hvoTemplateList)
            {
                MessageBox.Show(m_tree, xWorksStrings.ksCantPromoteGroupToTemplate,
                                xWorksStrings.ksProhibitedMovement, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(true);
            }
            // if the destination IS the root, that's fine...anything can move there.
            if (hvoDest == hvoTemplate)
            {
                return(false);
            }
            // It's OK to move a leaf to a group (one level down from the root, as long as
            // the destination 'group' isn't a column that's in use.
            bool moveColumnIsLeaf = movingColumn.SubPossibilitiesOS.Count == 0;

            if (cache.GetOwnerOfObject(hvoDest) == hvoTemplate && moveColumnIsLeaf)
            {
                CmPossibility dest = (CmPossibility.CreateFromDBObject(cache, hvoDest))
                                     as CmPossibility;
                // If it isn't already a group, we can only turn it into one if it's empty
                if (dest.SubPossibilitiesOS.Count == 0)
                {
                    return(dest.CheckAndReportProtectedChartColumn());
                }
                // If it's already a group it should be fine as a destination.
                return(false);
            }
            // Anything else represents an attempt to make the tree too deep, e.g., moving a
            // column into child column, or a group into another group.
            MessageBox.Show(m_tree, xWorksStrings.ksTemplateTooDeep,
                            xWorksStrings.ksProhibitedMovement, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return(true);
        }