Free cookie consent management tool by TermsFeed Policy Generator

source: branches/SimulationCore/HeuristicLab.SimulationCore.Dsl/Dsl/GeneratedCode/ToolboxHelper.cs @ 10995

Last change on this file since 10995 was 10525, checked in by abeham, 11 years ago

#1610: added visual model

File size: 15.3 KB
Line 
1//------------------------------------------------------------------------------
2// <auto-generated>
3//     This code was generated by a tool.
4//
5//     Changes to this file may cause incorrect behavior and will be lost if
6//     the code is regenerated.
7// </auto-generated>
8//------------------------------------------------------------------------------
9
10using DslModeling = global::Microsoft.VisualStudio.Modeling;
11using DslDesign = global::Microsoft.VisualStudio.Modeling.Design;
12using System;
13using System.Diagnostics;
14using System.Drawing.Design;
15using System.Windows.Forms;
16using DslDiagrams = global::Microsoft.VisualStudio.Modeling.Diagrams;
17
18namespace HeuristicLab.SimulationCore
19{
20  /// <summary>
21  /// Helper class used to create and initialize toolbox items for this DSL.
22  /// </summary>
23  /// <remarks>
24  /// Double-derived class to allow easier code customization.
25  /// </remarks>
26  public partial class HLSimToolboxHelper : HLSimToolboxHelperBase
27  {
28    /// <summary>
29    /// Constructs a new HLSimToolboxHelper.
30    /// </summary>
31    public HLSimToolboxHelper(global::System.IServiceProvider serviceProvider)
32      : base(serviceProvider) { }
33  }
34 
35  /// <summary>
36  /// Helper class used to create and initialize toolbox items for this DSL.
37  /// </summary>
38 
39  [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Justification = "The store is disposed on domain shut down")]
40  public abstract class HLSimToolboxHelperBase
41  {
42    /// <summary>
43    /// Toolbox item filter string used to identify HLSim toolbox items. 
44    /// </summary>
45    /// <remarks>
46    /// See the MSDN documentation for the ToolboxItemFilterAttribute class for more information on toolbox
47    /// item filters.
48    /// </remarks>
49    public const string ToolboxFilterString = "HLSim.1.0";
50    /// <summary>
51    /// Toolbox item filter string used to identify Trigger connector tool.
52    /// </summary>
53    public const string TriggerFilterString = "Trigger.1.0";
54    /// <summary>
55    /// Toolbox item filter string used to identify Listener connector tool.
56    /// </summary>
57    public const string ListenerFilterString = "Listener.1.0";
58
59 
60    private global::System.Collections.Generic.Dictionary<string, DslDesign::ModelingToolboxItem> toolboxItemCache = new global::System.Collections.Generic.Dictionary<string, DslDesign::ModelingToolboxItem>();
61    private DslModeling::Store toolboxStore;
62   
63    private global::System.IServiceProvider sp;
64   
65    /// <summary>
66    /// Constructs a new HLSimToolboxHelperBase.
67    /// </summary>
68    protected HLSimToolboxHelperBase(global::System.IServiceProvider serviceProvider)
69    {
70      if(serviceProvider == null) throw new global::System.ArgumentNullException("serviceProvider");
71     
72      this.sp = serviceProvider;
73    }
74   
75    /// <summary>
76    /// Serivce provider used to access services from the hosting environment.
77    /// </summary>
78    protected global::System.IServiceProvider ServiceProvider
79    {
80      get
81      {
82        return this.sp;
83      }
84    }
85
86    /// <summary>
87    /// Returns the display name of the tab that should be opened by default when the editor is opened.
88    /// </summary>
89    public static string DefaultToolboxTabName
90    {
91      get
92      {
93        return global::HeuristicLab.SimulationCore.HLSimDomainModel.SingletonResourceManager.GetString("HLSimToolboxTab", global::System.Globalization.CultureInfo.CurrentUICulture);
94      }
95    }
96   
97   
98    /// <summary>
99    /// Returns the toolbox items count in the default tool box tab.
100    /// </summary>
101    public static int DefaultToolboxTabToolboxItemsCount
102    {
103      get
104      {
105        return 4;
106      }
107    }
108   
109
110    /// <summary>
111    /// Returns a list of custom toolbox items to be added dynamically
112    /// </summary>
113    public virtual global::System.Collections.Generic.IList<DslDesign::ModelingToolboxItem> CreateToolboxItems()
114    {
115      global::System.Collections.Generic.List<DslDesign::ModelingToolboxItem> toolboxItems = new global::System.Collections.Generic.List<DslDesign::ModelingToolboxItem>();
116      return toolboxItems;
117    }
118   
119    /// <summary>
120    /// Creates an ElementGroupPrototype for the element tool corresponding to the given domain class id.
121    /// Default behavior is to create a prototype containing an instance of the domain class.
122    /// Derived classes may override this to add additional information to the prototype.
123    /// </summary>
124    protected virtual DslModeling::ElementGroupPrototype CreateElementToolPrototype(DslModeling::Store store, global::System.Guid domainClassId)
125    {
126      DslModeling::ModelElement element = store.ElementFactory.CreateElement(domainClassId);
127      DslModeling::ElementGroup elementGroup = new DslModeling::ElementGroup(store.DefaultPartition);
128      elementGroup.AddGraph(element, true);
129      return elementGroup.CreatePrototype();
130    }
131
132    /// <summary>
133    /// Returns instance of ModelingToolboxItem based on specified name.
134    /// This method must be called from within a Transaction. Failure to do so will result in an exception
135    /// </summary>
136    /// <param name="itemId">unique name of desired ToolboxItem</param>
137    /// <param name="store">Store to perform the operation against</param>
138    /// <returns>An instance of ModelingToolboxItem if the itemId can be resolved, null otherwise</returns>
139    public virtual DslDesign::ModelingToolboxItem GetToolboxItem(string itemId, DslModeling::Store store)
140    {
141      DslDesign::ModelingToolboxItem result = null;
142      if (string.IsNullOrEmpty(itemId))
143      {
144        return null;
145      }
146      if (store == null)
147      {
148        return null;
149      }
150      global::System.Resources.ResourceManager resourceManager = global::HeuristicLab.SimulationCore.HLSimDomainModel.SingletonResourceManager;
151      global::System.Globalization.CultureInfo resourceCulture = global::System.Globalization.CultureInfo.CurrentUICulture;
152      switch(itemId)
153      {
154        case "HeuristicLab.SimulationCore.ActivityToolboxItem":
155          // Add Activity shape tool.
156          result = new DslDesign::ModelingToolboxItem(
157            "HeuristicLab.SimulationCore.ActivityToolboxItem", // Unique identifier (non-localized) for the toolbox item.
158            1, // Position relative to other items in the same toolbox tab.
159            resourceManager.GetString("ActivityToolboxItem", resourceCulture), // Localized display name for the item.
160            (global::System.Drawing.Bitmap)DslDiagrams::ImageHelper.GetImage(resourceManager.GetObject("ActivityToolboxBitmap", resourceCulture)), // Image displayed next to the toolbox item.
161            "HeuristicLab.SimulationCore.HLSimToolboxTab", // Unique identifier (non-localized) for the toolbox item tab.
162            resourceManager.GetString("HLSimToolboxTab", resourceCulture), // Localized display name for the toolbox tab.
163            "Activity", // F1 help keyword for the toolbox item.
164            resourceManager.GetString("ActivityToolboxTooltip", resourceCulture), // Localized tooltip text for the toolbox item.
165            CreateElementToolPrototype(store, global::HeuristicLab.SimulationCore.Activity.DomainClassId), // ElementGroupPrototype (data object) representing model element on the toolbox.
166            new global::System.ComponentModel.ToolboxItemFilterAttribute[] { // Collection of ToolboxItemFilterAttribute objects that determine visibility of the toolbox item.
167            new global::System.ComponentModel.ToolboxItemFilterAttribute(ToolboxFilterString, global::System.ComponentModel.ToolboxItemFilterType.Require)
168            });
169          break;
170        case "HeuristicLab.SimulationCore.ActionToolboxItem":
171          // Add Action shape tool.
172          result = new DslDesign::ModelingToolboxItem(
173            "HeuristicLab.SimulationCore.ActionToolboxItem", // Unique identifier (non-localized) for the toolbox item.
174            2, // Position relative to other items in the same toolbox tab.
175            resourceManager.GetString("ActionToolboxItem", resourceCulture), // Localized display name for the item.
176            (global::System.Drawing.Bitmap)DslDiagrams::ImageHelper.GetImage(resourceManager.GetObject("ActionToolboxBitmap", resourceCulture)), // Image displayed next to the toolbox item.
177            "HeuristicLab.SimulationCore.HLSimToolboxTab", // Unique identifier (non-localized) for the toolbox item tab.
178            resourceManager.GetString("HLSimToolboxTab", resourceCulture), // Localized display name for the toolbox tab.
179            "Action", // F1 help keyword for the toolbox item.
180            resourceManager.GetString("ActionToolboxTooltip", resourceCulture), // Localized tooltip text for the toolbox item.
181            CreateElementToolPrototype(store, global::HeuristicLab.SimulationCore.Action.DomainClassId), // ElementGroupPrototype (data object) representing model element on the toolbox.
182            new global::System.ComponentModel.ToolboxItemFilterAttribute[] { // Collection of ToolboxItemFilterAttribute objects that determine visibility of the toolbox item.
183            new global::System.ComponentModel.ToolboxItemFilterAttribute(ToolboxFilterString, global::System.ComponentModel.ToolboxItemFilterType.Require)
184            });
185          break;
186        case "HeuristicLab.SimulationCore.TriggerToolboxItem":
187
188          // Add Trigger connector tool.
189          result = new DslDesign::ModelingToolboxItem(
190            "HeuristicLab.SimulationCore.TriggerToolboxItem", // Unique identifier (non-localized) for the toolbox item.
191            3, // Position relative to other items in the same toolbox tab.
192            resourceManager.GetString("TriggerToolboxItem", resourceCulture), // Localized display name for the item.
193            (global::System.Drawing.Bitmap)DslDiagrams::ImageHelper.GetImage(resourceManager.GetObject("TriggerToolboxBitmap", resourceCulture)), // Image displayed next to the toolbox item.       
194            "HeuristicLab.SimulationCore.HLSimToolboxTab", // Unique identifier (non-localized) for the toolbox item tab.
195            resourceManager.GetString("HLSimToolboxTab", resourceCulture), // Localized display name for the toolbox tab.
196            "Trigger", // F1 help keyword for the toolbox item.
197            resourceManager.GetString("TriggerToolboxTooltip", resourceCulture), // Localized tooltip text for the toolbox item.
198            null, // Connector toolbox items do not have an underlying data object.
199            new global::System.ComponentModel.ToolboxItemFilterAttribute[] { // Collection of ToolboxItemFilterAttribute objects that determine visibility of the toolbox item.
200              new global::System.ComponentModel.ToolboxItemFilterAttribute(ToolboxFilterString, global::System.ComponentModel.ToolboxItemFilterType.Require),
201              new global::System.ComponentModel.ToolboxItemFilterAttribute(TriggerFilterString)
202            });
203          break;
204        case "HeuristicLab.SimulationCore.ListenerToolboxItem":
205
206          // Add Listener connector tool.
207          result = new DslDesign::ModelingToolboxItem(
208            "HeuristicLab.SimulationCore.ListenerToolboxItem", // Unique identifier (non-localized) for the toolbox item.
209            4, // Position relative to other items in the same toolbox tab.
210            resourceManager.GetString("ListenerToolboxItem", resourceCulture), // Localized display name for the item.
211            (global::System.Drawing.Bitmap)DslDiagrams::ImageHelper.GetImage(resourceManager.GetObject("ListenerToolboxBitmap", resourceCulture)), // Image displayed next to the toolbox item.       
212            "HeuristicLab.SimulationCore.HLSimToolboxTab", // Unique identifier (non-localized) for the toolbox item tab.
213            resourceManager.GetString("HLSimToolboxTab", resourceCulture), // Localized display name for the toolbox tab.
214            "Listener", // F1 help keyword for the toolbox item.
215            resourceManager.GetString("ListenerToolboxTooltip", resourceCulture), // Localized tooltip text for the toolbox item.
216            null, // Connector toolbox items do not have an underlying data object.
217            new global::System.ComponentModel.ToolboxItemFilterAttribute[] { // Collection of ToolboxItemFilterAttribute objects that determine visibility of the toolbox item.
218              new global::System.ComponentModel.ToolboxItemFilterAttribute(ToolboxFilterString, global::System.ComponentModel.ToolboxItemFilterType.Require),
219              new global::System.ComponentModel.ToolboxItemFilterAttribute(ListenerFilterString)
220            });
221          break;
222        default:
223          break;
224      } // end switch
225     
226      return result;
227    }
228   
229
230    /// <summary>
231    /// The store toe be used for all the toolbox item creation
232    /// </summary>
233    protected DslModeling::Store ToolboxStore
234    {
235      get
236      {
237        if (toolboxStore==null)
238        {
239          toolboxStore = new DslModeling::Store(this.ServiceProvider);
240          EventHandler StoreCleanUp = (o, e) =>
241          {
242            //Since Store implements IDisposable, we need to dispose it when we're finished
243            if (this.toolboxStore != null)
244            {
245              this.toolboxStore.Dispose();
246            }
247            this.toolboxStore = null;
248          };
249          //There is no DomainUnload event for the default AppDomain, so we listen for both ProcessExit and DomainUnload
250          AppDomain.CurrentDomain.ProcessExit += new EventHandler(StoreCleanUp);
251          AppDomain.CurrentDomain.DomainUnload += new EventHandler(StoreCleanUp);
252         
253          //load the domain model
254          toolboxStore.LoadDomainModels(typeof(global::HeuristicLab.SimulationCore.HLSimDomainModel));
255         
256        }
257        return toolboxStore;
258      }
259    }
260   
261    /// <summary>
262    /// Given a toolbox item "unique ID" returns the the toolbox item using cached dictionary
263    /// </summary>
264    /// <param name="itemId">The unique ToolboxItem to retrieve</param>
265    private DslDesign::ModelingToolboxItem GetToolboxItem(string itemId)
266    {
267      DslDesign::ModelingToolboxItem item = null;
268
269      if (!this.toolboxItemCache.TryGetValue(itemId, out item))
270      {
271        DslModeling::Store store = this.ToolboxStore;
272       
273        // Open transaction so we can create model elements corresponding to toolbox items.
274        using (DslModeling::Transaction t = store.TransactionManager.BeginTransaction("CreateToolboxItems"))
275        {
276          // Retrieve the specified ToolboxItem from the DSL
277          this.toolboxItemCache[itemId] = item = this.GetToolboxItem(itemId, store);
278        }
279      }
280
281      return item;
282    }
283   
284    /// <summary>
285    /// Given a toolbox item "unique ID" and a data format identifier, returns the content of
286    /// the data format.
287    /// </summary>
288    /// <param name="itemId">The unique ToolboxItem to retrieve data for</param>
289    /// <param name="format">The desired format of the resulting data</param>
290    public virtual object GetToolboxItemData(string itemId, DataFormats.Format format)
291    {
292      DslDesign::ModelingToolboxItem item = null;
293
294      global::System.Resources.ResourceManager resourceManager = global::HeuristicLab.SimulationCore.HLSimDomainModel.SingletonResourceManager;
295      global::System.Globalization.CultureInfo resourceCulture = global::System.Globalization.CultureInfo.CurrentUICulture;
296
297      System.Windows.Forms.IDataObject tbxDataObj;
298
299      //get the toolbox item
300      item = GetToolboxItem(itemId);
301
302      if (item != null)
303      {
304        ToolboxItemContainer container = new ToolboxItemContainer(item);
305        tbxDataObj = container.ToolboxData;
306
307        if (tbxDataObj.GetDataPresent(format.Name))
308        {
309          return tbxDataObj.GetData(format.Name);
310        }
311        else
312        {
313          string invalidFormatString = resourceManager.GetString("UnsupportedToolboxFormat", resourceCulture);
314          throw new InvalidOperationException(string.Format(resourceCulture, invalidFormatString, format.Name));
315        }
316      }
317
318      string errorFormatString = resourceManager.GetString("UnresolvedToolboxItem", resourceCulture);
319      throw new InvalidOperationException(string.Format(resourceCulture, errorFormatString, itemId));
320    }   
321  }
322}
Note: See TracBrowser for help on using the repository browser.