Search This Blog

Tuesday, August 25, 2015

Getting ready the ConditionalAppearance module infrastructure for custom options of the extended AppearanceAttribute (e.g., tooltip)

First of all, this piece of information is quite advanced, so be sure you are well-aware of the module's basic functions and main extensibility and customization points, at least through AppearanceController. If not, check out the related online documentation before reading further. 

Customer scenario

Would it be possible to add in the conditional appearance module the possibility to show a tooltip in the cell in listView when the 
condition is satisfied? (you get different color based on criteria and when you move to the cell a tooltip is shown telling you why the color is different ), example:

[C#]
[Appearance("CategoryColoredInListView", AppearanceItemType = "ViewItem", TargetItems = "Category", Criteria = "Category = 'Seafood'", Context = "ListView",FontColor = "Blue", Priority = 1, ToolTip="the tooltiptext!!!!")]


Alternative solution considerations

If there were no ready built-in module in XAF, you could solve this by using the pure means available for the underlying grid control for a target platform. For instance, in WinForms, you could employ the ToolTipController API, while for ASP.NET WebForms you could handle the ASPxGridView events to programmatically assign a tooltip text to required data cells. Apparently, making these custom-tailored control-based solutions universal would require effort without XAF, and XAF users could even see this work as a duplication of the perfect existent infrastructure ConditionalAppearance provides. So, let's describe how to do things the XAF way!

XAF way



Let me repost the answer my colleague provided  in  the original SC ticket and then elaborate more on the technical aspects of this solution:

We designed the Conditional Appearance module to control various properties of controls and provided implementation for the most useful properties of DevExpress ASP.NET and WinForms controls: Enabled, Visible, BackColor, FontColor and FontStyle. However, there are other controls and properties that can be managed using the Conditional Appearance module capabilities. 
We reviewed our implementation and made a few changes in our code to support new properties, so you can request a hotfix right now, and we will publish it for you. This change will be included into the next public release/update for the 14.2 release.
The attached project demonstrates how to introduce an additional string value to the 'AppearanceAttribute' class and apply this string to the ASPxGridView cell as a tooltip in accordance with the Conditional Appearance rules. Note that other controls and properties may require other code to show a specified string as a tooltip. Please review the corresponding documentation for a necessary control for more details on how to implement this scenario.

Technical details

Solution26.Module:
AppearanceWithToolTipAttribute.cs - contains a definition of an AppearanceAttribute descendant with a custom ToolTip property (its sample use is shown in the Class1.cs file) as well as several required service classes to propagate this new option through the Application Model and the whole ConditionalAppearance module infrastructure. For instance, the AppearanceItemToolTip class is an AppearanceItemBase descendant that serves the same role as AppearanceItemEnabled, AppearanceItemFontColor and other built-in implementations (here it solely holds a tooltip value). 

The IModelAppearanceWithToolTipRule interface and its domain logic define a custom Application Model element that extends the built-in IModelAppearanceRule with the ToolTip property (see the Module.cs file for the registration code).

Finally, the ToolTipAppearanceRule class is a descendant of the service AppearanceRule class with a single overridden method that instantiates AppearanceItemToolTip objects for IModelAppearanceWithToolTipRule nodes defined by a user in the Application Model.

Solution26.Module.Web:
AppearanceGridViewToolTipController.cs - contains a ViewController that handles the CustomCreateAppearanceRule and ApperanceApplied events of the built-in AppearanceController for connecting rule metadata information with the underlying control customizations. In other words, the information from the AppearanceItemToolTip  entity is propagated to the built-in TableCellAppearanceAdapter object, which represents a precise implementation of the IAppearanceFormat interface (there are various implementations for different UI entities in XAF). Or, simply, a link between the underlying UI control and its TableCell object to which various appearance options (font, color, tooltip) can be applied.

5 comments:

  1. Hello Dennis, nice feature. I tested it and it works fine in your example.

    But when I create an appearance rule without setting the backcolor, the tooltip does not work. So the tooltip only works when also using the existing properties like back and fore color.

    Can you edit your example and make it possible to create and use an appearance rule with only the tooltip filled?

    ReplyDelete
    Replies
    1. Hi Hein, yes, I can replicate this behavior. I will post here once I have a chance to debug this case.

      Delete
    2. Hello Dennis, any progress on this issue?

      Delete
  2. Hi. I need union all ToolTips from all applied [AppearanceWithToolTip] by Priority values order

    For code

    [DefaultClassOptions]
    public class MyPerson : BaseObject {
    public MyPerson(Session session) : base(session) { }
    [AppearanceWithToolTip("MinorAppearance", "[Important] = false", BackColor = "Green", ToolTip = "Minor", Priority = 0)]
    [AppearanceWithToolTip("MinorAppearance2", "[Important] = false", FontStyle = FontStyle.Italic, ToolTip = "Addition tooltip", Priority = 1)]
    public string Name { get { return GetPropertyValue("Name"); } set { SetPropertyValue("Name", value); } }
    public bool Important { get { return GetPropertyValue("Important"); } set { SetPropertyValue("Important", value); } }
    }

    I want see
    "Minor
    Addition tooltip"


    And i need solution for Win

    ReplyDelete