protected override void SetupHandler() { OptionGroup toplevelGroup = Handler.AddGroup(TOP_LEVEL); //the toplevel group will show neither in Table view nor in dialog view explicitely //it's children will be shown one level above toplevelGroup.SetAttribute(TableEditorFactory.RENDERING_HINTS_ATTRIBUTE, (int)TableEditorFactory.RenderingHints.Invisible); toplevelGroup.SetAttribute(DefaultEditorFactory.RENDERING_HINTS_ATTRIBUTE, (int)DefaultEditorFactory.RenderingHints.Invisible); OptionGroup spcg = toplevelGroup.AddGroup(SourcePortConstraints); spcg.AddGeneric(PortConstraintStr, PortConstraintType.Any).SetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false); spcg.AddBool(StrongPortConstraint, false); OptionGroup tpcg = toplevelGroup.AddGroup(TargetPortConstraints); tpcg.AddGeneric(PortConstraintStr, PortConstraintType.Any).SetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false); tpcg.AddBool(StrongPortConstraint, false); CollectionOptionItem <string> scopeItem = toplevelGroup.AddList(Scope, scopes, ScopeAllEdges); BoolOptionItem clearItem = toplevelGroup.AddBool(ClearAllConstraints, false); ConstraintManager cm = new ConstraintManager(Handler); cm.SetEnabledOnValueEquals(clearItem, false, spcg); cm.SetEnabledOnValueEquals(clearItem, false, scopeItem); cm.SetEnabledOnValueEquals(clearItem, false, tpcg); }
/// <summary> /// Factory method that creates the option item using the provided parameters. /// </summary> protected virtual IOptionItem CreateItem(IOptionBuilderContext context, PropertyInfo propertyInfo, Type type, string description, object value) { IOptionItem item = null; if (type.IsEnum) { Type genericType = typeof(GenericOptionItem <>); Type newType = genericType.MakeGenericType(type); item = newType.GetConstructor(new Type[] { typeof(string) }).Invoke(new object[] { description }) as IOptionItem; } else if (type == typeof(Color)) { item = new ColorOptionItem(description); } else if (type.IsGenericType && type.GetGenericTypeDefinition().IsAssignableFrom((typeof(ICollection <>)))) { Type[] types = type.GetGenericArguments(); if (types.Length == 1) { Type collectionItemType = types[0]; Type collectionBaseType = typeof(ICollection <>); Type collectionType = collectionBaseType.MakeGenericType(collectionItemType); Type collectionOptionItemType = typeof(CollectionOptionItem <>); item = collectionOptionItemType.MakeGenericType(collectionItemType).GetConstructor( new Type[] { typeof(string), collectionType }).Invoke(new object[] { description, value }) as IOptionItem; } } if (item == null) { if (type == typeof(double)) { item = new DoubleOptionItem(description); } else if (type == typeof(int)) { item = new IntOptionItem(description); } else if (type == typeof(float)) { item = new FloatOptionItem(description); } else if (type == typeof(bool)) { item = new BoolOptionItem(description); } else if (type == typeof(string)) { item = new StringOptionItem(description); } else { Type genericType = typeof(GenericOptionItem <>); Type newType = genericType.MakeGenericType(type); item = newType.GetConstructor(new Type[] { typeof(string) }).Invoke(new object[] { description }) as IOptionItem; } } if (item != null) { TypeConverterAttribute converter = GetAttribute <TypeConverterAttribute>(propertyInfo); if (converter != null && !converter.IsDefaultAttribute()) { try { Type typeConverter = Type.GetType(converter.ConverterTypeName); if (typeConverter != null) { item.SetAttribute(OptionItem.CUSTOM_CONVERTER_ATTRIBUTE, typeConverter); } } catch (Exception e) { Trace.WriteLine("Could not load custom type converter " + e.Message); } } //by default, value types are not nullable if (type.IsValueType) { item.SetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false); } } return(item); }
/// <summary> /// Initializes the option handler for the export /// </summary> private void SetupHandler() { handler = new OptionHandler(IMAGE_EXPORT); handler.PropertyChanged += handler_PropertyChanged; OptionGroup currentGroup = handler.AddGroup(OUTPUT); OptionItem formatItem = currentGroup.AddList(FORMAT, Formats.Keys, FORMAT_JPG); currentGroup.AddBool(HIDE_DECORATIONS, true); currentGroup.AddBool(EXPORT_RECTANGLE, true); currentGroup = handler.AddGroup(BOUNDS); OptionItem sizeItem = currentGroup.AddList(SIZE, SizeModes, USE_ORIGINAL_SIZE); IOptionItem widthItem = currentGroup.AddInt(WIDTH, DefaultWidth, 1, int.MaxValue); IOptionItem heightItem = currentGroup.AddInt(HEIGHT, DefaultHeight, 1, Int32.MaxValue); currentGroup.AddDouble(SCALE, DefaultScale); currentGroup.AddDouble(ZOOM, DefaultZoom); currentGroup = handler.AddGroup(GRAPHICS); currentGroup.AddGeneric(SMOOTHING, SimpleSmoothingMode.HighSpeed).SetAttribute( OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false); currentGroup.AddGeneric(TEXTRENDERING, TextRenderingHint.SystemDefault).SetAttribute( OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false); currentGroup.AddGeneric(INTERPOLATION, InterpolationMode.Invalid).SetAttribute( OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false); currentGroup.AddGeneric(PIXELOFFSET, PixelOffsetMode.Invalid).SetAttribute( OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false); currentGroup = handler.AddGroup(MARGINS); currentGroup.AddInt(LEFT_MARGIN, DefaultMargins); currentGroup.AddInt(RIGHT_MARGIN, DefaultMargins); currentGroup.AddInt(TOP_MARGIN, DefaultMargins); currentGroup.AddInt(BOTTOM_MARGIN, DefaultMargins); currentGroup = handler.AddGroup(JPG); DoubleOptionItem qualityItem = currentGroup.AddDouble(QUALITY, DefaultQuality); currentGroup = handler.AddGroup(TIFF); OptionItem colorDepthItem = currentGroup.AddList(COLOR_DEPTH, ColorDepthList.Keys, DefaultDepth); OptionItem compressionItem = currentGroup.AddList(COMPRESSION, Compressions.Keys, DefaultCompression); currentGroup = handler.AddGroup(PNG); BoolOptionItem transparentPNGItem = currentGroup.AddBool(TRANSPARENT, false); currentGroup = handler.AddGroup(EMF); BoolOptionItem transparentEMFItem = currentGroup.AddBool(TRANSPARENT, false); var cm = new ConstraintManager(Handler); cm.SetEnabledOnValueEquals(sizeItem, SPECIFY_WIDTH, widthItem); cm.SetEnabledOnValueEquals(sizeItem, SPECIFY_HEIGHT, heightItem); cm.SetEnabledOnValueEquals(formatItem, FORMAT_EMF, transparentEMFItem); cm.SetEnabledOnValueEquals(formatItem, FORMAT_PNG, transparentPNGItem); cm.SetEnabledOnValueEquals(formatItem, FORMAT_JPG, qualityItem); cm.SetEnabledOnValueEquals(formatItem, FORMAT_TIFF, colorDepthItem); cm.SetEnabledOnValueEquals(formatItem, FORMAT_TIFF, compressionItem); // localization var rm = new ResourceManager("Demo.yFiles.ImageExport.ImageExport", Assembly.GetExecutingAssembly()); var rmf = new ResourceManagerI18NFactory(); rmf.AddResourceManager(Handler.Name, rm); Handler.I18nFactory = rmf; }