public string CreateImage(ImageSource SourceImage, IRecognizableComposite SourceOwner, object Source, string MemberName, IRecognizableComposite Requester = null) { if (SourceImage == null) { return(""); } var Creation = (SourceOwner == Source ? this.CreateUniqueRelativeLocationDirect(SourceOwner, MemberName, MemberName + ".png") : this.CreateUniqueRelativeLocation(SourceOwner, Source, MemberName, /*+? Source.ToStringAlways().TextToUrlIdentifier() + "." + */ MemberName + ".png")); var RefName = this.GetRelativeLocationOf(Source, MemberName, Requester); if (Creation) { var Location = this.GetPhysicalLocationOf(Source, MemberName); var Content = SourceImage.ToVisual(); // .RenderToBitmap((int)SourceImage.GetWidth(), (int)SourceImage.GetHeight()).ToBytes(); this.PrepareToWrite(Location); Display.ExportImageTo(Location, Content, (int)SourceImage.GetWidth(), (int)SourceImage.GetHeight()); } return(RefName); }
// ----------------------------------------------------------------------------------------- public string GetRecordValueAsHtmlString(object Value, IRecognizableComposite RecordsOwner, object RecordObject = null, IRecognizableComposite Requester = null, string MemberNamePrefix = null) { var Result = ""; // PENDING: Determine and include link if (Value is MAssignment) { Value = ((MAssignment)Value).AssignedValue; } if (Value is ImageSource) { var Picture = this.CurrentWorker.AtOriginalThreadGetFrozen((ImageSource)Value); var PictureRef = this.CreateImage(Picture, RecordsOwner, RecordObject, MemberNamePrefix.NullDefault("") + FormalPresentationElement.__Pictogram.TechName); Result = "<img Alt='' Src='" + PictureRef + "' style='width:" + ReportConfiguration.LIST_PICT_STD_WIDTH.ToString() + "px; height:" + ReportConfiguration.LIST_PICT_STD_HEIGHT.ToString() + "px;' />"; } else { Result = (Value is IIdentifiableElement ? ((IIdentifiableElement)Value).Name : Value.ToStringAlways()).ToHtmlEncoded(); } return(Result); }
public string CreateImage(ImageSource SourceImage, IRecognizableComposite Source, string MemberName, IRecognizableComposite Requester = null) { var Result = this.CreateImage(SourceImage, Source, Source, MemberName, Requester); return(Result); }
// ----------------------------------------------------------------------------------------- public void CreatePageHeader(IRecognizableComposite Source) { this.PageWrite("<HEAD>"); this.IncreaseIndent(); var Location = this.GetRelativeLocationOf(this.SourceComposition, STYLE_SHEET_FILE, this.CurrentPage.Source); this.PageWrite("<link rel='stylesheet' href='" + Location + "' type='text/css' />"); if (Source != null) { var Route = Source.GetContainmentNodes(true); var Navigator = Route.GetConcatenationIndexed((item, index) => "<a href=\"" + GetRelativeLocationOf(item, null, Source) + "\">" + item.NameCaption.GetTruncatedWithEllipsis(NAVLINK_TEXT_LIMIT) + "</a>", " / "); // looks ugly ni chrome this.PageWrite("<p class=\"extras\">At: / " + Navigator + "</p>"); } this.PageWrite("<table style='width: " + HTML_STD_PAGE_WIDTH.ToString() + "px;'>"); this.PageWrite("<col style='width: 30%;'/>"); this.PageWrite("<col style='width: 40%;'/>"); this.PageWrite("<col style='width: 30%;'/>"); this.PageWrite("<td class='header-left'>" + InterpretText(this.Configuration.PageHeader_Left) + "</td>"); this.PageWrite("<td class='header-center'>" + InterpretText(this.Configuration.PageHeader_Center) + "</td>"); this.PageWrite("<td class='header-right'>" + InterpretText(this.Configuration.PageHeader_Right) + "</td>"); this.PageWrite("</table>"); this.DecreaseIndent(); this.PageWrite("</HEAD>"); }
// ----------------------------------------------------------------------------------------- // Rows=[Value], ColumnDefinitions=[Tech-Name, Name, Width-Percentage, Row-Field-Extractor] public void PageWriteTable <TRow>(string ClassName, IRecognizableComposite SourceOwner, IEnumerable <TRow> Rows, params Capsule <string, string, double, Func <TRow, IMModelClass> >[] ColumnDefinitions) where TRow : IMModelClass { var Records = Rows.Select( row => { var Values = new List <string>(); // Travel Colum-Defs... foreach (var ColValueDef in ColumnDefinitions) { var Entity = (ColValueDef.Value3 == null ? row : ColValueDef.Value3(row)); var Spec = ""; if (Entity != null) { var ColDef = Entity.ClassDefinition.GetPropertyDef(ColValueDef.Value0, false); var Value = (ColDef == null ? null : ColDef.Read(Entity)); Spec = GetRecordValueAsHtmlString(Value, SourceOwner, row); } Values.Add(Spec); } return((IEnumerable <string>)Values); }); var ColDefs = ColumnDefinitions.Select( def => Capsule.Create(def.Value0, def.Value1, def.Value2)).ToArray(); this.PageWriteTable(ClassName, Records, ColDefs); }
/// <summary> /// Creates a unique location for the specified Source object, its relative-name and an optional specified member-name and relative-name. /// Example: Owner=IdeaX, Source=MarkerZ, "Pictogram", "Pictogram.png" /// Returns true if created, or false if already created. /// </summary> public bool CreateUniqueRelativeLocation(IRecognizableComposite Owner, object Source, string MemberName, string RelativeName) { if (!this.RegisteredDependents.ContainsKey(Source)) { this.RegisteredDependents.Add(Source, Owner); } return(this.CreateUniqueRelativeLocationDirect(Source, MemberName, RelativeName)); }
/// <summary> /// Gets the relative location (link identifier) of the specified Target object, plus optional Member-Name and Requester. /// Returns null when target has generation pending. /// </summary> public string GetRelativeLocationOf(object Target, string MemberName = null, IRecognizableComposite Requester = null) { if (MemberName == null) { MemberName = "."; } else { MemberName = MemberName.TextToUrlIdentifier(); } if (!this.RegisteredLocations.ContainsKey(Target) || !this.RegisteredLocations[Target].ContainsKey(MemberName)) { return(null); // not yet registered } var RelativeUniqueLocation = this.RegisteredLocations[Target][MemberName]; if (MemberName == ".") { RelativeUniqueLocation = RelativeUniqueLocation + ".html"; } var CompositeTarget = ((Target is IRecognizableComposite) ? (IRecognizableComposite)Target : this.RegisteredDependents[Target]); var AccessPath = (MemberName == "." ? "" : this.RegisteredLocations[CompositeTarget]["."] + CONTENT_FOLDER_SUFFIX + "/"); CompositeTarget = CompositeTarget.CompositeParent; while (CompositeTarget != null) { AccessPath = this.RegisteredLocations[CompositeTarget]["."] + CONTENT_FOLDER_SUFFIX + "/" + AccessPath; CompositeTarget = CompositeTarget.CompositeParent; } RelativeUniqueLocation = AccessPath + RelativeUniqueLocation; if (Requester == null && this.CurrentPage.Source != this.SourceComposition) { Requester = this.CurrentPage.Source; } if (Requester == null) { RelativeUniqueLocation = "./" + RelativeUniqueLocation; } else { RelativeUniqueLocation = "../".Replicate(Requester.CompositeDepthLevel - 1) + RelativeUniqueLocation; } return(RelativeUniqueLocation); }
/// <summary> /// Constructor. /// </summary> public ReportHtmlPage(IRecognizableComposite Source, ReportHtmlGenerator Generator) { this.Source = Source; Generator.CreateUniqueRelativeLocation(Source); // This already was created for root (Composition). this.PhysicalLocation = Generator.GetPhysicalLocationOf(Source); this.PageContentDir = Path.Combine(Path.GetDirectoryName(this.PhysicalLocation), Path.GetFileNameWithoutExtension(this.PhysicalLocation) + ReportHtmlGenerator.CONTENT_FOLDER_SUFFIX + "\\"); }
// ----------------------------------------------------------------------------------------- public void CreateListOfMarkers(IRecognizableComposite SourceOwner, IEnumerable <MarkerAssignment> Source) { var TableColDefs = new List <Capsule <string, string, double, Func <MarkerAssignment, IMModelClass> > >(); var TableRowVals = new List <List <string> >(); if (this.Configuration.CompositeIdea_Markers_List.Definitor) { TableColDefs.Add(new Capsule <string, string, double, Func <MarkerAssignment, IMModelClass> > (MarkerDefinition.__Name.TechName, // Think twice, this is ok MarkerAssignment.__Definitor.Name.RemoveNewLines().ToHtmlEncoded(), 25.0, rec => rec.Definitor)); } if (this.Configuration.CompositeIdea_Markers_List.PropPictogram) { TableColDefs.Add(new Capsule <string, string, double, Func <MarkerAssignment, IMModelClass> > (SimplePresentationElement.__Pictogram.TechName, "Pict.", 5.0, rec => (rec.Descriptor != null && rec.Descriptor.Pictogram != null ? rec.Descriptor : rec.Definitor))); } if (this.Configuration.CompositeIdea_Markers_List.PropName) { TableColDefs.Add(new Capsule <string, string, double, Func <MarkerAssignment, IMModelClass> > (SimplePresentationElement.__Name.TechName, SimplePresentationElement.__Name.Name.RemoveNewLines().ToHtmlEncoded(), 20.0, rec => rec.Descriptor)); } if (this.Configuration.CompositeIdea_Markers_List.PropTechName) { TableColDefs.Add(new Capsule <string, string, double, Func <MarkerAssignment, IMModelClass> > (SimplePresentationElement.__TechName.TechName, SimplePresentationElement.__TechName.Name.RemoveNewLines().ToHtmlEncoded(), 20.0, rec => rec.Descriptor)); } if (this.Configuration.CompositeIdea_Markers_List.PropSummary) { TableColDefs.Add(new Capsule <string, string, double, Func <MarkerAssignment, IMModelClass> > (SimplePresentationElement.__Summary.TechName, SimplePresentationElement.__Summary.Name.RemoveNewLines().ToHtmlEncoded(), 30.0, rec => rec.Descriptor)); } this.PageWriteTable("tbl_list_objects", SourceOwner, Source, TableColDefs.ToArray()); }
internal ReportHtmlPage PushPage(IRecognizableComposite Source) { this.PageCount++; var Page = new ReportHtmlPage(Source, this); this.PagesStack.Push(Page); this.PageWrite("<HTML>"); this.IncreaseIndent(); this.CreatePageHeader(Source); this.PageWrite("<BODY>"); this.IncreaseIndent(); return(Page); }
// ----------------------------------------------------------------------------------------- public string GetStoredPictureAsHtmlImageRef(ImageAssignment Picture, IRecognizableComposite RecordsOwner, TableRecord RecordObject) { var Result = ""; if (Picture != null) { var PictureImage = this.CurrentWorker.AtOriginalThreadGetFrozen(Picture.Image); if (PictureImage != null) { var PictureRef = this.CreateImage(PictureImage, RecordsOwner, RecordObject, RecordObject.OwnerTable.Designation.TechName + "_" + RecordObject.OwnerTable.OwnerIdea.Details.IndexOf(RecordObject.OwnerTable).ToString() + "_" + RecordObject.Index.ToString()); Result = "<img Alt='' Src='" + PictureRef.ToHtmlEncoded() + "' style='max-width:" + ReportConfiguration.TBLF_PICT_MAX_WIDTH.ToString() + "px; max-height:" + ReportConfiguration.TBLF_PICT_MAX_HEIGHT.ToString() + "px;' />"; } } return(Result); }
// ----------------------------------------------------------------------------------------- public void CreateContentCard(IRecognizableComposite Source, DisplayCard DispCard) { var TableColDefs = new List <Capsule <string, string, double> >(); var TableRowVals = new List <string>(); if (DispCard.PropName) { TableColDefs.Add(Capsule.Create(FormalPresentationElement.__Name.TechName.ToHtmlEncoded(), FormalPresentationElement.__Name.Name.ToHtmlEncoded(), 30.0)); TableRowVals.Add(Source.Name.RemoveNewLines().ToHtmlEncoded()); } if (DispCard.PropTechName) { TableColDefs.Add(Capsule.Create(FormalPresentationElement.__TechName.TechName.ToHtmlEncoded(), FormalPresentationElement.__TechName.Name.ToHtmlEncoded(), 30.0)); TableRowVals.Add(Source.TechName.ToHtmlEncoded()); } if (DispCard.PropPictogram && Source is IRecognizableElement) { var LocalPicture = this.CurrentWorker.AtOriginalThreadInvoke <ImageSource>( () => { var Picture = ((IRecognizableElement)Source).Pictogram; if (Picture == null) { if (Source is IdeaDefinition) { Picture = ((IdeaDefinition)Source).Pictogram; } else if (Source is Idea && ((Idea)Source).IdeaDefinitor.DefaultSymbolFormat.UseDefinitorPictogramAsNullDefault) { Picture = ((Idea)Source).IdeaDefinitor.Pictogram; } } if (Picture != null && !Picture.IsFrozen) { Picture.Freeze(); } return(Picture); }); if (LocalPicture != null) { var PictureRef = this.CreateImage(LocalPicture, Source, FormalPresentationElement.__Pictogram.TechName); TableColDefs.Add(Capsule.Create(FormalPresentationElement.__Pictogram.TechName.ToHtmlEncoded(), FormalPresentationElement.__Pictogram.Name.ToHtmlEncoded(), 40.0)); TableRowVals.Add("<img Alt='" + Source.Name.RemoveNewLines().ToHtmlEncoded() + "' Src='" + PictureRef + "' style='max-width:" + ReportConfiguration.PICTOGRAM_MAX_WIDTH.ToString() + "px; max-height:" + ReportConfiguration.PICTOGRAM_MAX_HEIGHT.ToString() + "px;' />"); /* This works on IE, but only if allowed by user (it says that 'IE has blocked execution of ActiveX or Script code')... * "width: expression(this.width > " + ReportConfiguration.PICTOGRAM_MAX_WIDTH.ToString() + " ? " + ReportConfiguration.PICTOGRAM_MAX_WIDTH.ToString() + ": true);" + * "height: expression(this.height > " + ReportConfiguration.PICTOGRAM_MAX_HEIGHT.ToString() + " ? " + ReportConfiguration.PICTOGRAM_MAX_HEIGHT.ToString() + ": true);' />"); */ } } this.PageWriteTable("tbl_card_props", TableRowVals.IntoEnumerable(), TableColDefs.ToArray()); // .......................................................... if (DispCard.PropSummary) { this.PageWriteTable("tbl_card_props", Source.Summary.ToHtmlEncoded().IntoEnumerable().IntoEnumerable(), Capsule.Create(FormalPresentationElement.__Summary.TechName.ToHtmlEncoded(), FormalPresentationElement.__Summary.Name.ToHtmlEncoded(), 100.0)); } // .......................................................... TableColDefs.Clear(); TableRowVals.Clear(); if (DispCard.Definitor && Source is Idea) { TableColDefs.Add(Capsule.Create("KindName", ((Idea)Source).BaseKind.Name.ToHtmlEncoded(), 30.0)); TableRowVals.Add(((Idea)Source).IdeaDefinitor.Name.ToHtmlEncoded()); } if (DispCard.PropGlobalId && Source is IUniqueElement) { TableColDefs.Add(Capsule.Create(UniqueElement.__GlobalId.TechName.ToHtmlEncoded(), UniqueElement.__GlobalId.Name.ToHtmlEncoded(), 30.0)); TableRowVals.Add(((IUniqueElement)Source).GlobalId.ToString().ToHtmlEncoded()); } if (DispCard.Definitor && Source is View) { TableColDefs.Add(Capsule.Create(View.__ClassDefinitor.TechName.ToHtmlEncoded(), View.__ClassDefinitor.Name.ToHtmlEncoded(), 30.0)); TableRowVals.Add(((Idea)Source).IdeaDefinitor.Name.ToHtmlEncoded()); } this.PageWriteTable("tbl_card_props", TableRowVals.IntoEnumerable(), TableColDefs.ToArray()); // .......................................................... if (DispCard.Route & Source is Idea) { this.PageWriteTable("tbl_card_props", ((Idea)Source).GetContainmentRoute().ToHtmlEncoded().IntoEnumerable().IntoEnumerable(), Capsule.Create("Route", "Route", 100.0)); } // .......................................................... if (DispCard.PropDescription && Source is IFormalizedElement) { var Element = (IFormalizedElement)Source; // Description if (!Element.Description.IsAbsent()) { var TextDocument = Display.XamlRichTextTo(Element.Description, DataFormats.Html); this.PageWriteTable("tbl_card_props", TextDocument.IntoEnumerable().IntoEnumerable(), Capsule.Create(FormalElement.__Description.TechName.ToHtmlEncoded(), FormalElement.__Description.Name.ToHtmlEncoded(), 100.0)); } // Classification (Pending) // Versioning if (Element.Version != null) { TableColDefs.Clear(); TableRowVals.Clear(); var VerInfo = new Grid(); VerInfo.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.13, GridUnitType.Star) }); // Version Number VerInfo.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.13, GridUnitType.Star) }); // Version Sequence VerInfo.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.13, GridUnitType.Star) }); // Creation VerInfo.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.24, GridUnitType.Star) }); // Creator VerInfo.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.13, GridUnitType.Star) }); // Last Modification VerInfo.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.24, GridUnitType.Star) }); // Last Modifier TableColDefs.Add(Capsule.Create(VersionCard.__VersionNumber.TechName.ToHtmlEncoded(), VersionCard.__VersionNumber.Name.ToHtmlEncoded(), 13.0)); TableRowVals.Add(Element.Version.VersionNumber.ToHtmlEncoded()); TableColDefs.Add(Capsule.Create(VersionCard.__VersionSequence.TechName.ToHtmlEncoded(), VersionCard.__VersionSequence.Name.ToHtmlEncoded(), 13.0)); TableRowVals.Add(Element.Version.VersionSequence.ToString()); TableColDefs.Add(Capsule.Create(VersionCard.__Creation.TechName.ToHtmlEncoded(), VersionCard.__Creation.Name.ToHtmlEncoded(), 13.0)); TableRowVals.Add(Element.Version.Creation.ToString().ToHtmlEncoded()); TableColDefs.Add(Capsule.Create(VersionCard.__Creator.TechName.ToHtmlEncoded(), VersionCard.__Creator.Name.ToHtmlEncoded(), 24.0)); TableRowVals.Add(Element.Version.Creator.ToHtmlEncoded()); TableColDefs.Add(Capsule.Create(VersionCard.__LastModification.TechName.ToHtmlEncoded(), VersionCard.__LastModification.Name.ToHtmlEncoded(), 13.0)); TableRowVals.Add(Element.Version.LastModification.ToString().ToHtmlEncoded()); TableColDefs.Add(Capsule.Create(VersionCard.__LastModifier.TechName.ToHtmlEncoded(), VersionCard.__LastModifier.Name.ToHtmlEncoded(), 24.0)); TableRowVals.Add(Element.Version.LastModifier.ToHtmlEncoded()); this.PageWriteTable("tbl_card_props", TableRowVals.IntoEnumerable(), TableColDefs.ToArray()); if (!Element.Version.Annotation.IsAbsent()) { this.PageWriteTable("tbl_card_props", Element.Version.Annotation.ToHtmlEncoded().IntoEnumerable().IntoEnumerable(), Capsule.Create(VersionCard.__Annotation.TechName.ToHtmlEncoded(), VersionCard.__Annotation.Name.ToHtmlEncoded(), 100.0)); } } } if (DispCard.PropTechSpec && Source is ITechSpecifier) { var Element = (ITechSpecifier)Source; if (!Element.TechSpec.IsAbsent()) { this.PageWriteTable("tbl_card_props", Element.TechSpec.ToHtmlEncoded().IntoEnumerable().IntoEnumerable(), Capsule.Create(FormalPresentationElement.__TechSpec.TechName.ToHtmlEncoded(), FormalPresentationElement.__TechSpec.Name.ToHtmlEncoded(), 100.0)); } } }
public void CreateContentList(IEnumerable <IMModelClass> Source, IRecognizableComposite SourceOwner, DisplayList DispList, string DefinitorTechName, string DefinitorName, string TechPrefixInternalOwner = null, string TechPrefixSource = null, params Tuple <string, string, double, Func <IMModelClass, object> >[] ExtraColDefs) { var TableColDefs = new List <Capsule <string, string, double, Func <IMModelClass, object> > >(); var TableRowVals = new List <List <string> >(); // Define columns if (DispList.PropName) { TableColDefs.Add(Capsule.Create(FormalPresentationElement.__Name.TechName.RemoveNewLines().ToHtmlEncoded(), FormalPresentationElement.__Name.Name.RemoveNewLines().ToHtmlEncoded(), 25.0, (Func <IMModelClass, object>)null)); } if (DispList.PropTechName) { TableColDefs.Add(Capsule.Create(FormalPresentationElement.__TechName.TechName.RemoveNewLines().ToHtmlEncoded(), FormalPresentationElement.__TechName.Name.RemoveNewLines().ToHtmlEncoded(), 20.0, (Func <IMModelClass, object>)null)); } if (DispList.PropSummary) { TableColDefs.Add(Capsule.Create(FormalPresentationElement.__Summary.TechName.RemoveNewLines().ToHtmlEncoded(), FormalPresentationElement.__Summary.Name.RemoveNewLines().ToHtmlEncoded(), (!DispList.PropTechName ? 50.0 : 30.0), (Func <IMModelClass, object>)null)); } if (DispList.PropPictogram) { TableColDefs.Add(Capsule.Create(FormalPresentationElement.__Pictogram.TechName.RemoveNewLines().ToHtmlEncoded(), "Pict.", 5.0, // FormalPresentationElement.__Pictogram.Name.RemoveNewLines().ToHtmlEncoded() (Func <IMModelClass, object>)null)); } if (DispList.Definitor && !(DefinitorTechName.IsAbsent() || DefinitorName.IsAbsent())) { TableColDefs.Add(Capsule.Create(DefinitorTechName.ToHtmlEncoded(), DefinitorName.ToHtmlEncoded(), (!DispList.PropPictogram ? 28.0 : 20.0), (Func <IMModelClass, object>)null)); } if (ExtraColDefs != null) { foreach (var ExtraColDef in ExtraColDefs) { TableColDefs.Add(Capsule.Create(ExtraColDef.Item1.ToHtmlEncoded(), ExtraColDef.Item2.ToHtmlEncoded(), ExtraColDef.Item3, ExtraColDef.Item4)); } } // Generate record values foreach (var Record in Source) { var Values = new List <string>(); string Anchor = null; if (this.RegisteredLocations.ContainsKey(Record)) { var RefLink = this.GetRelativeLocationOf(Record); if (!RefLink.IsAbsent()) { Anchor = "<a href=" + RefLink + ">@VALUE</a>"; } } // Travel Colum-Defs... foreach (var ColValueDef in TableColDefs) { var ColDef = Record.ClassDefinition.GetPropertyDef(ColValueDef.Value0, false); object Value = null; if (ColDef != null && Record is IRecognizableElement && ColDef.TechName == FormalPresentationElement.__Pictogram.TechName) // Used as "Formal..." but could be a "Simple..." { Value = this.CurrentWorker.AtOriginalThreadInvoke( () => { var Picture = ((IRecognizableElement)Record).Pictogram; if (Picture == null) { if (Record is IdeaDefinition) { Picture = ((IdeaDefinition)Record).Pictogram; } else if (Record is Idea && ((Idea)Record).IdeaDefinitor.DefaultSymbolFormat.UseDefinitorPictogramAsNullDefault) { Picture = ((Idea)Record).IdeaDefinitor.Pictogram; } } if (Picture != null && !Picture.IsFrozen) { Picture.Freeze(); } return(Picture); }); } else { Value = (ColValueDef.Value3 != null ? ColValueDef.Value3(Record) : (ColDef == null ? null : ColDef.Read(Record))); } var NamePrefix = (TechPrefixInternalOwner.IsAbsent() ? "" : TechPrefixInternalOwner + ".") + (TechPrefixSource.IsAbsent() ? "" : TechPrefixSource + "_" + Source.IndexOfMatch(item => item == Record).ToString() + "."); var Spec = GetRecordValueAsHtmlString(Value, SourceOwner, Record, null, NamePrefix); if (Values.Count < 1 && Anchor != null) { Spec = Anchor.Replace("@VALUE", Spec); } Values.Add(Spec); } TableRowVals.Add(Values); } ; this.PageWriteTable("tbl_list_objects", TableRowVals, TableColDefs.Select(def => Capsule.Create(def.Value0, def.Value1, def.Value2)).ToArray()); }
/// <summary> /// Creates a unique location for the specified Source Recognizable-Composite with the optional specified member-name and relative-name. /// Example: Source=IdeaX, MemberName="MainView", InitialRelativeName="MainView.png" /// Returns true if created, or false if already created. /// </summary> public bool CreateUniqueRelativeLocation(IRecognizableComposite Source, string MemberName = null, string InitialRelativeName = null) { return(this.CreateUniqueRelativeLocationDirect(Source, MemberName, InitialRelativeName)); }
// --------------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Creates and returns a data-grid-column for the supplied table Field definitor. /// </summary> public static DataGridColumn CreateGridColumn(FieldDefinition Definitor, IRecognizableComposite ReferencesContext) { DataGridColumn Result = null; FrameworkElementFactory CellEditFactory = null; FrameworkElementFactory CellShowFactory = null; var EditingTemplate = new DataTemplate(); var ShowingTemplate = new DataTemplate(); var Column = new ExtendedDataGridTemplateColumn(); var ShowBinder = new Binding(Definitor.TechName); ShowBinder.ConverterCulture = System.Globalization.CultureInfo.CurrentCulture; ShowBinder.Mode = BindingMode.OneWay; CellShowFactory = new FrameworkElementFactory(typeof(TextBlock)); CellShowFactory.SetValue(TextBlock.TextProperty, ShowBinder); var EditBinder = new Binding(Definitor.TechName); EditBinder.ConverterCulture = System.Globalization.CultureInfo.CurrentCulture; EditBinder.Mode = BindingMode.TwoWay; if (Definitor.FieldType is BasicDataType) { var BasicKind = ((BasicDataType)Definitor.FieldType); ShowBinder.StringFormat = BasicKind.DisplayFormat; CellShowFactory.SetValue(TextBlock.TextAlignmentProperty, BasicKind.DisplayAlignment); EditBinder.StringFormat = BasicKind.DisplayFormat; if (BasicKind is TextType) { var TextKind = BasicKind as TextType; CellEditFactory = new FrameworkElementFactory(typeof(ExtendedEditText)); CellEditFactory.SetValue(ExtendedEditText.StorageFieldNameProperty, Definitor.TechName); CellEditFactory.SetValue(ExtendedEditText.ApplyDirectAccessProperty, true); CellEditFactory.SetValue(ExtendedEditText.ValueProperty, EditBinder); CellEditFactory.SetValue(ExtendedEditText.MaxLengthProperty, TextKind.SizeLimit); //- CellEditFactory.SetValue(ExtendedEditText.PaddingProperty, new Thickness(0, -1, 0, 0)); if (Definitor.ValuesSource != null && Definitor.ValuesSource is Table && Definitor.ValuesSource != Domain.Unassigned_BaseTable) { CellEditFactory.SetValue(ExtendedEditText.ValuesSourceProperty, Definitor.ValuesSource); CellEditFactory.SetValue(ExtendedEditText.ValuesSourceMemberPathProperty, "Label"); } if (ReferencesContext != null && Definitor.IdeaReferencingProperty != null && Definitor.IdeaReferencingProperty != Domain.Unassigned_IdeaReferencingPropertyProperty) { CellEditFactory.SetValue(ExtendedEditText.CompositesSourceProperty, ReferencesContext.CompositeMembers); CellEditFactory.SetValue(ExtendedEditText.CompositesSourceMemberPathProperty, Definitor.IdeaReferencingProperty.TechName); } } else if (BasicKind is NumberType) { var NumberKind = BasicKind as NumberType; CellEditFactory = new FrameworkElementFactory(typeof(MaskEditNumber)); CellEditFactory.SetValue(MaskEditNumber.StorageFieldNameProperty, Definitor.TechName); CellEditFactory.SetValue(MaskEditNumber.ApplyDirectAccessProperty, true); CellEditFactory.SetValue(MaskEditNumber.FormatProperty, NumberKind.DisplayFormat); CellEditFactory.SetValue(MaskEditNumber.IntegerDigitsProperty, NumberKind.IntegerDigits); CellEditFactory.SetValue(MaskEditNumber.DecimalDigitsProperty, NumberKind.DecimalDigits); CellEditFactory.SetValue(MaskEditNumber.MinLimitProperty, NumberKind.MinLimit); CellEditFactory.SetValue(MaskEditNumber.MaxLimitProperty, NumberKind.MaxLimit); CellEditFactory.SetValue(MaskEditNumber.ValueProperty, EditBinder); if (Definitor.ValuesSource != null && Definitor.ValuesSource is Table) { CellEditFactory.SetValue(MaskEditNumber.ValuesSourceProperty, Definitor.ValuesSource); CellEditFactory.SetValue(MaskEditNumber.ValuesSourceMemberPathProperty, "Label"); CellEditFactory.SetValue(MaskEditNumber.ValuesSourceNumericConverterProperty, TableRecord.TableRecordToNumericConverter); } } else if (BasicKind is DateTimeType) { var DateTimeKind = BasicKind as DateTimeType; CellEditFactory = new FrameworkElementFactory(typeof(MaskEditDateTime)); CellEditFactory.SetValue(MaskEditDateTime.StorageFieldNameProperty, Definitor.TechName); CellEditFactory.SetValue(MaskEditDateTime.ApplyDirectAccessProperty, true); if (!DateTimeKind.HasDatePart) { CellEditFactory.SetValue(MaskEditDateTime.HasDateProperty, false); } else if (!DateTimeKind.HasTimePart) { CellEditFactory.SetValue(MaskEditDateTime.HasTimeProperty, false); } CellEditFactory.SetValue(MaskEditDateTime.ValueProperty, EditBinder); } else if (BasicKind is ChoiceType) { var ChoiceKind = BasicKind as ChoiceType; // Notice the use of IsEquivalent() to preserve comparability after deserialization if (ChoiceKind.IsEquivalent(DataType.DataTypeSwitch)) { CellEditFactory = new FrameworkElementFactory(typeof(ExtendedEditCheckBox)); CellShowFactory = new FrameworkElementFactory(typeof(ExtendedEditCheckBox)); CellEditFactory.SetValue(ExtendedEditCheckBox.StorageFieldNameProperty, Definitor.TechName); CellEditFactory.SetValue(ExtendedEditCheckBox.ApplyDirectAccessProperty, true); CellShowFactory.SetValue(ExtendedEditCheckBox.StorageFieldNameProperty, Definitor.TechName); CellShowFactory.SetValue(ExtendedEditCheckBox.ApplyDirectAccessProperty, true); CellEditFactory.SetValue(ExtendedEditCheckBox.IsCheckedProperty, EditBinder); CellEditFactory.SetValue(ExtendedEditCheckBox.HorizontalAlignmentProperty, HorizontalAlignment.Center); CellShowFactory.SetValue(ExtendedEditCheckBox.IsCheckedProperty, ShowBinder); CellShowFactory.SetValue(ExtendedEditCheckBox.HorizontalAlignmentProperty, HorizontalAlignment.Center); } else { CellEditFactory = new FrameworkElementFactory(typeof(ExtendedEditComboBox)); //- CellShowFactory = new FrameworkElementFactory(typeof(ExtendedEditComboBox)); CellEditFactory.SetValue(ExtendedEditComboBox.StorageFieldNameProperty, Definitor.TechName); CellEditFactory.SetValue(ExtendedEditComboBox.ApplyDirectAccessProperty, true); //- CellShowFactory.SetValue(ExtendedEditComboBox.StorageFieldNameProperty, Definitor.TechName); //- CellShowFactory.SetValue(ExtendedEditComboBox.ApplyDirectAccessProperty, true); CellEditFactory.SetValue(ExtendedEditComboBox.ItemsSourceProperty, ChoiceKind.GetRegisteredOptions()); CellEditFactory.SetValue(ExtendedEditComboBox.SelectedValuePathProperty, "Item1"); // The Choice/Option CellEditFactory.SetValue(ExtendedEditComboBox.DisplayMemberPathProperty, "Item2"); // The Name //- CellShowFactory.SetValue(ExtendedEditComboBox.ItemsSourceProperty, ChoiceKind.GetRegisteredOptions()); //- CellShowFactory.SetValue(ExtendedEditComboBox.SelectedValuePathProperty, "Item1"); // The Choice/Option //- CellShowFactory.SetValue(ExtendedEditComboBox.DisplayMemberPathProperty, "Item2"); // The Name //- CellShowFactory.SetValue(ExtendedEditComboBox.IsReadOnlyProperty, true); ShowBinder.Path = new PropertyPath(Definitor.TechName + ".Item2"); // Special case: Binds KVP instead on only the Key. So, update of values is made directly. // Really, for the Extended-Edit-Controls, the binding is not needed. EditBinder.Mode = BindingMode.OneWay; CellEditFactory.SetValue(ExtendedEditComboBox.SelectedItemProperty, EditBinder); //- CellShowFactory.SetValue(ExtendedEditComboBox.SelectedItemProperty, ShowBinder); } } } else if (Definitor.FieldType is TableRecordLinkType) { CellEditFactory = new FrameworkElementFactory(typeof(ExtendedEditComboBox)); CellEditFactory.SetValue(ExtendedEditComboBox.StorageFieldNameProperty, Definitor.TechName); CellEditFactory.SetValue(ExtendedEditComboBox.ApplyDirectAccessProperty, true); CellEditFactory.SetValue(ExtendedEditComboBox.ItemsSourceProperty, Definitor.ValuesSource); CellEditFactory.SetValue(ExtendedEditComboBox.DisplayMemberPathProperty, "Label"); ShowBinder.Path = new PropertyPath(Definitor.TechName + ".Label"); /*? Didn't work (editable cell): * CellShowFactory.SetValue(ExtendedEditComboBox.IsReadOnlyProperty, false); * CellShowFactory.SetValue(ExtendedEditComboBox.IsEditableProperty, true); */ // Really, for the Extended-Edit-Controls, the binding is not needed. EditBinder.Mode = BindingMode.OneWay; CellEditFactory.SetValue(ExtendedEditComboBox.SelectedItemProperty, EditBinder); // Didn't work // ShowBinder.Converter = new GenericConverter<TableRecord, string>(trec => (trec == null ? null : trec.Label), str => null); } else if (Definitor.FieldType is IdeaLinkType) { /* Binding only works on record-fields, so don't use as in the next way... * var SpecBinder = new MultiBinding(); * SpecBinder.Bindings.Add(new Binding("NameCaption")); * SpecBinder.Bindings.Add(new Binding("DescriptiveCaption")); * SpecBinder.StringFormat = "{}{0} {1}"; * SpecBinder.ConverterCulture = System.Globalization.CultureInfo.CurrentCulture; * SpecBinder.Mode = BindingMode.OneWay; * CellShowFactory.SetValue(TextBlock.TextProperty, SpecBinder); */ CellEditFactory = new FrameworkElementFactory(typeof(TreeItemSelector)); CellShowFactory = new FrameworkElementFactory(typeof(TreeItemSelector)); CellEditFactory.SetValue(TreeItemSelector.StorageFieldNameProperty, Definitor.TechName); CellEditFactory.SetValue(TreeItemSelector.ApplyDirectAccessProperty, true); CellEditFactory.SetValue(TreeItemSelector.ValueProperty, EditBinder); CellShowFactory.SetValue(TreeItemSelector.StorageFieldNameProperty, Definitor.TechName); CellShowFactory.SetValue(TreeItemSelector.ApplyDirectAccessProperty, true); CellShowFactory.SetValue(TreeItemSelector.ValueProperty, EditBinder); if (ReferencesContext != null) { CellEditFactory.SetValue(TreeItemSelector.CompositesSourceProperty, ReferencesContext.CompositeMembers); } } else if (Definitor.FieldType is TableType) { EditBinder.Path = new PropertyPath("."); // This references the Table-Record, not a field within it. ShowBinder.Path = new PropertyPath(Definitor.TechName + ".RecordsLabel"); CellEditFactory = new FrameworkElementFactory(typeof(PaletteButton)); CellShowFactory = new FrameworkElementFactory(typeof(TextBlock)); CellEditFactory.SetValue(PaletteButton.ButtonTextProperty, ShowBinder); CellEditFactory.SetValue(PaletteButton.ButtonShowImageProperty, false); // CellEditFactory.SetValue(PaletteButton.ButtonImageProperty, Display.GetAppImage("table_edit.png")); CellEditFactory.SetValue(PaletteButton.ToolTipProperty, "Edit data values"); CellEditFactory.SetValue(PaletteButton.ButtonActionFieldNameProperty, Definitor.TechName); CellEditFactory.SetValue(PaletteButton.ButtonActionFieldSourceProperty, EditBinder); CellEditFactory.SetValue(PaletteButton.ButtonClickActionProperty, (Action <string, object>) ((fname, fsource) => { //T Display.DialogMessage("Field: [" + fname.NullDefault("?") + "]", "Value: [" + fvalue.NullDefault("") + "]"); var SourceRecord = fsource as TableRecord; if (SourceRecord == null) { return; } var StoredTable = SourceRecord.GetStoredValue(fname) as Table; if (Definitor.ContainedTableDesignator == null) { return; } if (StoredTable == null) { StoredTable = new Table(SourceRecord.OwnerTable.OwnerIdea, Definitor.ContainedTableDesignator.Assign <DetailDesignator>(false)); // This must be set for explicit change. Databinding didn't work. SourceRecord.SetStoredValue(Definitor, StoredTable); //-? Ctl.ButtonText = StoredTable.RecordsLabel; } Definitor.OwnerTableDef.EditEngine.StartCommandVariation("Edit Field contained Table"); var Changed = DetailTableEditor.Edit(StoredTable, Definitor.ContainedTableDesignator, null, Definitor.ContainedTableIsSingleRecord); Definitor.OwnerTableDef.EditEngine.CompleteCommandVariation(); if (!Changed) { Definitor.OwnerTableDef.EditEngine.Undo(); } })); CellEditFactory.SetValue(PaletteButton.CursorProperty, Cursors.Hand); CellShowFactory.SetValue(TextBlock.TextProperty, ShowBinder); CellShowFactory.SetValue(TextBlock.CursorProperty, Cursors.Hand); } else if (Definitor.FieldType is PictureType) { EditBinder.Path = new PropertyPath("."); // This references the Table-Record, not a field within it. ShowBinder.Path = new PropertyPath(Definitor.TechName + ".Image"); // EditBinder.Path = new PropertyPath(Definitor.TechName + ".Image"); // ShowBinder.Path = new PropertyPath(Definitor.TechName + ".Image"); CellEditFactory = new FrameworkElementFactory(typeof(ImagePickerSimple)); CellShowFactory = new FrameworkElementFactory(typeof(ImagePickerSimple)); CellEditFactory.SetValue(ImagePickerSimple.CursorProperty, Cursors.Hand); CellEditFactory.SetValue(ImagePickerSimple.SelectedImageProperty, ShowBinder); CellEditFactory.SetValue(ImagePickerSimple.ImagePickerActionFieldNameProperty, Definitor.TechName); CellEditFactory.SetValue(ImagePickerSimple.ImagePickerActionFieldSourceProperty, EditBinder); CellShowFactory.SetValue(ImagePickerSimple.CursorProperty, Cursors.Hand); CellShowFactory.SetValue(ImagePickerSimple.SelectedImageProperty, ShowBinder); CellShowFactory.SetValue(ImagePickerSimple.ImagePickerActionFieldNameProperty, Definitor.TechName); CellShowFactory.SetValue(ImagePickerSimple.ImagePickerActionFieldSourceProperty, EditBinder); CellShowFactory.SetValue(ImagePickerSimple.ToolTipProperty, "Edit picture"); Action <string, object, object> ImagePickAction = ((fname, fsource, ctl) => { //T Display.DialogMessage("Field: [" + fname.NullDefault("?") + "]", "Value: [" + fvalue.NullDefault("") + "]"); var SourceRecord = fsource as TableRecord; if (SourceRecord == null) { return; } // var StoredPicture = SourceRecord.GetStoredValue(fname) as ImageAssignment; //- var StoredPicture = fsource as ImageAssignment; var Selection = Display.DialogGetImageFromFile(); if (Selection != null) { Definitor.OwnerTableDef.EditEngine.StartCommandVariation("Edit Field contained Picture"); // This must be set for explicit change. Databinding didn't work. // IMPORTANT: Always store a whole new StoredPicture (ImageAssignment), // and don't just change the StoredPicture.Image property, in order to support undo/redo. var StoredPicture = Selection.AssignImage(); SourceRecord.SetStoredValue(Definitor, StoredPicture); var ImgCtl = ctl as ImagePickerSimple; if (ImgCtl != null) { ImgCtl.SelectedImage = Selection; } Definitor.OwnerTableDef.EditEngine.CompleteCommandVariation(); } }); CellEditFactory.SetValue(ImagePickerSimple.ImagePickerSelectActionProperty, ImagePickAction); CellShowFactory.SetValue(ImagePickerSimple.ImagePickerSelectActionProperty, ImagePickAction); /*- //! PENDING: NOT WORKING! SOLUTION: CREATE A CUSTOM IMAGE-CONTROL * var MouseHandler = new MouseButtonEventHandler(new Action<object, MouseButtonEventArgs>( * (obj, args) => * { * var Ctl = (obj as Image).NullDefault(args.Source as Image); * * var StoredPicture = Ctl.Tag as ImageAssignment; * * var Selection = Display.DialogGetImageFromFile(); * if (Selection != null) * { * Definitor.OwnerTableDef.EditEngine.StartCommandVariation("Edit Field contained Picture"); * * if (StoredPicture == null) * { * StoredPicture = new ImageAssignment(); * Ctl.Tag = StoredPicture; * * // This must be set for explicit change. Databinding didn't work. * //? exp.InstanceSource.SetStoredValue(exp.SourceFieldDefinitor, StoredPicture); * } * * StoredPicture.Image = Selection; * Ctl.Source = Selection; * * Definitor.OwnerTableDef.EditEngine.CompleteCommandVariation(); * } * })); * * CellEditFactory.AddHandler(Image.MouseLeftButtonDownEvent, MouseHandler, true); * CellShowFactory.AddHandler(Image.MouseLeftButtonDownEvent, MouseHandler, true); */ } // PENDING: IMPLEMENT FOR IMAGE TYPE // SEE: http://stackoverflow.com/questions/1951839/how-do-i-show-image-in-wpf-datagrid-column-programmatically // If Column and Factory were determined, then assign template if (Column != null && CellEditFactory != null) { // Setting of the editing template EditingTemplate.VisualTree = CellEditFactory; Column.CellEditingTemplate = EditingTemplate; // Setting of the showing template ShowingTemplate.VisualTree = CellShowFactory; Column.CellTemplate = ShowingTemplate; // Final assign Column.IsReadOnly = false; Result = Column; } if (Result == null) { // For unknown types assign a read-only text column Console.WriteLine("Editing set to read-only for column '{0}' with type '{1}'.", Definitor.TechName, Definitor.FieldType); var TextColumn = new DataGridTextColumn(); TextColumn.EditingElementStyle = new Style(typeof(TextBox)); TextColumn.EditingElementStyle.Setters.Add(new Setter(TextBox.PaddingProperty, new Thickness(0, -1, 0, 0))); TextColumn.IsReadOnly = true; var Binder = new Binding(Definitor.TechName); Binder.Mode = BindingMode.OneWay; TextColumn.Binding = Binder; Result = TextColumn; } var Entitler = new TextBlock(); Entitler.Text = Definitor.Name; Entitler.ToolTip = Definitor.Summary; Entitler.Tag = Definitor; Result.Header = Entitler; Result.MinWidth = Definitor.GetEstimatedColumnPixelsWidth(); return(Result); }