/// <summary> /// Retrieves the ToolboxItem used by this Modeling based editor. /// This is where you add complex toolbox items that are not simply /// fragments of diagram to be added. /// </summary> public override ModelingToolboxItem[] GetToolboxItems() { // Put all the base items in the list and then add the connector tools List <ModelingToolboxItem> items = new List <ModelingToolboxItem>(); // Get the base list of toolbox items ModelingToolboxItem[] baseItems = base.GetToolboxItems(); foreach (ModelingToolboxItem baseItem in baseItems) { items.Add(baseItem); } // Create an entry for the SchemaModelItemHasSchemaModelItemConnector tool { ModelingToolboxItem item = new ModelingToolboxItem( "SchemaModelItemHasSchemaModelItemConnectorToolBoxItemId", // Id EditorFactory.SchemaModelItemHasSchemaModelItemConnectorPosition, // Position EditorFactory.GetResource("ActivityHasArtifactConnectorToolboxCaption", true) as string, // Caption EditorFactory.GetResource("connector") as System.Drawing.Bitmap, // Bitmap Designer_Resource.ToolboxTab + "Id", Designer_Resource.ToolboxTab, "ExampleConnectorHelpId", // f1Keyword null, // Tooltip null, // ElementGroupPrototype new ToolboxItemFilterAttribute[] { new ToolboxItemFilterAttribute(SFSchemaLanguageDiagram.DiagramFilterString, ToolboxItemFilterType.Require), new ToolboxItemFilterAttribute(EditorFactory.SchemaModelItemHasSchemaModelItemConnectorFilterString, ToolboxItemFilterType.Allow) }); items.Add(item); } // Return the augmented list return(items.ToArray()); }
/// <summary> /// Create a list of <see cref="ModelingToolboxItem"/>s from a <see cref="IServiceProvider"/> /// </summary> /// <param name="serviceProvider">The context <see cref="IServiceProvider"/></param> /// <param name="domainModelType">The type of the <see cref="DomainModel"/> associated with this attribute</param> /// <returns>List of <see cref="ModelingToolboxItem"/> elements.</returns> public IList <ModelingToolboxItem> CreateToolboxItems(IServiceProvider serviceProvider, Type domainModelType) { Type createType = myToolboxItemProviderType; if (createType == null) { string[] nestedTypeNames = myNestedToolboxInitializerName.Split(new char[] { '.', '+' }, StringSplitOptions.RemoveEmptyEntries); createType = domainModelType; for (int i = 0; i < nestedTypeNames.Length; ++i) { createType = createType.GetNestedType(nestedTypeNames[i], BindingFlags.NonPublic | BindingFlags.Public); } } if (createType != null) { IModelingToolboxItemProvider initializer = (IModelingToolboxItemProvider)Activator.CreateInstance(createType, true); IList <ModelingToolboxItem> items = initializer.CreateToolboxItems(serviceProvider); int itemCount; if (items != null && 0 != (itemCount = items.Count)) { int offsetAdjustment = initializer.ToolboxItemPositionOffset; if (offsetAdjustment != 0) { for (int i = 0; i < itemCount; ++i) { ModelingToolboxItem item = items[i]; items[i] = new ModelingToolboxItem(item.Id, item.Position + offsetAdjustment, item.DisplayName, item.Bitmap, item.TabNameId, item.TabName, item.ContextSensitiveHelpKeyword, item.Description, item.Prototype, item.Filter); } } return(items); } } return(null); }
private ModelingToolboxItem CreateToolboxItem(Store store, GadgeteerPart moduleDefinition, string description, string tabName, ElementGroupPrototype prototype, string itemId) { //Add a filter attribute for each of the .NETMF versions supported by this module. The DocData adds a corresponding //filter depending on the version of the project var filters = moduleDefinition.SupportedMicroframeworkVersions.Select(v => new ToolboxItemFilterAttribute(GadgeteerDSLToolboxHelperBase.ToolboxFilterString + v, ToolboxItemFilterType.Require)).ToArray(); var result = new ModelingToolboxItem( itemId, // Unique identifier (non-localized) for the toolbox item. 2, // Position relative to other items in the same toolbox tab. moduleDefinition.Name, moduleToolboxIcon, // Image displayed next to the toolbox item. "Microsoft.Gadgeteer.Designer.GadgeteerDSLToolboxTab", // Unique identifier (non-localized) for the toolbox item tab. tabName, // Localized display name for the toolbox tab. moduleDefinition.Name, // F1 help keyword for the toolbox item. description, // Localized tooltip text for the toolbox item. prototype, filters ); //Imporant to make this transient. Otherwise the toolbox items remain even if modules are uninstalled result.IsTransient = true; return(result); }
/// <summary> /// Create a serialized prototype for Activity to attach to the toolbox. /// </summary> /// <param name="toolboxItem"></param> /// <returns>The prototype</returns> public override ElementGroupPrototype InitializeToolboxItem(ModelingToolboxItem toolboxItem) { ElementGroup elementGroup = new ElementGroup(this.Store); ElementGroupPrototype proto = null; Debug.Assert(this.Store.TransactionManager.InTransaction, "Must be in transaction"); ISpySoft.SFSchemaLanguage.DomainModel.Activity instance = ISpySoft.SFSchemaLanguage.DomainModel.Activity.CreateActivity(this.Store); if (instance != null) { elementGroup.AddGraph(instance); proto = elementGroup.CreatePrototype(instance); } return(proto); }
/// <summary> /// Add a filter to the specified <see cref="ModelingToolboxItem"/> /// </summary> /// <param name="items">A list of existing items</param> /// <param name="itemIndexDictionary">A dictionary mapping from the item identifier to an index in the /// <paramref name="items"/> list. The dictionary should be created with <see cref="CreateIdentifierToIndexMap"/></param> /// <param name="itemId">The identifer of the item to modify</param> /// <param name="filterAttribute">The filter attribute to add</param> public static void AddFilterAttribute(IList <ModelingToolboxItem> items, IDictionary <string, int> itemIndexDictionary, string itemId, ToolboxItemFilterAttribute filterAttribute) { int itemIndex; if (itemIndexDictionary.TryGetValue(itemId, out itemIndex)) { ModelingToolboxItem itemBase = items[itemIndex]; ICollection baseFilters = itemBase.Filter; int baseFilterCount = (baseFilters != null) ? baseFilters.Count : 0; ToolboxItemFilterAttribute[] newFilters = new ToolboxItemFilterAttribute[baseFilterCount + 1]; if (baseFilterCount != 0) { baseFilters.CopyTo(newFilters, 0); } newFilters[baseFilterCount] = filterAttribute; itemBase.Filter = newFilters; } }
/// <summary> /// Remove a filter from the specified <see cref="ModelingToolboxItem"/> /// </summary> /// <param name="items">A list of existing items</param> /// <param name="itemIndexDictionary">A dictionary mapping from the item identifier to an index in the /// <paramref name="items"/> list. The dictionary should be created with <see cref="CreateIdentifierToIndexMap"/></param> /// <param name="itemId">The identifer of the item to modify</param> /// <param name="filterString">The filter string for the filter to remove</param> public static void RemoveFilterAttribute(IList <ModelingToolboxItem> items, IDictionary <string, int> itemIndexDictionary, string itemId, string filterString) { int itemIndex; if (itemIndexDictionary.TryGetValue(itemId, out itemIndex)) { ModelingToolboxItem itemBase = items[itemIndex]; ICollection baseFilters = itemBase.Filter; int baseFilterCount = baseFilters.Count; if (baseFilterCount != 0) { int removeCount = 0; foreach (object filter in baseFilters) { ToolboxItemFilterAttribute filterAttribute = filter as ToolboxItemFilterAttribute; if (filterAttribute == null || filterAttribute.FilterString == filterString) { ++removeCount; } } if (removeCount == baseFilterCount) { itemBase.Filter = null; } else { ToolboxItemFilterAttribute[] newFilters = new ToolboxItemFilterAttribute[baseFilterCount - removeCount]; int nextIndex = 0; foreach (object filter in baseFilters) { ToolboxItemFilterAttribute filterAttribute = filter as ToolboxItemFilterAttribute; if (filterAttribute != null && filterAttribute.FilterString != filterString) { newFilters[nextIndex] = filterAttribute; ++nextIndex; } } itemBase.Filter = newFilters; } } } }
/// <summary> /// Create a list of <see cref="ModelingToolboxItem"/>s from a <see cref="IServiceProvider"/> /// </summary> /// <param name="serviceProvider">The context <see cref="IServiceProvider"/></param> /// <param name="domainModelType">The type of the <see cref="DomainModel"/> associated with this attribute</param> /// <returns>List of <see cref="ModelingToolboxItem"/> elements.</returns> public IList<ModelingToolboxItem> CreateToolboxItems(IServiceProvider serviceProvider, Type domainModelType) { Type createType = myToolboxItemProviderType; if (createType == null) { string[] nestedTypeNames = myNestedToolboxInitializerName.Split(new char[] { '.', '+' }, StringSplitOptions.RemoveEmptyEntries); createType = domainModelType; for (int i = 0; i < nestedTypeNames.Length; ++i) { createType = createType.GetNestedType(nestedTypeNames[i], BindingFlags.NonPublic | BindingFlags.Public); } } if (createType != null) { IModelingToolboxItemProvider initializer = (IModelingToolboxItemProvider)Activator.CreateInstance(createType, true); IList<ModelingToolboxItem> items = initializer.CreateToolboxItems(serviceProvider); int itemCount; if (items != null && 0 != (itemCount = items.Count)) { int offsetAdjustment = initializer.ToolboxItemPositionOffset; if (offsetAdjustment != 0) { for (int i = 0; i < itemCount; ++i) { ModelingToolboxItem item = items[i]; items[i] = new ModelingToolboxItem(item.Id, item.Position + offsetAdjustment, item.DisplayName, item.Bitmap, item.TabNameId, item.TabName, item.ContextSensitiveHelpKeyword, item.Description, item.Prototype, item.Filter); } } return items; } } return null; }