public static void CreateHistogram(WorksheetController ctrl) { var table = Altaxo.Analysis.Statistics.Histograms.HistogramCreation.CreateHistogramOnColumns(ctrl.DataTable, ctrl.SelectedDataColumns, ctrl.SelectedDataRows, Gui.UserInteractionLevel.InteractAlways); if (null != table && !Current.Project.DataTableCollection.Contains(table)) { Current.Project.DataTableCollection.Add(table); // create a new worksheet without any columns Current.ProjectService.CreateNewWorksheet(table); } }
/// <summary> /// Shows the data source editor dialog. After sucessful execution of the dialog, the modified data source is stored back in the <see cref="DataTable"/>, and the data source is requeried. /// </summary> /// <param name="ctrl">The controller that controls the data table.</param> public static void ShowDataSourceEditor(WorksheetController ctrl) { var table = ctrl.DataTable; if (null == table || null == table.DataSource) return; bool sourceIsChanged = false; var originalDataSource = table.DataSource; var dataSource = (Data.IAltaxoTableDataSource)table.DataSource.Clone(); var dataSourceController = (Altaxo.Gui.IMVCANController)Current.Gui.GetControllerAndControl(new object[] { dataSource }, typeof(Altaxo.Gui.IMVCANController), Gui.UseDocument.Directly); if (null == dataSourceController) { Current.Gui.ErrorMessageBox(string.Format("Sorry. There is no dialog available to edit the data source of type {0}", dataSource.GetType()), "No dialog available"); return; } var controllerAsSupportApplyCallback = dataSourceController as Altaxo.Gui.IMVCSupportsApplyCallback; if (null != controllerAsSupportApplyCallback) { controllerAsSupportApplyCallback.SuccessfullyApplied += () => { sourceIsChanged = true; table.DataSource = dataSource; RequeryTableDataSource(ctrl); }; } var result = Current.Gui.ShowDialog(dataSourceController, "Edit data source " + dataSource.GetType().ToString(), true); if (result == false) // user has cancelled the dialog { if (sourceIsChanged) // if source is changed, revert it { table.DataSource = originalDataSource; RequeryTableDataSource(ctrl); } return; } if (!sourceIsChanged) // controller might have forgotten to implement the SuccessfullyApplied event - thus we have to apply here { table.DataSource = dataSource; RequeryTableDataSource(ctrl); } }
/// <summary> /// Requeries the table data source. /// </summary> /// <param name="ctrl">The controller that controls the data table.</param> public static void RequeryTableDataSource(WorksheetController ctrl) { var table = ctrl.DataTable; if (null == table || null == table.DataSource) return; using (var suspendToken = table.SuspendGetToken()) { try { table.DataSource.FillData(table); } catch (Exception ex) { table.Notes.WriteLine("Error during requerying the table data source: {0}", ex.Message); } if (!(null != table.DataSource)) throw new InvalidProgramException("table.DataSource.FillData should never set the data source to zero!"); if (table.DataSource.ImportOptions.ExecuteTableScriptAfterImport && null != table.TableScript) { try { table.TableScript.Execute(table, new Altaxo.Main.Services.DummyBackgroundMonitor(), false); } catch (Exception ex) { table.Notes.WriteLine("Error during execution of the table script (after requerying the table data source: {0}", ex.Message); } } suspendToken.Resume(); } }