Exemple #1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Implement CreateTestData, called by InMemoryFdoTestBase set up.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void CreateTestData()
		{
			var servloc = Cache.ServiceLocator;

			ICmPossibilityFactory possibilityFactory = servloc.GetInstance<ICmPossibilityFactory>();
			// Add an annotation category (for Discourse)
			m_categoryDiscourse = possibilityFactory.Create();
			var affixCatList = servloc.GetInstance<ICmPossibilityListFactory>().Create();
			Cache.LangProject.AffixCategoriesOA = affixCatList;
			affixCatList.PossibilitiesOS.Add(m_categoryDiscourse);

			// Add an annotation category (for Grammar)
			m_categoryGrammar = possibilityFactory.Create();
			affixCatList.PossibilitiesOS.Add(m_categoryGrammar);

			// add a sub-annotation category (for "Pronominal reference")
			m_categoryGrammar_PronominalRef = possibilityFactory.Create();
			m_categoryGrammar.SubPossibilitiesOS.Add(m_categoryGrammar_PronominalRef);

			// Set up a filter, with a CmCell we can test on.
			ICmFilter filter = servloc.GetInstance<ICmFilterFactory>().Create();
			Cache.LangProject.FiltersOC.Add(filter);
			ICmRow row = servloc.GetInstance<ICmRowFactory>().Create();
			filter.RowsOS.Add(row);
			m_cell = servloc.GetInstance<ICmCellFactory>().Create();
			row.CellsOS.Add(m_cell);
		}
Exemple #2
0
        public void BuildCmFilter2()
        {
            // Setup test values
            Cache.LangProject.PeopleOA = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create();
            ICmPossibility person1 = Cache.ServiceLocator.GetInstance <ICmPersonFactory>().Create();

            Cache.LangProject.PeopleOA.PossibilitiesOS.Add(person1);
            person1.ForeColor = 5;
            person1.BackColor = 10;

            // Setup filter
            ILcmOwningCollection <ICmFilter> filtersCol = Cache.LangProject.FiltersOC;
            ICmFilter filter = Cache.ServiceLocator.GetInstance <ICmFilterFactory>().Create();

            filtersCol.Add(filter);
            filter.ColumnInfo = CmPossibilityTags.kClassId + "," + CmPossibilityTags.kflidForeColor
                                + "|" + CmPossibilityTags.kClassId + "," + CmPossibilityTags.kflidBackColor;
            ICmRow row = Cache.ServiceLocator.GetInstance <ICmRowFactory>().Create();

            filter.RowsOS.Add(row);
            ICmCell cell1 = Cache.ServiceLocator.GetInstance <ICmCellFactory>().Create();

            row.CellsOS.Add(cell1);
            cell1.Contents = MakeString("= 5");
            ICmCell cell2 = Cache.ServiceLocator.GetInstance <ICmCellFactory>().Create();

            row.CellsOS.Add(cell2);
            cell2.Contents = MakeString("= 10");

            // Check the result
            filter.InitCriteria();
            Assert.IsTrue(filter.MatchesCriteria(person1.Hvo));
        }
Exemple #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initialize the filter so it can check for matches in reference collections.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void InitReferenceCriteria(ICmCell cell, int filteredFlid)
        {
            cell.ParseObjectMatchCriteria();

            if (cell is CmCell && ((CmCell)cell).MatchOnlyEmptyRefCollection)
            {
                return;
            }

            // Do we need to prompt the user for the value he wants to match?
            if (cell.MatchValue == 0 || ShowPrompt == 1)
            {
                throw new NotImplementedException("Need to implement prompting the user for filter information");
                // Prompt the user for a possibility.
                //Debug.Assert(m_possSupplier != null);
                //int hvoPossList = m_userView.GetPossibilityListForProperty(filteredFlid);
                //if (hvoPossList == 0)
                //    throw new Exception("Couldn't find appropriate Possibility List to prompt for filter criteria");

                //// The possibility supplier actually displays the Chooser dialog to prompt the user.
                //ICmPossibility pss = m_possSupplier.GetPossibility((CmPossibilityList)Services.GetObject(hvoPossList),
                //    (CmPossibility)Services.GetObject(cell.MatchValue));
                //if (pss == null)
                //    throw new Exception("User cancelled Filter");

                //cell.MatchValue = pss.Hvo;
            }
        }
Exemple #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Implement CreateTestData, called by InMemoryLcmTestBase set up.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void CreateTestData()
        {
            var servloc = Cache.ServiceLocator;

            ICmPossibilityFactory possibilityFactory = servloc.GetInstance <ICmPossibilityFactory>();

            // Add an annotation category (for Discourse)
            m_categoryDiscourse = possibilityFactory.Create();
            var affixCatList = servloc.GetInstance <ICmPossibilityListFactory>().Create();

            Cache.LangProject.AffixCategoriesOA = affixCatList;
            affixCatList.PossibilitiesOS.Add(m_categoryDiscourse);

            // Add an annotation category (for Grammar)
            m_categoryGrammar = possibilityFactory.Create();
            affixCatList.PossibilitiesOS.Add(m_categoryGrammar);

            // add a sub-annotation category (for "Pronominal reference")
            m_categoryGrammar_PronominalRef = possibilityFactory.Create();
            m_categoryGrammar.SubPossibilitiesOS.Add(m_categoryGrammar_PronominalRef);

            // Set up a filter, with a CmCell we can test on.
            ICmFilter filter = servloc.GetInstance <ICmFilterFactory>().Create();

            Cache.LangProject.FiltersOC.Add(filter);
            ICmRow row = servloc.GetInstance <ICmRowFactory>().Create();

            filter.RowsOS.Add(row);
            m_cell = servloc.GetInstance <ICmCellFactory>().Create();
            row.CellsOS.Add(m_cell);
        }
Exemple #5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initialize the filter so it can check for matches in reference collections.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void InitReferenceCriteria(ICmCell cell, int filteredFlid)
        {
            cell.ParseObjectMatchCriteria();

            if (cell is CmCell && ((CmCell)cell).MatchOnlyEmptyRefCollection)
            {
                return;
            }

            // Do we need to prompt the user for the value he wants to match?
            if (cell.MatchValue == 0 || ShowPrompt == 1)
            {
                // Prompt the user for a possibility.
                Debug.Assert(m_userView != null);
                Debug.Assert(m_possSupplier != null);
                int hvoPossList = m_userView.GetPossibilityListForProperty(filteredFlid);
                if (hvoPossList == 0)
                {
                    throw new Exception("Couldn't find appropriate Possibility List to prompt for filter criteria");
                }

                // The possibility supplier actually displays the Chooser dialog to prompt the user.
                int hvoPoss = m_possSupplier.GetPossibility(
                    new CmPossibilityList(m_cache, hvoPossList), cell.MatchValue);

                if (hvoPoss == 0)
                {
                    throw new Exception("User cancelled Filter");
                }

                cell.MatchValue = hvoPoss;
            }
        }
Exemple #6
0
        public void GreaterThanOrEqual()
        {
            // Setup test values
            Cache.LangProject.PeopleOA = new CmPossibilityList();
            ICmPossibility person1 = Cache.LangProject.PeopleOA.PossibilitiesOS.Append(new CmPerson());

            person1.ForeColor = 4;
            ICmPossibility person2 = Cache.LangProject.PeopleOA.PossibilitiesOS.Append(new CmPerson());

            person2.ForeColor = 5;
            ICmPossibility person3 = Cache.LangProject.PeopleOA.PossibilitiesOS.Append(new CmPerson());

            person3.ForeColor = 10;

            // Setup filter
            FdoOwningCollection <ICmFilter> filtersCol = Cache.LangProject.FiltersOC;
            ICmFilter filter = filtersCol.Add(new CmFilter());

            filter.ColumnInfo = CmPossibility.kClassId + "," + (int)CmPossibility.CmPossibilityTags.kflidForeColor;
            ICmRow  row   = filter.RowsOS.Append(new CmRow());
            ICmCell cell1 = row.CellsOS.Append(new DummyCmCell());

            cell1.Contents.Text = ">= 5";

            // Check the result
            ((CmFilter)filter).InitCriteria();
            Assert.IsFalse(((CmFilter)filter).MatchesCriteria(person1.Hvo));
            Assert.IsTrue(((CmFilter)filter).MatchesCriteria(person2.Hvo));
            Assert.IsTrue(((CmFilter)filter).MatchesCriteria(person3.Hvo));
        }
Exemple #7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initialize the filter so it can check for matches. This must be called once before
        /// calling <see cref="MatchesCriteria"/>.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void InitCriteria()
        {
            lock (SyncRoot)
            {
                m_filteredFieldTypes.Clear();
                m_filteredFlids.Clear();
                m_cells.Clear();

                // Get the filter's essential details
                string[] columns = ColumnInfo.Split('|');

                ICmRow row = RowsOS[0];
                for (int i = 0; i < row.CellsOS.Count; i++)
                {
                    string[] columnInfo = columns[i].Split(new char[] { ',' }, 2);
                    m_filteredFlids.Add(Int32.Parse(columnInfo[1]));
                    m_filteredFieldTypes.Add((CellarPropertyType)m_cache.MetaDataCache.GetFieldType(m_filteredFlids[i]));
                    ICmCell tempCell = row.CellsOS[i];
                    m_cells.Add(tempCell);

                    // Determine the field value this filter wants to match
                    switch (m_filteredFieldTypes[i])
                    {
                    case CellarPropertyType.Integer:
                        // ENHANCE: Someday handle prompting user
                        Debug.Assert(ShowPrompt == 0, "Can't prompt for int values yet.");
                        tempCell.ParseIntegerMatchCriteria();
                        break;

                    case CellarPropertyType.ReferenceAtomic:
                    case CellarPropertyType.ReferenceSequence:
                    case CellarPropertyType.ReferenceCollection:
                        InitReferenceCriteria(tempCell, m_filteredFlids[i]);
                        break;

                    default:
                        throw new Exception("Attempt to filter on unexpected type of field.");
                    }
                }
            }
        }
Exemple #8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes the list of categories based on categories in the specified filter.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private bool InitializeFromFilter(FdoCache cache, ICmFilter filter,
                                          out List <int> initiallySelectedList)
        {
            initiallySelectedList = new List <int>();

            if (filter == null || filter.RowsOS.Count == 0 || filter.RowsOS[0].CellsOS.Count == 0)
            {
                return(false);
            }

            bool fFilterContainsCategories = false;

            // Get the pairs of class ids and flids.
            string[] pairs = filter.ColumnInfo.Split('|');
            Debug.Assert(filter.RowsOS[0].CellsOS.Count == pairs.Length);

            for (int i = 0; i < pairs.Length; i++)
            {
                ICmCell cell = filter.RowsOS[0].CellsOS[i];
                Guid    guid;

                // Get the flid for this cell.
                string[] pair = pairs[i].Split(',');
                int      flid = 0;
                int.TryParse(pair[1], out flid);

                if (flid == ScrScriptureNoteTags.kflidCategories)
                {
                    fFilterContainsCategories = true;
                    cell.ParseObjectMatchCriteria();
                    if (cell.Contents.RunCount > 1)
                    {
                        guid = TsStringUtils.GetGuidFromRun(cell.Contents, 1);
                        int hvo = cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(guid).Hvo;
                        initiallySelectedList.Add(hvo);
                    }
                }
            }

            return(fFilterContainsCategories);
        }
Exemple #9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initialize the filter so it can check for matches in reference collections.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void InitReferenceCriteria(ICmCell cell, int filteredFlid)
		{
			cell.ParseObjectMatchCriteria();

			if (cell is CmCell && ((CmCell)cell).MatchOnlyEmptyRefCollection)
				return;

			// Do we need to prompt the user for the value he wants to match?
			if (cell.MatchValue == 0 || ShowPrompt == 1)
			{
				throw new NotImplementedException("Need to implement prompting the user for filter information");
				// Prompt the user for a possibility.
				//Debug.Assert(m_possSupplier != null);
				//int hvoPossList = m_userView.GetPossibilityListForProperty(filteredFlid);
				//if (hvoPossList == 0)
				//    throw new Exception("Couldn't find appropriate Possibility List to prompt for filter criteria");

				//// The possibility supplier actually displays the Chooser dialog to prompt the user.
				//ICmPossibility pss = m_possSupplier.GetPossibility((CmPossibilityList)Services.GetObject(hvoPossList),
				//    (CmPossibility)Services.GetObject(cell.MatchValue));
				//if (pss == null)
				//    throw new Exception("User cancelled Filter");

				//cell.MatchValue = pss.Hvo;
			}
		}
Exemple #10
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initialize the filter so it can check for matches in reference collections.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void InitReferenceCriteria(ICmCell cell, int filteredFlid)
		{
			cell.ParseObjectMatchCriteria();

			if (cell is CmCell && ((CmCell)cell).MatchOnlyEmptyRefCollection)
				return;

			// Do we need to prompt the user for the value he wants to match?
			if (cell.MatchValue == 0 || ShowPrompt == 1)
			{
				// Prompt the user for a possibility.
				Debug.Assert(m_userView != null);
				Debug.Assert(m_possSupplier != null);
				int hvoPossList = m_userView.GetPossibilityListForProperty(filteredFlid);
				if (hvoPossList == 0)
					throw new Exception("Couldn't find appropriate Possibility List to prompt for filter criteria");

				// The possibility supplier actually displays the Chooser dialog to prompt the user.
				int hvoPoss = m_possSupplier.GetPossibility(
					new CmPossibilityList(m_cache, hvoPossList), cell.MatchValue);

				if (hvoPoss == 0)
					throw new Exception("User cancelled Filter");

				cell.MatchValue = hvoPoss;
			}
		}
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes the form's controls from the settings in the filter.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void InitializeFromFilter()
        {
            if (m_filter == null || m_filter.RowsOS.Count == 0 || m_filter.RowsOS[0].CellsOS.Count == 0)
            {
                return;
            }

            // Get the pairs of class ids and flids.
            string[] pairs = m_filter.ColumnInfo.Split('|');
            Debug.Assert(m_filter.RowsOS[0].CellsOS.Count == pairs.Length);

            for (int i = 0; i < pairs.Length; i++)
            {
                ICmCell cell = m_filter.RowsOS[0].CellsOS[i];

                // Get the flid for this cell.
                string[] pair = pairs[i].Split(',');
                int      flid = 0;
                int.TryParse(pair[1], out flid);

                switch (flid)
                {
                case ScrScriptureNoteTags.kflidResolutionStatus:
                    chkStatus.Checked = true;
                    cell.ParseIntegerMatchCriteria();
                    rbResolved.Checked   = (cell.MatchValue == 1);
                    rbUnresolved.Checked = (cell.MatchValue == 0);
                    break;

                case CmAnnotationTags.kflidAnnotationType:
                    chkType.Checked = true;
                    cell.ParseObjectMatchCriteria();
                    Guid guid = TsStringUtils.GetGuidFromRun(cell.Contents, 1);
                    rbConsultant.Checked = (guid == CmAnnotationDefnTags.kguidAnnConsultantNote);
                    rbTranslator.Checked = (guid == CmAnnotationDefnTags.kguidAnnTranslatorNote);
                    break;

                case CmBaseAnnotationTags.kflidBeginRef:
                    chkScrRange.Checked = true;
                    cell.ParseIntegerMatchCriteria();
                    ScrReference scrRef = new ScrReference(cell.MatchValue, m_scr.Versification);
                    // If the reference was adjusted to 0:0 to include notes in the title and
                    // introduction, adjust it back to 1:1 so we don't confuse the user.
                    if (scrRef.Chapter == 0)
                    {
                        scrRef.Chapter = 1;
                    }
                    if (scrRef.Verse == 0)
                    {
                        scrRef.Verse = 1;
                    }

                    if (cell.ComparisonType == ComparisonTypes.kGreaterThanEqual)
                    {
                        scrBookFrom.ScReference = scrRef;
                    }
                    else
                    {
                        scrBookTo.ScReference = scrRef;
                    }
                    break;
                }
            }
        }