Beispiel #1
0
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            if (FoldChangeBindingSource != null)
            {
                AllowDisplayTip = true;

                _bindingListSource                         = FoldChangeBindingSource.GetBindingListSource();
                _bindingListSource.ListChanged            += BindingListSourceOnListChanged;
                _bindingListSource.AllRowsChanged         += BindingListSourceAllRowsChanged;
                zedGraphControl.GraphPane.AxisChangeEvent += GraphPane_AxisChangeEvent;

                if (_skylineWindow == null)
                {
                    _skylineWindow = ((SkylineDataSchema)_bindingListSource.ViewInfo.DataSchema).SkylineWindow;
                    if (_skylineWindow != null)
                    {
                        _skylineWindow.SequenceTree.AfterSelect += SequenceTreeOnAfterSelect;
                    }
                }

                UpdateGraph(Settings.Default.FilterVolcanoPlotPoints);
            }
        }
Beispiel #2
0
 public DocumentGridForm(SkylineViewContext viewContext)
 {
     InitializeComponent();
     _originalFormTitle = Text;
     BindingListSource.SetViewContext(viewContext);
     BindingListSource.ListChanged += BindingListSourceOnListChanged;
 }
Beispiel #3
0
        protected virtual void WriteData(IProgressMonitor progressMonitor, TextWriter writer,
                                         BindingListSource bindingListSource, DsvWriter dsvWriter)
        {
            IProgressStatus status = new ProgressStatus(string.Format(Resources.AbstractViewContext_WriteData_Writing__0__rows, bindingListSource.Count));

            WriteDataWithStatus(progressMonitor, ref status, writer, bindingListSource, dsvWriter);
        }
Beispiel #4
0
 public void Export(Control owner, BindingListSource bindingListSource)
 {
     try
     {
         var    dataFormats = new[] { DataFormats.CSV, DataFormats.TSV };
         string fileFilter  = string.Join(@"|", dataFormats.Select(format => format.FileFilter).ToArray());
         using (var saveFileDialog = new SaveFileDialog
         {
             Filter = fileFilter,
             InitialDirectory = GetExportDirectory(),
             FileName = GetDefaultExportFilename(bindingListSource.ViewInfo),
         })
         {
             if (saveFileDialog.ShowDialog(FormUtil.FindTopLevelOwner(owner)) == DialogResult.Cancel)
             {
                 return;
             }
             var dataFormat = dataFormats[saveFileDialog.FilterIndex - 1];
             ExportToFile(owner, bindingListSource, saveFileDialog.FileName, dataFormat.GetDsvWriter());
             SetExportDirectory(Path.GetDirectoryName(saveFileDialog.FileName));
         }
     }
     catch (Exception exception)
     {
         ShowMessageBox(owner, Resources.AbstractViewContext_Export_There_was_an_error_writing_to_the_file__ + exception.Message,
                        MessageBoxButtons.OK);
     }
 }
 public void Export(Control owner, BindingListSource bindingListSource)
 {
     try
     {
         var    dataFormats = new[] { DataFormats.CSV, DataFormats.TSV };
         string fileFilter  = string.Join("|", dataFormats.Select(format => format.FileFilter).ToArray()); // Not L10N
         using (var saveFileDialog = new SaveFileDialog
         {
             Filter = fileFilter,
             InitialDirectory = GetExportDirectory(),
             FileName = GetDefaultExportFilename(bindingListSource.ViewInfo),
         })
         {
             if (saveFileDialog.ShowDialog(FormUtil.FindTopLevelOwner(owner)) == DialogResult.Cancel)
             {
                 return;
             }
             var dataFormat = dataFormats[saveFileDialog.FilterIndex - 1];
             SafeWriteToFile(owner, saveFileDialog.FileName, stream =>
             {
                 var writer             = new StreamWriter(stream, new UTF8Encoding(false));
                 var cloneableRowSource = bindingListSource.RowSource as ICloneableList;
                 bool finished          = false;
                 if (null == cloneableRowSource)
                 {
                     var progressMonitor = new UncancellableProgressMonitor();
                     WriteData(progressMonitor, writer, bindingListSource, dataFormat.GetDsvWriter());
                     finished = true;
                 }
                 else
                 {
                     var clonedList = cloneableRowSource.DeepClone();
                     RunLongJob(owner, progressMonitor =>
                     {
                         using (var clonedBindingList = new BindingListSource())
                         {
                             SetViewFrom(bindingListSource, clonedList, clonedBindingList);
                             WriteData(progressMonitor, writer, clonedBindingList, dataFormat.GetDsvWriter());
                             finished = !progressMonitor.IsCanceled;
                         }
                     });
                 }
                 if (finished)
                 {
                     writer.Flush();
                 }
                 return(finished);
             });
             SetExportDirectory(Path.GetDirectoryName(saveFileDialog.FileName));
         }
     }
     catch (Exception exception)
     {
         ShowMessageBox(owner, Resources.AbstractViewContext_Export_There_was_an_error_writing_to_the_file__ + exception.Message,
                        MessageBoxButtons.OK);
     }
 }
Beispiel #6
0
 protected void SetViewFrom(BindingListSource sourceBindingList, IRowSource newRowSource,
                            BindingListSource targetBindingList)
 {
     targetBindingList.SetView(sourceBindingList.ViewInfo, newRowSource);
     targetBindingList.RowFilter = sourceBindingList.RowFilter;
     if (sourceBindingList.SortDescriptions != null)
     {
         targetBindingList.ApplySort(sourceBindingList.SortDescriptions);
     }
 }
Beispiel #7
0
        public bool ChooseView(ViewName viewName)
        {
            var viewInfo = BindingListSource.ViewContext.GetViewInfo(viewName);

            if (null == viewInfo)
            {
                return(false);
            }
            BindingListSource.SetViewContext(BindingListSource.ViewContext, viewInfo);
            return(true);
        }
Beispiel #8
0
        public DataGridViewColumn FindColumn(PropertyPath propertyPath)
        {
            var propertyDescriptor =
                BindingListSource.GetItemProperties(null)
                .OfType <ColumnPropertyDescriptor>()
                .FirstOrDefault(colPd => Equals(propertyPath, colPd.PropertyPath));

            if (null == propertyDescriptor)
            {
                return(null);
            }
            return(DataGridView.Columns.Cast <DataGridViewColumn>().FirstOrDefault(col => col.DataPropertyName == propertyDescriptor.Name));
        }
Beispiel #9
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);
        }
Beispiel #10
0
 public virtual void ToggleClustering(BindingListSource bindingListSource, bool turnClusteringOn)
 {
     if (null == bindingListSource.ClusteringSpec)
     {
         bindingListSource.ClusteringSpec = ClusteringSpec.DEFAULT;
     }
     else
     {
         if (!bindingListSource.IsComplete && !(bindingListSource.ReportResults is ClusteredReportResults))
         {
             return;
         }
         bindingListSource.ClusteringSpec = null;
     }
 }
Beispiel #11
0
        public DataGridViewColumn FindColumn(PropertyPath propertyPath)
        {
            // Get the list separately for debugging, since this helps in figuring out what
            // the propertyPath should be.
            var propertyDescriptorList = BindingListSource.GetItemProperties(null)
                                         .OfType <ColumnPropertyDescriptor>();
            var propertyDescriptor = propertyDescriptorList
                                     .FirstOrDefault(colPd => Equals(propertyPath, colPd.PropertyPath));

            if (null == propertyDescriptor)
            {
                return(null);
            }
            return(DataGridView.Columns.Cast <DataGridViewColumn>().FirstOrDefault(col => col.DataPropertyName == propertyDescriptor.Name));
        }
Beispiel #12
0
        public DocumentGridForm(SkylineViewContext viewContext)
        {
            InitializeComponent();
            BindingListSource.QueryLock = viewContext.SkylineDataSchema.QueryLock;
            _originalFormTitle          = Text;
            BindingListSource.SetViewContext(viewContext);
            BindingListSource.ListChanged += BindingListSourceOnListChanged;
            _skylineWindow = viewContext.SkylineDataSchema.SkylineWindow;
            var documentGridViewContext = viewContext as DocumentGridViewContext;

            if (documentGridViewContext != null)
            {
                documentGridViewContext.BoundDataGridView = DataGridView;
            }
        }
Beispiel #13
0
        public void SetSortDirection(PropertyDescriptor propertyDescriptor, ListSortDirection direction)
        {
            if (null == propertyDescriptor)
            {
                return;
            }
            List <ListSortDescription> sortDescriptions = new List <ListSortDescription>();

            sortDescriptions.Add(new ListSortDescription(propertyDescriptor, direction));
            if (null != BindingListSource.SortDescriptions)
            {
                sortDescriptions.AddRange(
                    BindingListSource.SortDescriptions.OfType <ListSortDescription>()
                    .Where(sortDescription => sortDescription.PropertyDescriptor.Name != propertyDescriptor.Name));
            }
            BindingListSource.ApplySort(new ListSortDescriptionCollection(sortDescriptions.ToArray()));
        }
Beispiel #14
0
 public void AddRef()
 {
     if (Interlocked.Increment(ref _referenceCount) == 1)
     {
         _skylineDataSchema = new SkylineDataSchema(GroupComparisonModel.DocumentContainer,
                                                    SkylineDataSchema.GetLocalizedSchemaLocalizer());
         var viewInfo = new ViewInfo(_skylineDataSchema, typeof(FoldChangeRow), GetDefaultViewSpec(new FoldChangeRow[0]))
                        .ChangeViewGroup(ViewGroup.BUILT_IN);
         var rowSourceInfo = new RowSourceInfo(typeof(FoldChangeRow), new StaticRowSource(new FoldChangeRow[0]), new[] { viewInfo });
         ViewContext        = new GroupComparisonViewContext(_skylineDataSchema, new[] { rowSourceInfo });
         _container         = new Container();
         _bindingListSource = new BindingListSource(_container);
         _bindingListSource.SetViewContext(ViewContext, viewInfo);
         GroupComparisonModel.ModelChanged += GroupComparisonModelOnModelChanged;
         GroupComparisonModelOnModelChanged(GroupComparisonModel, new EventArgs());
     }
 }
Beispiel #15
0
        public override void ToggleClustering(BindingListSource bindingListSource, bool turnClusteringOn)
        {
            if (Equals(ViewGroup.BUILT_IN.Id, bindingListSource.ViewInfo.ViewGroup.Id))
            {
                if (turnClusteringOn && bindingListSource.ViewInfo.ViewSpec.Name == AbstractViewContext.DefaultViewName)
                {
                    bindingListSource.SetViewContext(this, GetViewInfo(ViewGroup.BUILT_IN.Id.ViewName(FoldChangeBindingSource.CLUSTERED_VIEW_NAME)));
                    return;
                }

                if (!turnClusteringOn && bindingListSource.ViewInfo.ViewSpec.Name ==
                    FoldChangeBindingSource.CLUSTERED_VIEW_NAME)
                {
                    bindingListSource.SetViewContext(this, GetViewInfo(ViewGroup.BUILT_IN.Id.ViewName(AbstractViewContext.DefaultViewName)));
                }
            }
            base.ToggleClustering(bindingListSource, turnClusteringOn);
        }
Beispiel #16
0
        public void TestDataBindingIsNotNullFilter()
        {
            var dataSchema = new DataSchema();
            var viewSpec   = new ViewSpec().SetColumns(new[] { new ColumnSpec(PropertyPath.Parse("AminoAcidsDict!*.Value")), })
                             .SetSublistId(PropertyPath.Parse("AminoAcidsDict!*"));
            var viewSpecWithFilter = viewSpec.SetFilters(new[]
            {
                new FilterSpec(PropertyPath.Parse("AminoAcidsDict!*.Value"), FilterPredicate.IS_NOT_BLANK),
            });
            var bindingListSource           = new BindingListSource();
            var bindingListSourceWithFilter = new BindingListSource();

            bindingListSource.SetView(new ViewInfo(dataSchema, typeof(Peptide), viewSpec), null);
            bindingListSourceWithFilter.SetView(new ViewInfo(dataSchema, typeof(Peptide), viewSpecWithFilter), new[] { new Peptide("") });
            Assert.AreEqual(0, bindingListSourceWithFilter.Count);
            bindingListSource.RowSource = bindingListSourceWithFilter.RowSource;
            Assert.AreEqual(1, bindingListSource.Count);
        }
Beispiel #17
0
 protected override void OnShown(EventArgs e)
 {
     base.OnShown(e);
     if (null != FoldChangeBindingSource)
     {
         _bindingListSource              = FoldChangeBindingSource.GetBindingListSource();
         _bindingListSource.ListChanged += BindingListSourceOnListChanged;
         if (_skylineWindow == null)
         {
             _skylineWindow = ((SkylineDataSchema)_bindingListSource.ViewInfo.DataSchema).SkylineWindow;
             if (_skylineWindow != null)
             {
                 _skylineWindow.SequenceTree.AfterSelect += SequenceTreeOnAfterSelect;
             }
         }
         UpdateGraph();
     }
 }
Beispiel #18
0
        private void UpdateViewContext()
        {
            var documentGridViewContext = BindingListSource.ViewContext as DocumentGridViewContext;

            if (documentGridViewContext == null)
            {
                return;
            }
            documentGridViewContext.UpdateBuiltInViews();
            if (null != BindingListSource.ViewInfo && null != BindingListSource.ViewInfo.ViewGroup && ViewGroup.BUILT_IN.Id.Equals(BindingListSource.ViewInfo.ViewGroup.Id))
            {
                var viewName    = BindingListSource.ViewInfo.ViewGroup.Id.ViewName(BindingListSource.ViewInfo.Name);
                var newViewInfo = documentGridViewContext.GetViewInfo(viewName);
                if (null != newViewInfo && !Equals(newViewInfo.ViewSpec, BindingListSource.ViewSpec))
                {
                    BindingListSource.SetView(newViewInfo, BindingListSource.RowSource);
                }
            }
        }
Beispiel #19
0
 public void ExportToFile(Control owner, BindingListSource bindingListSource, String filename,
                          DsvWriter dsvWriter)
 {
     SafeWriteToFile(owner, filename, stream =>
     {
         var writer    = new StreamWriter(stream, new UTF8Encoding(false));
         bool finished = false;
         RunOnThisThread(owner, (cancellationToken, progressMonitor) =>
         {
             WriteData(progressMonitor, writer, bindingListSource, dsvWriter);
             finished = !progressMonitor.IsCanceled;
         });
         if (finished)
         {
             writer.Flush();
         }
         return(finished);
     });
 }
Beispiel #20
0
        public bool Export(CancellationToken cancellationToken, IProgressMonitor progressMonitor, ref IProgressStatus status, ViewInfo viewInfo, TextWriter writer, DsvWriter dsvWriter)
        {
            progressMonitor = progressMonitor ?? new SilentProgressMonitor();
            using (var bindingListSource = new BindingListSource(cancellationToken))
            {
                bindingListSource.SetViewContext(this, viewInfo);
                progressMonitor.UpdateProgress(status = status.ChangePercentComplete(5)
                                                        .ChangeMessage(Resources.ExportReportDlg_ExportReport_Writing_report));

                WriteDataWithStatus(progressMonitor, ref status, writer, bindingListSource, dsvWriter);
                if (progressMonitor.IsCanceled)
                {
                    return(false);
                }

                writer.Flush();
                progressMonitor.UpdateProgress(status = status.Complete());
            }
            return(true);
        }
 public void CopyAll(Control owner, BindingListSource bindingListSource)
 {
     try
     {
         StringWriter tsvWriter          = new StringWriter();
         var          cloneableRowSource = bindingListSource.RowSource as ICloneableList;
         if (null == cloneableRowSource)
         {
             var progressMonitor = new UncancellableProgressMonitor();
             WriteData(progressMonitor, tsvWriter, bindingListSource, DataFormats.TSV.GetDsvWriter());
         }
         else
         {
             var clonedList = cloneableRowSource.DeepClone();
             if (!RunLongJob(owner, progressMonitor =>
             {
                 using (var clonedBindingList = new BindingListSource())
                 {
                     SetViewFrom(bindingListSource, clonedList, clonedBindingList);
                     WriteData(progressMonitor, tsvWriter, clonedBindingList, DataFormats.TSV.GetDsvWriter());
                     progressMonitor.UpdateProgress(new ProgressStatus(string.Empty).Complete());
                 }
             }))
             {
                 return;
             }
         }
         DataObject dataObject = new DataObject();
         dataObject.SetText(tsvWriter.ToString());
         Clipboard.SetDataObject(dataObject);
     }
     catch (Exception exception)
     {
         ShowMessageBox(owner,
                        Resources.AbstractViewContext_CopyAll_There_was_an_error_copying_the_data_to_the_clipboard__ + exception.Message,
                        MessageBoxButtons.OK);
     }
 }
Beispiel #22
0
        public void TestPivotResultsThenIsotopeLabel()
        {
            var           assembly           = typeof(LiveReportPivotTest).Assembly;
            XmlSerializer documentSerializer = new XmlSerializer(typeof(SrmDocument));
            // ReSharper disable once AssignNullToNotNullAttribute
            var document = (SrmDocument)documentSerializer.Deserialize(
                assembly.GetManifestResourceStream(typeof(ReportSpecConverterTest), "silac_1_to_4.sky"));
            XmlSerializer reportSerializer = new XmlSerializer(typeof(ReportOrViewSpecList));
            // ReSharper disable once AssignNullToNotNullAttribute
            var views = (ReportOrViewSpecList)reportSerializer.Deserialize(
                assembly.GetManifestResourceStream(typeof(ReportSpecConverterTest), "LiveReportPivots.skyr"));
            var view = views.First(reportSpec => reportSpec.Name == "ResultSummaryPivotResultsThenLabelType").ViewSpec;
            var bindingListSource = new BindingListSource();
            var documentContainer = new MemoryDocumentContainer();

            Assert.IsTrue(documentContainer.SetDocument(document, null));
            var dataSchema = new SkylineDataSchema(documentContainer, DataSchemaLocalizer.INVARIANT);

            bindingListSource.SetViewContext(new DocumentGridViewContext(dataSchema), new ViewInfo(dataSchema, typeof(Precursor), view));
            var expectedColumnNames = new[] {
                "PeptideSequence",
                "Chromatograms Replicate",
                "Chromatograms PeptideRetentionTime",
                "light IsotopeLabelType",
                "light MeanTotalArea",
                "light Chromatograms TotalArea",
                "heavy IsotopeLabelType",
                "heavy MeanTotalArea",
                "heavy Chromatograms TotalArea",
            };
            var actualColumnNames =
                bindingListSource.GetItemProperties(null)
                .Cast <PropertyDescriptor>()
                .Select(pd => pd.DisplayName)
                .ToArray();

            CollectionAssert.AreEqual(expectedColumnNames, actualColumnNames);
        }
Beispiel #23
0
        public DocumentGridForm(SkylineViewContext viewContext, string text)
        {
            InitializeComponent();
            if (!string.IsNullOrEmpty(text))
            {
                Text = text;
            }
            _originalFormTitle = Text;
            if (viewContext == null)    // For designer
            {
                return;
            }
            BindingListSource.QueryLock = viewContext.SkylineDataSchema.QueryLock;
            BindingListSource.SetViewContext(viewContext);
            BindingListSource.ListChanged += BindingListSourceOnListChanged;
            _skylineWindow = viewContext.SkylineDataSchema.SkylineWindow;
            var documentGridViewContext = viewContext as DocumentGridViewContext;

            if (documentGridViewContext != null)
            {
                documentGridViewContext.BoundDataGridView = DataGridView;
            }
        }
Beispiel #24
0
 public void CopyAll(Control owner, BindingListSource bindingListSource)
 {
     try
     {
         StringWriter tsvWriter = new StringWriter();
         if (!RunOnThisThread(owner, (cancellationToken, progressMonitor) =>
         {
             WriteData(progressMonitor, tsvWriter, bindingListSource, DataFormats.TSV.GetDsvWriter());
             progressMonitor.UpdateProgress(new ProgressStatus(string.Empty).Complete());
         }))
         {
             return;
         }
         DataObject dataObject = new DataObject();
         dataObject.SetText(tsvWriter.ToString());
         Clipboard.SetDataObject(dataObject);
     }
     catch (Exception exception)
     {
         ShowMessageBox(owner,
                        Resources.AbstractViewContext_CopyAll_There_was_an_error_copying_the_data_to_the_clipboard__ + exception.Message,
                        MessageBoxButtons.OK);
     }
 }
        public void CheckReport(ReportSpec reportSpec)
        {
            string    message   = string.Format("Report {0}", reportSpec.Name);
            var       converter = new ReportSpecConverter(_dataSchema);
            var       viewInfo  = converter.Convert(reportSpec);
            var       report    = Report.Load(reportSpec);
            ResultSet resultSet;

            try
            {
                resultSet = report.Execute(_database);
            }
            catch (Exception)
            {
                return;
            }
            using (var bindingListSource = new BindingListSource())
            {
                bindingListSource.SetViewContext(new SkylineViewContext(viewInfo.ParentColumn, GetRowSource(viewInfo)),
                                                 viewInfo);
                var   oldCaptions = resultSet.ColumnInfos.Select(columnInfo => columnInfo.Caption).ToArray();
                var   properties  = bindingListSource.GetItemProperties(null);
                IList resultRows  = bindingListSource;
                var   newCaptions = properties.Cast <PropertyDescriptor>().Select(pd => pd.DisplayName).ToArray();
                if (!oldCaptions.SequenceEqual(newCaptions))
                {
                    CollectionAssert.AreEqual(oldCaptions, newCaptions, message);
                }
                if (resultSet.RowCount != resultRows.Count)
                {
                    Assert.AreEqual(resultSet.RowCount, resultRows.Count, message);
                }
                resultRows = SortRows(resultRows, properties);
                resultSet  = SortResultSet(resultSet);
                for (int iRow = 0; iRow < resultSet.RowCount; iRow++)
                {
                    for (int iCol = 0; iCol < resultSet.ColumnInfos.Count; iCol++)
                    {
                        var    propertyDescriptor = properties[iCol];
                        object oldValue           = resultSet.GetRow(iRow)[iCol];
                        object newValue           = propertyDescriptor.GetValue(resultRows[iRow]);
                        if (!Equals(oldValue, newValue))
                        {
                            Assert.AreEqual(oldValue, newValue,
                                            message + "{0}:Values are not equal on Row {1} Column {2} ({3}) FullName:{4}",
                                            message, iRow, iCol, propertyDescriptor.DisplayName, propertyDescriptor.Name);
                        }
                    }
                }
                foreach (char separator in new[] { ',', '\t' })
                {
                    StringWriter oldStringWriter = new StringWriter();
                    var          cultureInfo     = LocalizationHelper.CurrentCulture;
                    ResultSet.WriteReportHelper(resultSet, separator, oldStringWriter, cultureInfo);
                    StringWriter   newStringWriter    = new StringWriter();
                    var            skylineViewContext = (SkylineViewContext)bindingListSource.ViewContext;
                    ProgressStatus progressStatus     = new ProgressStatus("Status");
                    skylineViewContext.Export(null, ref progressStatus, viewInfo, newStringWriter,
                                              new DsvWriter(cultureInfo, separator));
                    var newLineSeparators = new[] { "\r\n" };
                    var oldLines          = oldStringWriter.ToString().Split(newLineSeparators, StringSplitOptions.None);
                    var newLines          = newStringWriter.ToString().Split(newLineSeparators, StringSplitOptions.None);
                    // TODO(nicksh): Old reports would hide columns for annotations that were not in the document.
                    bool anyHiddenColumns = resultSet.ColumnInfos.Any(column => column.IsHidden);
                    if (!anyHiddenColumns)
                    {
                        Assert.AreEqual(oldLines[0], newLines[0]);
                        CollectionAssert.AreEquivalent(oldLines, newLines);
                    }
                }
            }
        }
Beispiel #26
0
 public void ShowFormatDialog(DataGridViewColumn column)
 {
     _columnFilterPropertyDescriptor = BindingListSource.FindDataProperty(column.DataPropertyName);
     formatToolStripMenuItem_Click(formatToolStripMenuItem, new EventArgs());
 }
Beispiel #27
0
 private void clearSortToolStripMenuItem_Click(object sender, EventArgs e)
 {
     BindingListSource.ApplySort(new ListSortDescriptionCollection());
 }
Beispiel #28
0
        public void TestMapping()
        {
            var settings          = SrmSettingsList.GetDefault();
            var document          = new SrmDocument(settings);
            var documentContainer = new MemoryDocumentContainer();

            documentContainer.SetDocument(document, null);
            using (var database = new Database(settings))
            {
                var dataSchema     = new SkylineDataSchema(documentContainer, DataSchemaLocalizer.INVARIANT);
                var sessionFactory = database.SessionFactory;
                foreach (var classMetaData in sessionFactory.GetAllClassMetadata().Values)
                {
                    var tableType = classMetaData.GetMappedClass(EntityMode.Poco);
                    foreach (var propertyName in classMetaData.PropertyNames)
                    {
                        if (propertyName == "Protein" && tableType == typeof(DbProteinResult))
                        {
                            continue;
                        }
                        var queryDef = new QueryDef
                        {
                            Select = new[] { new ReportColumn(tableType, propertyName), }
                        };
                        var reportSpec   = new ReportSpec("test", queryDef);
                        var newTableType = ReportSpecConverter.GetNewTableType(reportSpec);
                        Assert.IsNotNull(newTableType, "No table for type {0}", tableType);
                        var converter = new ReportSpecConverter(dataSchema);
                        var viewInfo  = converter.Convert(reportSpec);
                        Assert.IsNotNull(viewInfo, "Unable to convert property {0} in table {1}", propertyName, tableType);
                        Assert.AreEqual(1, viewInfo.DisplayColumns.Count, "No conversion for property {0} in table {1}", propertyName, tableType);
                        Assert.IsNotNull(viewInfo.DisplayColumns[0].ColumnDescriptor, "Column not found for property {0} in table {1}", propertyName, tableType);
                        var report            = Report.Load(reportSpec);
                        var resultSet         = report.Execute(database);
                        var bindingListSource = new BindingListSource();
                        bindingListSource.SetViewContext(new SkylineViewContext(viewInfo.ParentColumn, Array.CreateInstance(viewInfo.ParentColumn.PropertyType, 0)), viewInfo);
                        var properties  = bindingListSource.GetItemProperties(null);
                        var oldCaptions = resultSet.ColumnInfos.Select(columnInfo => columnInfo.Caption).ToArray();
                        var newCaptions = properties.Cast <PropertyDescriptor>().Select(pd => pd.DisplayName).ToArray();
                        if (oldCaptions.Length != newCaptions.Length)
                        {
                            Console.Out.WriteLine(oldCaptions);
                        }
                        CollectionAssert.AreEqual(oldCaptions, newCaptions, "Caption mismatch on {0} in {1}", propertyName, tableType);
                        for (int i = 0; i < resultSet.ColumnInfos.Count; i++)
                        {
                            var    columnInfo      = resultSet.ColumnInfos[i];
                            var    formatAttribute = (FormatAttribute)properties[i].Attributes[typeof(FormatAttribute)];
                            string message         = string.Format("Format problem on column converted from {0} in {1}",
                                                                   columnInfo.ReportColumn.Column, columnInfo.ReportColumn.Table);
                            if (null == columnInfo.Format)
                            {
                                Assert.IsTrue(null == formatAttribute || null == formatAttribute.Format, message);
                            }
                            else
                            {
                                Assert.IsNotNull(formatAttribute, message);
                                Assert.AreEqual(columnInfo.Format, formatAttribute.Format, message);
                            }
                            if (columnInfo.IsNumeric)
                            {
                                Assert.IsNotNull(formatAttribute, message);
                                Assert.AreEqual(TextUtil.EXCEL_NA, formatAttribute.NullValue, message);
                            }
                            else
                            {
                                Assert.IsTrue(null == formatAttribute || null == formatAttribute.NullValue, message);
                            }
                        }
                    }
                }
            }
        }
Beispiel #29
0
        protected virtual void WriteDataWithStatus(IProgressMonitor progressMonitor, ref IProgressStatus status, TextWriter writer, BindingListSource bindingListSource, DsvWriter dsvWriter)
        {
            IList <RowItem>            rows       = Array.AsReadOnly(bindingListSource.Cast <RowItem>().ToArray());
            IList <PropertyDescriptor> properties = bindingListSource.GetItemProperties(new PropertyDescriptor[0]).Cast <PropertyDescriptor>().ToArray();

            dsvWriter.WriteHeaderRow(writer, properties);
            var rowCount     = rows.Count;
            int startPercent = status.PercentComplete;

            for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
            {
                if (progressMonitor.IsCanceled)
                {
                    return;
                }
                int percentComplete = startPercent + (rowIndex * (100 - startPercent) / rowCount);
                if (percentComplete > status.PercentComplete)
                {
                    status = status.ChangeMessage(string.Format(Resources.AbstractViewContext_WriteData_Writing_row__0___1_, (rowIndex + 1), rowCount))
                             .ChangePercentComplete(percentComplete);
                    progressMonitor.UpdateProgress(status);
                }
                dsvWriter.WriteDataRow(writer, rows[rowIndex], properties);
            }
        }
Beispiel #30
0
        private void UpdateViewContext()
        {
            RememberActiveView();
            IRowSource rowSource       = null;
            Type       rowType         = null;
            string     builtInViewName = null;

            if (_selectedIdentityPaths.Count == 1)
            {
                var identityPath = _selectedIdentityPaths[0];
                if (identityPath.Length == 2)
                {
                    rowSource       = new PeptideResultList(new Peptide(_dataSchema, identityPath));
                    rowType         = typeof(PeptideResult);
                    builtInViewName = "Peptide Results"; // Not L10N
                }
                else if (identityPath.Length == 3)
                {
                    rowSource       = new PrecursorResultList(new Precursor(_dataSchema, identityPath));
                    rowType         = typeof(PrecursorResult);
                    builtInViewName = "Precursor Results"; // Not L10N
                }
                else if (identityPath.Length == 4)
                {
                    rowSource       = new TransitionResultList(new Transition(_dataSchema, identityPath));
                    rowType         = typeof(TransitionResult);
                    builtInViewName = "Transition Results"; // Not L10N
                }
            }
            else
            {
                // ReSharper disable PossibleMultipleEnumeration
                var pathLengths = _selectedIdentityPaths.Select(path => path.Length).Distinct().ToArray();
                if (pathLengths.Length == 1)
                {
                    var pathLength = pathLengths[0];
                    if (pathLength == 3)
                    {
                        rowSource = new MultiPrecursorResultList(_dataSchema,
                                                                 _selectedIdentityPaths.Select(idPath => new Precursor(_dataSchema, idPath)));
                        rowType         = typeof(MultiPrecursorResult);
                        builtInViewName = "Multiple Precursor Results"; // Not L10N
                    }
                    if (pathLength == 4)
                    {
                        rowSource = new MultiTransitionResultList(_dataSchema,
                                                                  _selectedIdentityPaths.Select(idPath => new Transition(_dataSchema, idPath)));
                        rowType         = typeof(MultiTransitionResult);
                        builtInViewName = "Multiple Transition Results"; // Not L10N
                    }
                }
                // ReSharper restore PossibleMultipleEnumeration
            }
            if (rowSource == null)
            {
                rowSource       = new ReplicateList(_dataSchema);
                rowType         = typeof(Replicate);
                builtInViewName = "Replicates"; // Not L10N
            }
            var parentColumn    = ColumnDescriptor.RootColumn(_dataSchema, rowType);
            var builtInViewSpec = SkylineViewContext.GetDefaultViewInfo(parentColumn).GetViewSpec()
                                  .SetName(builtInViewName).SetRowType(rowType);

            if (null == BindingListSource.ViewContext ||
                !BindingListSource.ViewContext.GetViewSpecList(ViewGroup.BUILT_IN.Id).ViewSpecs.Contains(builtInViewSpec))
            {
                var oldViewContext = BindingListSource.ViewContext as ResultsGridViewContext;
                if (null != oldViewContext)
                {
                    oldViewContext.RememberColumnWidths(DataGridView);
                }
                Debug.Assert(null != builtInViewName);
                var builtInView   = new ViewInfo(parentColumn, builtInViewSpec).ChangeViewGroup(ViewGroup.BUILT_IN);
                var rowSourceInfo = new RowSourceInfo(rowSource, builtInView);
                var viewContext   = new ResultsGridViewContext(_dataSchema,
                                                               new[] { rowSourceInfo });
                ViewInfo activeView = null;
                string   activeViewName;
                if (Settings.Default.ResultsGridActiveViews.TryGetValue(rowSourceInfo.Name, out activeViewName))
                {
                    activeView = viewContext.GetViewInfo(ViewName.Parse(activeViewName));
                }
                activeView = activeView ?? builtInView;
                BindingListSource.SetViewContext(viewContext, activeView);
            }
            BindingListSource.RowSource = rowSource;
        }