コード例 #1
0
ファイル: FilterTab.cs プロジェクト: zrolfs/pwiz
        void CommitFilterOpCombo()
        {
            var dataGridViewComboBoxEditingControl = dataGridViewFilter.EditingControl as DataGridViewComboBoxEditingControl;

            if (dataGridViewComboBoxEditingControl == null || dataGridViewFilter.CurrentRow == null)
            {
                return;
            }
            var rowIndex        = dataGridViewFilter.CurrentRow.Index;
            var filterOperation = FilterOperationFromDisplayName(dataGridViewComboBoxEditingControl.Text);

            if (filterOperation == null)
            {
                return;
            }
            if (filterOperation == ViewInfo.Filters[rowIndex].FilterSpec.Operation)
            {
                return;
            }
            var newFilters       = ViewSpec.Filters.ToArray();
            var columnDescriptor = ViewInfo.Filters[rowIndex].ColumnDescriptor;

            newFilters[rowIndex] = newFilters[rowIndex].SetPredicate(
                FilterPredicate.CreateFilterPredicate(columnDescriptor.DataSchema, columnDescriptor.PropertyType, filterOperation,
                                                      dataGridViewFilter.CurrentRow.Cells[colFilterOperand.Index].Value as string));
            ViewSpec = ViewSpec.SetFilters(newFilters);
        }
コード例 #2
0
ファイル: FilterSpecTest.cs プロジェクト: zrolfs/pwiz
        public void TestFilterSpecRoundTrips()
        {
            var propertyPath        = PropertyPath.Root.Property("property");
            var invariantDataSchema = new DataSchema();

            foreach (var cultureInfo in ListTestCultureInfos())
            {
                var dataSchema = new DataSchema(new DataSchemaLocalizer(cultureInfo));
                foreach (var testOperand in ListTestOperands())
                {
                    var columnType      = testOperand.GetType();
                    var filterPredicate = FilterPredicate.CreateFilterPredicate(dataSchema, columnType,
                                                                                FilterOperations.OP_EQUALS, ValueToString(testOperand, cultureInfo));
                    var invariantFilterPredicate = FilterPredicate.CreateFilterPredicate(invariantDataSchema, columnType,
                                                                                         FilterOperations.OP_EQUALS, ValueToString(testOperand, CultureInfo.InvariantCulture));
                    Assert.AreEqual(invariantFilterPredicate, filterPredicate);
                    var filterSpec            = new FilterSpec(propertyPath, filterPredicate);
                    var predicateOperandValue = filterSpec.Predicate.GetOperandValue(dataSchema, columnType);
                    var expectedOperandValue  = predicateOperandValue is double
                                                ?Convert.ChangeType(testOperand, typeof(double))
                                                    : testOperand;

                    Assert.AreEqual(expectedOperandValue, predicateOperandValue);
                    Assert.AreEqual(ValueToString(testOperand, cultureInfo), filterSpec.Predicate.GetOperandDisplayText(dataSchema, columnType));
                    var filterSpecRoundTrip = RoundTripToXml(filterSpec);
                    Assert.AreEqual(expectedOperandValue, filterSpecRoundTrip.Predicate.GetOperandValue(dataSchema, columnType));
                    Assert.AreEqual(ValueToString(testOperand, cultureInfo), filterSpecRoundTrip.Predicate.GetOperandDisplayText(dataSchema, columnType));
                }
            }
        }
コード例 #3
0
        public void TestViewLayoutRowTransforms()
        {
            var dataSchema = new DataSchema();
            var viewLayout = new ViewLayout("TestName").ChangeRowTransforms(
                new IRowTransform[]
            {
                new PivotSpec()
                .ChangeRowHeaders(new[]
                                  { new PivotSpec.Column(new ColumnId("RowHeaderOne")).ChangeCaption("MyCaption") })
                .ChangeColumnHeaders(new[] { new PivotSpec.Column(new ColumnId("ColumnOne")), })
                .ChangeValues(new[]
                {
                    (PivotSpec.AggregateColumn) new PivotSpec.AggregateColumn(new ColumnId("ValueOne"),
                                                                              AggregateOperation.Cv).ChangeCaption("Aggregate column caption"),
                }),
                new RowFilter("filterText", true, new[]
                {
                    new RowFilter.ColumnFilter(new ColumnId("column1"), FilterPredicate.CreateFilterPredicate(dataSchema, typeof(string), FilterOperations.OP_CONTAINS, "contains1"))
                }).SetColumnSorts(new[]
                {
                    new RowFilter.ColumnSort(new ColumnId("columnSort1"), ListSortDirection.Ascending),
                    new RowFilter.ColumnSort(new ColumnId("columnSort2"), ListSortDirection.Descending)
                })
            }
                ).ChangeColumnFormats(new []
            {
                Tuple.Create(new ColumnId("ColumnId1"), ColumnFormat.EMPTY.ChangeFormat("R").ChangeWidth(20))
            });
            var viewLayoutList = new ViewLayoutList("Test").ChangeLayouts(new [] { viewLayout })
                                 .ChangeDefaultLayoutName("TestName");
            var roundTrip = RoundTripToXml(viewLayoutList);

            Assert.AreEqual(viewLayoutList, roundTrip);
        }
コード例 #4
0
        private RowFilter.ColumnFilter CreateColumnFilter(ColumnId columnId, IFilterOperation filterOp, double operand)
        {
            var op = FilterPredicate.CreateFilterPredicate(_bindingListSource.ViewInfo.DataSchema,
                                                           typeof(double), filterOp,
                                                           operand.ToString(CultureInfo.CurrentCulture));

            return(new RowFilter.ColumnFilter(columnId, op));
        }
コード例 #5
0
ファイル: FilterTab.cs プロジェクト: zrolfs/pwiz
 private FilterPredicate SafeCreateFilterPredicate(DataSchema dataSchema, Type columnType,
                                                   IFilterOperation filterOperation, string operand)
 {
     try
     {
         return(FilterPredicate.CreateFilterPredicate(dataSchema, columnType, filterOperation, operand));
     }
     catch
     {
         return(FilterPredicate.CreateFilterPredicate(dataSchema, typeof(string), filterOperation, operand));
     }
 }
コード例 #6
0
        private RowFilter.ColumnFilter MakeColumnFilter(ComboBox comboOperation, TextBox text)
        {
            FilterItem filterItem = comboOperation.SelectedItem as FilterItem;

            if (null == filterItem || FilterOperations.OP_HAS_ANY_VALUE == filterItem.FilterOperation)
            {
                return(null);
            }
            var filterPredicate = FilterPredicate.CreateFilterPredicate(DataSchema, PropertyDescriptor.PropertyType,
                                                                        filterItem.FilterOperation, text.Text);

            return(new RowFilter.ColumnFilter(ColumnId.GetColumnId(PropertyDescriptor), filterPredicate));
        }
コード例 #7
0
        public void TestDataBindingIsSulfur()
        {
            var dataSchema = new DataSchema();
            var viewSpec   =
                new ViewSpec().SetColumns(new[]
                                          { new ColumnSpec(PropertyPath.Parse("Code")), new ColumnSpec(PropertyPath.Parse("Molecule!*.Key")), })
                .SetFilters(new[]
                            { new FilterSpec(PropertyPath.Parse("Molecule!*.Key"), FilterPredicate.CreateFilterPredicate(dataSchema, typeof(string), FilterOperations.OP_EQUALS, "S")) });
            var bindingListSource = new BindingListSource();

            bindingListSource.SetView(new ViewInfo(dataSchema, typeof(AminoAcid), viewSpec), AminoAcid.AMINO_ACIDS);
            Assert.AreEqual(2, bindingListSource.Count);
        }
コード例 #8
0
        private List <TItem> ApplyFilter <TItem>(IFilterOperation filterOperation, string operand, IEnumerable <TItem> items)
        {
            var dataSchema       = new DataSchema(new DataSchemaLocalizer(CultureInfo.CurrentCulture));
            var columnDescriptor = ColumnDescriptor.RootColumn(dataSchema, typeof(TItem));

            if (null != operand)
            {
                Assert.IsNotNull(filterOperation.GetOperandType(columnDescriptor));
            }
            var filterPredicate = FilterPredicate.CreateFilterPredicate(dataSchema, typeof(TItem), filterOperation, operand);
            var predicate       = filterPredicate.MakePredicate(dataSchema, typeof(TItem));

            return(items.Where(item => predicate(item)).ToList());
        }
コード例 #9
0
ファイル: FilterTab.cs プロジェクト: tomas-pluskal/pwiz
 private void DataGridViewFilterOnCellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     if (InChangeView)
     {
         return;
     }
     if (e.ColumnIndex == colFilterOperation.Index || e.ColumnIndex == colFilterOperand.Index)
     {
         var newFilters      = ViewSpec.Filters.ToArray();
         var filterInfo      = ViewInfo.Filters[e.RowIndex];
         var filterPredicate = FilterPredicate.CreateFilterPredicate(
             filterInfo.ColumnDescriptor.DataSchema,
             filterInfo.ColumnDescriptor.PropertyType,
             FilterOperationFromDisplayName(
                 dataGridViewFilter.Rows[e.RowIndex].Cells[colFilterOperation.Index].Value as string),
             dataGridViewFilter.Rows[e.RowIndex].Cells[colFilterOperand.Index].Value as string);
         newFilters[e.RowIndex] = new FilterSpec(filterInfo.ColumnDescriptor.PropertyPath, filterPredicate);
         ViewSpec = ViewSpec.SetFilters(newFilters);
     }
 }