Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/FileManager.cs @ 17987

Last change on this file since 17987 was 17828, checked in by dpiringe, 4 years ago

#3026

  • removed the option to set the value for JsonItems via exporter
    • reworked some base controls
    • added new controls for JsonItem specific properties (e.g. ArrayResizable)
    • deleted a lot of obsolet controls
  • removed the Enable checkbox in the detail view of JsonItems
  • exporter now clones the IOptimizer object
  • added a check + message for unsupported exports
  • list of JsonItems now includes unsupported JsonItems (disabled and marked with 'unsupported')
  • refactored the converter type check
    • now every converter has to specify its supported type(s)
File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7using System.Windows.Forms;
8using HeuristicLab.Common;
9using HeuristicLab.Core;
10using HeuristicLab.MainForm;
11using HeuristicLab.Optimization;
12using HeuristicLab.PluginInfrastructure;
13
14namespace HeuristicLab.JsonInterface.OptimizerIntegration {
15  internal static class FileManager {
16    private static OpenFileDialog openFileDialog;
17    private static ExportJsonDialog exportDialog = new ExportJsonDialog();
18
19    public static void ExportJsonTemplate() {
20      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
21      if (activeView != null) {
22        ExportJsonTemplate(activeView);
23      }
24    }
25    public static void ExportJsonTemplate(IContentView view) {
26      IStorableContent content = view.Content as IStorableContent;
27      if (!view.Locked && content != null) {
28        if(content is IOptimizer) {
29          exportDialog.Content = content;
30          exportDialog.ShowDialog();
31        } else {
32          MessageBox.Show("This cannot item cannot be converted.", "Unsupported Item", MessageBoxButtons.OK);
33        }
34      }
35    }
36
37
38    public static void ImportJsonTemplate() {
39      if (openFileDialog == null) {
40        openFileDialog = new OpenFileDialog();
41        openFileDialog.Title = "Import .json-Template";
42        openFileDialog.FileName = "Item";
43        openFileDialog.Multiselect = false;
44        openFileDialog.DefaultExt = "json";
45        openFileDialog.Filter = ".json-Template|*.json|All Files|*.*";
46      }
47
48      if (openFileDialog.ShowDialog() == DialogResult.OK) {
49        try {
50          var content = JsonTemplateInstantiator.Instantiate(openFileDialog.FileName);
51          IView view = MainFormManager.MainForm.ShowContent(content.Optimizer);
52          if (view == null)
53            ErrorHandling.ShowErrorDialog("There is no view for the loaded item. It cannot be displayed.", new InvalidOperationException("No View Available"));
54        } catch (Exception ex) {
55          ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, "Cannot open file.", ex);
56        } finally {
57          ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).ResetAppStartingCursor();
58        }
59      }
60    }
61  }
62}
Note: See TracBrowser for help on using the repository browser.