Hard-coding the name of the icon in CSS

Article ID: 2452
Last updated: 29 May, 2018
Article ID: 2452
Last updated: 29 May, 2018
Revision: 3
Views: 635
Posted: 11 Sep, 2013
by Dean J.
Updated: 29 May, 2018
by Gargani A.

Question

How to avoid hard-coding the name of the icon in CSS?

Cause

You can't use url() which is a special function that is part of the CSS2 specification: URLs and URIs in CSS2.
It is statically interpreted by the CSS parser when the CSS declaration is initially parsed to construct an absolute path based on the path of the CSS file. Property indirection is evaluated later.

Answer

One possibility is to store the fully qualified path of the icon in your data model. Then you can do:

icon: 
  "@iconFullPath";

If you need to dynamically construct the path to your icon, one possibility is to build this into your graphic object as slowhand suggests. An alternative is to write a CSS function that dynamically computes the icon's full path, using a relative or partial path specified in your data model. Assume you write a CSS function that converts a partial path to a fully qualified path.

public class GetImage
extends IlvCSSFunction

Then you can register the CSS function in the style sheet, via:

StyleSheet {
    functionList:
        "GetImage";
}

and use it like this:

icon:
    '@}getImage(@icon)'

You can find info on custom CSS functions in the documentation at Developing with the JViews Diagrammer SDK > Using CSS syntax in the style sheet > Applying CSS to Java objects > Expressions.

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2452
Last updated: 29 May, 2018
Revision: 3
Views: 635
Posted: 11 Sep, 2013 by Dean J.
Updated: 29 May, 2018 by Gargani A.
Also listed in


Others in this category