NuttyCoder's profile初级程序员BlogLists Tools Help

Blog


    3/28/2008

    Use XSLT to Dispose Data in Matrix

    Both Matrix and Matrix.Column have a property named "jsxvaluetemplate". The value of this property should be a XSLT. JSX engine transform the CDF with this XSLT. So, sometimes we could dispose data in matrix with this property.

    <xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:choose>
            <xsl:when test="@property1 = 'false' ">
                <span style="width:100%; height:100%; background-color: #FFFFFF; font-weight:bold">
                    <xsl:value-of select="{0}"/>
                </span>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:choose>
                        <xsl:when test="@property2 = 'false' ">
                            <span style="width:100%; height:100%; background-color: #FFFFFF; font-weight:bold">
                                <xsl:value-of select="{0}"/>
                            </span>
                        </xsl:when>
                        <xsl:otherwise>
                            <span style="width:100%; height:100%; background-color: #FFFFFF; font-weight:bold; padding-left:2px; cursor:pointer;cursor:hand; text-decoration:underline; color:blue;" onmousedown="function1('{@property3}');">
                                Remove
                            </span>
                        </xsl:otherwise>
                    </xsl:choose>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    For example, the XSLT above will judge "property1" and "property2", only if they are all true, a "remove" link would be shown. "@property1" is a way to quote property "property1" of the record, while "{@property3}" is another way, in string argument, maybe. (I'm not clear on it now.)

    Sometimes we have to use data in JavaScript, but not only in CDF. In this condition, we could split the XSLT to some joint strings, then save as a JSS record, which is set to be evaluated. So each part of the XSLT could be replace with a section of JavaScript.

    Following is the value of "jsxtext" in a JSS record:

    '<xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform">    <xsl:choose>        <xsl:when test="@property1 = \'false\' ">            <span style="width:100%; height:100%; background-color: #FFFFFF; font-weight:bold">            <xsl:value-of select="{0}"/>            </span>        </xsl:when>        <xsl:otherwise>            <xsl:choose>                <xsl:when test="@property2 = \'false\' ">                    <span style="width:100%; height:100%; background-color: #FFFFFF; font-weight:bold">                        <xsl:value-of select="{0}"/>                    </span>                </xsl:when>                <xsl:otherwise>                    <span style="width:100%; height:100%; background-color: #FFFFFF; font-weight:bold; padding-left:2px; cursor:pointer;cursor:hand; text-decoration:underline; color:' + getDynamicProperty("@addin@Link Color") + '" onmousedown="function1(\'{@property3}\');">                        Remove                    </span>                </xsl:otherwise>            </xsl:choose>        </xsl:otherwise>    </xsl:choose></xsl:template>'

    There are 3 parts in it. The second one is JavaScript code and used for getting data in JS.

    Notify: "'" should be changed to "\'" when in JS string.

    3/26/2008

    用PubSub传递List-Details形式的消息

    List-Details是一种很常见的界面表现形式。页面载入时,List首先被显示。当用户点击某条记录时(或其它动作),该条记录相关的Details显示出来。SPM的某些部分中,PubSub被用来完成List-Details消息的传递。

    例如在Rule Library中(文件位于rule/library/),当用户选择一条记录时,会触发RuleLibMaster中的publishSelect。此函数将必要的信息装入Message并publish。这条消息在RuleLibrary和RuleLibDetail中分别被订阅,他们会先后(?)先后接收到消息。作为顶层框架,RuleLibrary会检查右侧Detail Panel是否已经被载入,如果没有,RuleLibrary会将该Components载入。随后(?)RuleLibDetail会分析Message,并将Message中的Record信息显示在Detail Panel上。

    我在windowShadow的Alert中仿照了Rule Library中的这种处理方式。由List publish消息,顶层框架订阅消息装载Panel,Details Panel订阅消息并显示信息。

    List-Details形式的消息比较单纯,所以直接调用Detail Panel的相关函数并通过参数传递信息并不显得复杂。但是更多时候,PubSub可以使程序逻辑更清晰。从设计的角度看,PubSub机制为不同模块之间实现了更松散的耦合。据说PubSub使用全局变量的设计会消耗更多的内存,是这种方式的一个弊端,及时的unsubscribe也许可以缓解这个问题。