Extending Styles for displaying Attributes

Currently how an attribute and its items are displayed are based on the style (including item views) stored in the View information. For example:

    <View Type="Instanced" Title="General">
      <InstancedAttributes>
        <Att Name="numerics-att" Type="numerics" />
        <Att Name="outputs-att" Type="outputs">
          <ItemViews>
            <View Path="/output-times" ImportFromFile="true" LoadButtonText="Import from File"
              FileFormat="Double" BrowserTitle="Import from Double File"
              ValueSeparator="," CommentChar="#" FileExtensions="Time Files (*.txt *.csv *.dat)"/>
          </ItemViews>
        </Att>
        <Att Name="simulation-control-att" Type="simulation-control" />
      </InstancedAttributes>
    </View>

Shows an Instanced View Description that includes style information for an outputs attribute. This allows the designer to provide customization for attributes displayed within a View.

The downside of this approach is that if you wanted an Attribute to be displayed in two different Views you would have to make sure you copied the style exactly. The other downside is when creating an item’s expression using the attribute editor dialog. Currently there is no way to specify the style for the attribute and if we did, it would have to store under the item referring to it which seems wrong.

Proposed Extension

Create a Style Section inside the View Configuration information. When an attribute is about to be displayed, the View or Editor would first look to see if the it contains a style specification. If it does it would use it (this is the current behavior), but if it doesn’t it would ask the UIManager (eventually it would be the View Manager but thats still a work in progress) to see if it has a Style for the attribute and it did find one it would use it.

Several styles, each with a unique style name, could be registered to the same attribute definition. These styles could then be referenced in a View Configuration. In addition, a default style (Name="") could also be defined. Default styles would not need to be explicitly referenced within a View Configuration.

Styles can also be inherited. If an attribute’s Definition did not have a Style defined but it’s base definition did, then that Style would be applied (this would work with both named and default Styles).

So in the above we would have something like this:

The following is a default style example in XML:

  <!-- Style specifications -->
  <Styles>
    <Att Type="outputs">
      <Style>
        <ItemViews>
          <View Path="/output-times" ImportFromFile="true" LoadButtonText="Import from File"
            FileFormat="Double" BrowserTitle="Import from Double File"
            ValueSeparator="," CommentChar="#" FileExtensions="Time Files (*.txt *.csv *.dat)"/>
        </ItemViews>
      </Style>
    </Att>
  </Styles>

The following shows an example of using a named style:

  <!-- Style specifications -->
  <Styles>
    <Att Type="outputs">
      <Style Name="foo">
        <ItemViews>
          <View Path="/output-times" ImportFromFile="true" LoadButtonText="Import from File"
            FileFormat="Double" BrowserTitle="Import from Double File"
            ValueSeparator="," CommentChar="#" FileExtensions="Time Files (*.txt *.csv *.dat)"/>
        </ItemViews>
      </Style>
    </Att>
  </Styles>
<Views>
    <View Type="Instanced" Title="General">
      <InstancedAttributes>
        <Att Name="outputs-att" Type="outputs" Style="foo"/>
      </InstancedAttributes>
    </View>
</Views>

Comments?

1 Like

@johnt @chart3388 @amuhsin FYI

+1 for the feature. We can really use ItemViews in the attribute editor dialog.

+1 from me too.

The only thing I would consider is a way to enable multiple styles for the same attribute def to add more flexibility.

Maybe something like this:

  <Styles>
    <Att Type="outputs">
      <Style Name="style1">
        <ItemViews>
          <View Path="/output-times" ImportFromFile="true" LoadButtonText="Import from File"
                FileFormat="Double" BrowserTitle="Import from Double File"
                ValueSeparator="," CommentChar="#" FileExtensions="Time Files (*.txt *.csv *.dat)"/>
        </ItemViews>
      </Style>
      <Style Name="style2">
        <ItemViews>
          <View Path="/output-times" ReadOnly="true"/>
        </ItemViews>
      </Style>
    </Att>
  </Styles>

  <Views>
    <View Type="Instanced" Title="General">
      <InstancedAttributes>
        <Att Name="numerics-att" Type="numerics" />
        <Att Name="outputs-att" Type="outputs" Style="style1">
        <Att Name="simulation-control-att" Type="simulation-control" />
      </InstancedAttributes>
    </View>
    <View Type="Instanced" Title="Custom">
      <InstancedAttributes>
        <Att Name="numerics-att" Type="numerics" />
        <Att Name="outputs-att" Type="outputs" Style="style2">
        <Att Name="simulation-control-att" Type="simulation-control" />
      </InstancedAttributes>
    </View>
  </Views>

My primary use case has a bunch of function definitions that all have the same base definition and structure, and I want to apply the same style to them in both attribute views and attribute editor dialogs. (The particular item view being the new “load from file” feature Bob just added.)

With the original/proposed approach, I need to specify a separate style for each individual definition, but in the attribute view I only need to call out the base definition type. If instead styles are named, then I would need to not only create separate style for each definition, but I would also need to enumerate each definition in the attribute view in order to reference the style name.

If we are going to support multiple styles, could we consider some options to reduce duplication for my use case, for example

  • Can we designate a default style that would not have to be explicitly referenced it in the attribute view?

  • Or can we make styles generic, that is, not specified to any particular definition. That would let me create a single style element that I could then reference to each of the enumerated types in my attribute views?

+1 I think that will be useful.

I imagine that this would only be possible for attributes that have the same structure since we’re using item paths.

Can the alternative be to allow base definition support for ItemViews and Styles? We can compliment that by allowing sub definitions to override their base definition style specification.

So for your use-case you can assign a style to the base definition and specify that style name in the attribute view where the base definition is already used. We can avoid specifying the style name by adding the ability to specify a default style like you suggested.

Furthermore, if one of your sub definitions needs to deviate from that base definition style spec all it needs is its own style in the styles section. Depending on whether or not we have default styles you may not even need to add anything to the attribute view.