summaryrefslogtreecommitdiffstats
path: root/qtjava/designer/juic/java/methods.xsl
blob: c8573a5e2eb04bafd5df6442115ba196d4efbfae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?xml version="1.0" encoding="iso-8859-1"?>
<!--
  ** Author: Marco Ladermann <marco.ladermann@gmx.de>
  ** Date:   Thu Mar 06 16:08:06 CET 2003 @672 /Internet Time/
  ** 
  ** This software is free software. It is released under the terms of the
  ** GNU Lesser General Public Licence (LGPL)
  ** see http://www.gnu.org/copyleft/lesser.html
  **
  ** These stylesheets are distributed in the hope that they will be useful,
  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  -->
<xsl:stylesheet 
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:exsl="http://exslt.org/common"
    xmlns:func="http://exslt.org/functions"
    xmlns:date="http://exslt.org/dates-and-times"
    xmlns:kde="http://kde.org/functions"
    xmlns:java="http://kde.org/java"
 >
    <!--
      ** All methods definitions are in this stylesheet
      -->
    <!--
      ** Put the definition of all needed method
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="putMethods">
        <xsl:param name="data"/>
        <!-- Do we need a uncompress function for Pixmap's ? -->
        <xsl:if test="boolean(//image | //pixmap) and not(/UI/pixmapfunction | /UI/pixmapinproject)">
            <xsl:call-template name="putDecodePixmaps"/>
        </xsl:if>
        <!-- Do we need "polishing" ? -->
        <xsl:if test="//property[@name = 'database']">
            <xsl:call-template name="putPolish"/>
        </xsl:if>
        <!-- The slot for a language change signal -->
        <xsl:call-template name="putLanguageChangeSlot"/>
    </xsl:template>
    <!--
      ** Put the definition of the main method
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="putMain">
        <xsl:param name="data"/>
        <xsl:if test="not($abstract) and $main">

    public static void main(String [] args) {
		<xsl:choose>
		<xsl:when test="$kde">
		TDECmdLineArgs.init( args , "<xsl:value-of select="$mainClass"/>", "<xsl:value-of select="$mainClass"/>", "<xsl:value-of select="java:toJavaString(/UI/widget/property[@name='caption']/string)"/>", "version");
        TDEApplication app = new TDEApplication();
		</xsl:when>
		<xsl:otherwise>
        TQApplication app = new TQApplication(args);
        </xsl:otherwise>
        </xsl:choose>
        <xsl:value-of select="$mainClass"/> myWidget = new <xsl:value-of select="$mainClass"/>();
        app.setMainWidget( myWidget );
        myWidget.show();
        app.exec();
    }</xsl:if>
    </xsl:template>
    

    <xsl:template name="putDecodePixmaps">

    /**
     * decodePixmap extracts a pixmap from coded data
     * @param size of uncompressed data
     * @param code string coded data
     * @param isCompressed need data to be uncompressed
     */
    private static TQPixmap decodePixmap(int size, String code, boolean isCompressed) {
        int len = code.length() >> 1;
        byte [] data = new byte[len];
        try {
            for (int i=0, j=0 ; i &lt; len; ++i, j+=2) {
                data[i] = (byte)Short.parseShort(code.substring(j, j+2), 16);
            }
            if (isCompressed) {
                byte [] pic = new byte [size];
                Inflater inflater = new Inflater();
                pic = new byte [size];
                inflater.setInput(data);
                inflater.inflate(pic, 0, size);
                return new TQPixmap(pic);
            } else {
                return new TQPixmap(data);
            }
        }
        catch (Exception e) {
            System.err.println("Problem, while reading image data: "+e.getMessage());
        }
        return null;
    }
    </xsl:template>
    
    <xsl:template name="putPolish">

    /**
     * polish does some last initialization just before the widget
     * is displayed. Here we setup:
     *   i) databases
     *   ...
     */
    public void polish() {
        <xsl:for-each select="//widget[@class = 'TQDataTable' or @class = 'TQDataBrowser']">
            <xsl:if test="not( property[@name = 'frameworkCode']/bool = 'false' )">
                <xsl:variable name="dataName" select="java:getNodeName(.)"/>
                <xsl:variable name="conn" select="property[@name='database']/stringlist/string[1]"/>
                <xsl:variable name="table" select="property[@name='database']/stringlist/string[2]"/>
                <xsl:choose>
                    <xsl:when test="@class = 'TQDataTable'">
        if ( <xsl:value-of select="$dataName"/> != null ) {
            TQSqlCursor cursor = <xsl:value-of select="$dataName"/>.sqlCursor();
            if ( cursor == null ) {<xsl:choose>
                        <xsl:when test="$conn = '(default)'">
                cursor = new TQSqlCursor( "<xsl:value-of select="$table"/>" );</xsl:when>
                        <xsl:otherwise>
                cursor = new TQSqlCursor( "<xsl:value-of select="$table"/>", true, TQSqlDatabase.database("<xsl:value-of select="$conn"/>") );</xsl:otherwise>
                        </xsl:choose>
                if ( <xsl:value-of select="$dataName"/>.isReadOnly() )
                    cursor.setMode( TQSqlCursor.ReadOnly );
                <xsl:value-of select="$dataName"/>.setSqlCursor( cursor, false, true );
            }
            if ( !cursor.isActive() )
                <xsl:value-of select="$dataName"/>.refresh( TQDataTable.RefreshAll );
        }
                    </xsl:when>
                    <xsl:otherwise>
        if ( <xsl:value-of select="$dataName"/> != null ) {
            if ( <xsl:value-of select="$dataName"/>.sqlCursor() == null ) {<xsl:choose>
                        <xsl:when test="$conn = '(default)'">
                TQSqlCursor cursor = new TQSqlCursor( "<xsl:value-of select="$table"/>" );</xsl:when>
                        <xsl:otherwise>
                TQSqlCursor cursor = new TQSqlCursor( "<xsl:value-of select="$table"/>", true, TQSqlDatabase.database("<xsl:value-of select="$conn"/>") );</xsl:otherwise>
                        </xsl:choose><xsl:text>
                    </xsl:text>
                    <xsl:value-of select="$dataName"/>.setSqlCursor( cursor, true );
                    <xsl:value-of select="$dataName"/>.refresh();
                    <xsl:value-of select="$dataName"/>.first();
            }
        }
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
        </xsl:for-each>
        super.polish();
    }
    </xsl:template>

    <xsl:template name="putLanguageChangeSlot">

    /**
     * TQ_SLOT
     * languageChange sets the strings according to current language
     */
   protected void languageChange() {
        <!-- all "normal" i18n strings -->
        <xsl:for-each select="//*[not(name() = 'item' or name() = 'column' or name() = 'row')]/property/string">
            <xsl:apply-templates select="." mode="property">
                <xsl:with-param name="name" select="../@name"/>
                <xsl:with-param name="data" select="'languageChange'"/>
            </xsl:apply-templates>
        </xsl:for-each>
        <!-- all ListViews -->
        <xsl:for-each select="//widget[item]">
            <xsl:variable name="contName" select="java:getContainerName(.)"/>
            <xsl:for-each select="./column">
                <xsl:value-of select="$nlIndent8"/>
                <xsl:value-of select="$contName"/>
                <xsl:text>.header().setLabel( </xsl:text>
                <xsl:value-of select="position() - 1"/>
                <xsl:text>, </xsl:text>
                <xsl:value-of select="java:tr(kde:isUtf8(property[@name = 'text']/string))"/>
                <xsl:text>( &quot;</xsl:text>
                <xsl:value-of select="java:toJavaString(property[@name = 'text']/string)"/>
                <xsl:text>&quot; ) );</xsl:text>
            </xsl:for-each>
            <xsl:value-of select="$nlIndent8"/>
            <xsl:value-of select="$contName"/>
            <xsl:text>.clear();</xsl:text>
            <xsl:variable name="containerClass">
                <xsl:apply-templates mode="toClass" select="."/>
            </xsl:variable>
            <xsl:for-each select="item">
                <xsl:call-template name="putItemDefinition">
                    <xsl:with-param name="class" select="$containerClass"/>
                    <xsl:with-param name="number" select="position() - 1"/>
                    <!-- xsl:with-param name="data" select=""/ -->
                </xsl:call-template>
            </xsl:for-each>
        </xsl:for-each>
        <!-- all Tables -->
        <xsl:for-each select="//widget[(column or row) and not(item)]">
            <xsl:variable name="table" select="property[@name='name']/cstring"/>
            <xsl:for-each select="column">
                <xsl:value-of select="$nlIndent8"/>
                <xsl:value-of select="$table"/>
                <xsl:choose>
                    <xsl:when test="substring(../@class, 2) = 'ListView'">
                        <xsl:text>.header()</xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text>.horizontalHeader()</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:text>.setLabel( </xsl:text>
                <xsl:value-of select="position() - 1"/>
                <xsl:text>, </xsl:text>
                <xsl:value-of select="java:tr(kde:isUtf8(property[@name='text']/string))"/>
                <xsl:text>( &quot;</xsl:text>
                <xsl:value-of select="java:toJavaString(property[@name='text']/string)"/>
                <xsl:if test="property[@name='image']">
                </xsl:if>
                <xsl:text>&quot; ) );</xsl:text>
            </xsl:for-each>
            <xsl:for-each select="row">
                <xsl:value-of select="$nlIndent8"/>
                <xsl:value-of select="$table"/>
                <xsl:text>.verticalHeader().setLabel( </xsl:text>
                <xsl:value-of select="position() - 1"/>
                <xsl:value-of select="java:tr(kde:isUtf8(property[@name='text']/string))"/>
                <xsl:text>( &quot;</xsl:text>
                <xsl:value-of select="java:toJavaString(property[@name='text']/string)"/>
                <xsl:text>&quot; ) );</xsl:text>
            </xsl:for-each>
        </xsl:for-each>
        <!-- Menubar -->
        <xsl:variable name="menubar" select="/UI/menubar/property[@name='name']/cstring"/>
        <xsl:for-each select="/UI/menubar/item">
            <xsl:variable name="findItem">
                <xsl:value-of select="$menubar"/>
                <xsl:text>.findItem(</xsl:text>
                <xsl:value-of select="position()"/>
                <xsl:text>)</xsl:text>
            </xsl:variable>
            <xsl:value-of select="$nlIndent8"/>
            <xsl:text>if (</xsl:text>
            <xsl:value-of select="$findItem"/>
            <xsl:text> != null)</xsl:text>
            <xsl:value-of select="$nlIndent8"/>
            <xsl:text>    </xsl:text>
            <xsl:value-of select="$findItem"/>
            <xsl:text>.setText( </xsl:text>
            <xsl:value-of select="java:tr(kde:isUtf8(@text))"/>
            <xsl:text>( &quot;</xsl:text>
            <xsl:value-of select="java:toJavaString(@text)"/>
            <xsl:text>&quot; ) );</xsl:text>
        </xsl:for-each>
   }
   </xsl:template>
    
</xsl:stylesheet>