- Timestamp:
- 07/14/16 22:38:23 (8 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 13502,13504,13507-13508,13512,13514,13517
- Property svn:mergeinfo changed
-
stable/HeuristicLab.DataPreprocessing.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.DataPreprocessing.Views merged: 13502,13504,13507-13508,13512,13514,13517
- Property svn:mergeinfo changed
-
stable/HeuristicLab.DataPreprocessing.Views/3.4/DataPreprocessingView.cs
r12718 r14075 21 21 22 22 using System; 23 using System.IO; 24 using System.Threading.Tasks; 23 25 using System.Windows.Forms; 24 26 using HeuristicLab.Common; … … 26 28 using HeuristicLab.Core.Views; 27 29 using HeuristicLab.MainForm; 30 using HeuristicLab.Problems.DataAnalysis; 31 using HeuristicLab.Problems.Instances.DataAnalysis; 32 using HeuristicLab.Problems.Instances.DataAnalysis.Views; 28 33 29 34 namespace HeuristicLab.DataPreprocessing.Views { 30 35 [View("DataPreprocessing View")] 31 36 [Content(typeof(PreprocessingContext), true)] 32 [Content(typeof(IPreprocessingContext), false)] 33 public partial class DataPreprocessingView : ItemView { 37 public partial class DataPreprocessingView : NamedItemView { 34 38 35 39 public DataPreprocessingView() { … … 37 41 } 38 42 39 public new IPreprocessingContext Content {40 get { return ( IPreprocessingContext)base.Content; }43 public new PreprocessingContext Content { 44 get { return (PreprocessingContext)base.Content; } 41 45 set { base.Content = value; } 42 46 } … … 60 64 new CorrelationMatrixContent(Content), 61 65 new DataCompletenessChartContent(searchLogic), 62 66 63 67 new FilterContent(filterLogic), 64 68 new ManipulationContent(manipulationLogic, searchLogic, filterLogic), … … 67 71 68 72 viewShortcutListView.Content = viewShortcuts.AsReadOnly(); 69 70 73 viewShortcutListView.ItemsListView.Items[0].Selected = true; 71 74 viewShortcutListView.Select(); 72 75 76 applyTypeContextMenuStrip.Items.Clear(); 77 exportTypeContextMenuStrip.Items.Clear(); 78 foreach (var exportOption in Content.GetSourceExportOptions()) { 79 var applyMenuItem = new ToolStripMenuItem(exportOption.Key) { Tag = exportOption.Value }; 80 applyMenuItem.Click += applyToolStripMenuItem_Click; 81 applyTypeContextMenuStrip.Items.Add(applyMenuItem); 82 83 var exportMenuItem = new ToolStripMenuItem(exportOption.Key) { Tag = exportOption.Value }; 84 exportMenuItem.Click += exportToolStripMenuItem_Click; 85 exportTypeContextMenuStrip.Items.Add(exportMenuItem); 86 } 87 var exportCsvMenuItem = new ToolStripMenuItem(".csv"); 88 exportCsvMenuItem.Click += exportCsvMenuItem_Click; 89 exportTypeContextMenuStrip.Items.Add(exportCsvMenuItem); 73 90 } else { 74 91 viewShortcutListView.Content = null; 75 92 } 76 93 } 77 78 94 protected override void RegisterContentEvents() { 79 95 base.RegisterContentEvents(); 96 Content.Reset += Content_Reset; 80 97 Content.Data.FilterChanged += Data_FilterChanged; 81 98 } … … 83 100 protected override void DeregisterContentEvents() { 84 101 base.DeregisterContentEvents(); 102 Content.Reset -= Content_Reset; 85 103 Content.Data.FilterChanged -= Data_FilterChanged; 104 } 105 106 void Content_Reset(object sender, EventArgs e) { 107 OnContentChanged(); // Reset by setting new content 86 108 } 87 109 … … 94 116 viewShortcutListView.Enabled = Content != null; 95 117 applyInNewTabButton.Enabled = Content != null; 96 exportProblemButton.Enabled = Content != null && Content. Problem != null;118 exportProblemButton.Enabled = Content != null && Content.CanExport; 97 119 undoButton.Enabled = Content != null; 98 120 } 99 121 122 #region New 123 private void newButton_Click(object sender, EventArgs e) { 124 newProblemDataTypeContextMenuStrip.Show(Cursor.Position); 125 } 126 private void newRegressionToolStripMenuItem_Click(object sender, EventArgs e) { 127 Content.Import(new RegressionProblemData()); 128 } 129 private void newClassificationToolStripMenuItem_Click(object sender, EventArgs e) { 130 Content.Import(new ClassificationProblemData()); 131 } 132 private void newTimeSeriesToolStripMenuItem_Click(object sender, EventArgs e) { 133 Content.Import(new TimeSeriesPrognosisProblemData()); 134 } 135 #endregion 136 137 #region Import 138 private void importButton_Click(object sender, EventArgs e) { 139 importProblemDataTypeContextMenuStrip.Show(Cursor.Position); 140 } 141 private void importRegressionToolStripMenuItem_Click(object sender, EventArgs e) { 142 Import(new RegressionCSVInstanceProvider(), new RegressionImportTypeDialog(), 143 (dialog => ((RegressionImportTypeDialog)dialog).ImportType)); 144 } 145 private void importClassificationToolStripMenuItem_Click(object sender, EventArgs e) { 146 Import(new ClassificationCSVInstanceProvider(), new ClassificationImportTypeDialog(), 147 (dialog => ((ClassificationImportTypeDialog)dialog).ImportType)); 148 } 149 private void importTimeSeriesToolStripMenuItem_Click(object sender, EventArgs e) { 150 Import(new TimeSeriesPrognosisCSVInstanceProvider(), new TimeSeriesPrognosisImportTypeDialog(), 151 (dialog => ((TimeSeriesPrognosisImportTypeDialog)dialog).ImportType)); 152 } 153 private void Import<TProblemData, TImportType>(DataAnalysisInstanceProvider<TProblemData, TImportType> instanceProvider, DataAnalysisImportTypeDialog importTypeDialog, 154 Func<DataAnalysisImportTypeDialog, TImportType> getImportType) 155 where TProblemData : class, IDataAnalysisProblemData 156 where TImportType : DataAnalysisImportType { 157 if (importTypeDialog.ShowDialog() == DialogResult.OK) { 158 Task.Run(() => { 159 TProblemData instance; 160 var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm; 161 // lock active view and show progress bar 162 var activeView = (IContentView)MainFormManager.MainForm.ActiveView; 163 164 try { 165 var progress = mainForm.AddOperationProgressToContent(activeView.Content, "Loading problem instance."); 166 167 instanceProvider.ProgressChanged += (o, args) => { progress.ProgressValue = args.ProgressPercentage / 100.0; }; 168 169 instance = instanceProvider.ImportData(importTypeDialog.Path, getImportType(importTypeDialog), importTypeDialog.CSVFormat); 170 } catch (IOException ex) { 171 MessageBox.Show(string.Format("There was an error parsing the file: {0}", Environment.NewLine + ex.Message), "Error while parsing", MessageBoxButtons.OK, MessageBoxIcon.Error); 172 mainForm.RemoveOperationProgressFromContent(activeView.Content); 173 return; 174 } 175 try { 176 Content.Import(instance); 177 } catch (IOException ex) { 178 MessageBox.Show(string.Format("This problem does not support loading the instance {0}: {1}", Path.GetFileName(importTypeDialog.Path), Environment.NewLine + ex.Message), "Cannot load instance"); 179 } finally { 180 mainForm.RemoveOperationProgressFromContent(activeView.Content); 181 } 182 }); 183 } 184 } 185 #endregion 186 187 #region Apply 188 private void applyInNewTabButton_Click(object sender, EventArgs e) { 189 applyTypeContextMenuStrip.Show(Cursor.Position); 190 } 191 private void applyToolStripMenuItem_Click(object sender, EventArgs e) { 192 var menuItem = (ToolStripMenuItem)sender; 193 var itemCreator = (Func<IItem>)menuItem.Tag; 194 MainFormManager.MainForm.ShowContent(itemCreator()); 195 } 196 #endregion 197 198 #region Export 100 199 private void exportProblemButton_Click(object sender, EventArgs e) { 101 var problem = Content.ExportProblem(); 102 200 exportTypeContextMenuStrip.Show(Cursor.Position); 201 } 202 private void exportToolStripMenuItem_Click(object sender, EventArgs e) { 203 var menuItem = (ToolStripMenuItem)sender; 204 var itemCreator = (Func<IItem>)menuItem.Tag; 103 205 var saveFileDialog = new SaveFileDialog { 104 206 Title = "Save Item", … … 108 210 }; 109 211 110 var content = problem as IStorableContent;111 212 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 112 bool compressed = saveFileDialog.FilterIndex != 1; 113 ContentManager.Save(content, saveFileDialog.FileName, compressed); 114 } 115 } 116 117 private void applyInNewTabButton_Click(object sender, EventArgs e) { 118 var item = Content.Export(); 119 120 MainFormManager.MainForm.ShowContent(item); 121 } 122 213 Task.Run(() => { 214 bool compressed = saveFileDialog.FilterIndex != 1; 215 var storable = itemCreator() as IStorableContent; 216 if (storable != null) { 217 var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm; 218 var activeView = (IContentView)MainFormManager.MainForm.ActiveView; 219 try { 220 mainForm.AddOperationProgressToContent(activeView.Content, "Exporting data."); 221 ContentManager.Save(storable, saveFileDialog.FileName, compressed); 222 } finally { 223 mainForm.RemoveOperationProgressFromContent(activeView.Content); 224 } 225 } 226 }); 227 } 228 } 229 private void exportCsvMenuItem_Click(object sender, EventArgs e) { 230 var saveFileDialog = new SaveFileDialog { 231 Title = "Save Data", 232 DefaultExt = "csv", 233 Filter = "CSV files|*.csv|All files|*.*", 234 FilterIndex = 1 235 }; 236 237 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 238 Task.Run(() => { 239 var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm; 240 var activeView = (IContentView)MainFormManager.MainForm.ActiveView; 241 try { 242 var problemData = Content.CreateNewProblemData(); 243 mainForm.AddOperationProgressToContent(activeView.Content, "Exporting data."); 244 if (problemData is TimeSeriesPrognosisProblemData) 245 Export(new TimeSeriesPrognosisCSVInstanceProvider(), problemData, saveFileDialog.FileName); 246 else if (problemData is RegressionProblemData) 247 Export(new RegressionCSVInstanceProvider(), problemData, saveFileDialog.FileName); 248 else if (problemData is ClassificationProblemData) 249 Export(new ClassificationCSVInstanceProvider(), problemData, saveFileDialog.FileName); 250 } finally { 251 mainForm.RemoveOperationProgressFromContent(activeView.Content); 252 } 253 }); 254 } 255 } 256 private void Export<TProblemData, TImportType>(DataAnalysisInstanceProvider<TProblemData, TImportType> instanceProvider, 257 IDataAnalysisProblemData problemData, string path) 258 where TProblemData : class, IDataAnalysisProblemData where TImportType : DataAnalysisImportType { 259 instanceProvider.ExportData((TProblemData)problemData, path); 260 } 261 #endregion 262 263 #region Undo / Redo 123 264 private void undoButton_Click(object sender, EventArgs e) { 124 265 Content.Data.Undo(); 125 266 } 267 #endregion 126 268 } 127 269 }
Note: See TracChangeset
for help on using the changeset viewer.