You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/09/26 16:32:23 UTC

svn commit: r819142 - in /incubator/pivot/trunk: demos/src/org/apache/pivot/demos/itunes/ demos/src/org/apache/pivot/demos/scripting/ tools/src/org/apache/pivot/tools/json/ tutorials/src/org/apache/pivot/tutorials/layout/ tutorials/src/org/apache/pivot...

Author: gbrown
Date: Sat Sep 26 14:32:21 2009
New Revision: 819142

URL: http://svn.apache.org/viewvc?rev=819142&view=rev
Log:
Revert change that eliminated need for <wtkx:script> tag in element listener lists; specify script language in <wtkx:script> tag or using XML processing instruction instead of in WTKXSerializer constructor argument.

Modified:
    incubator/pivot/trunk/demos/src/org/apache/pivot/demos/itunes/search_demo.wtkx
    incubator/pivot/trunk/demos/src/org/apache/pivot/demos/scripting/scripting_demo.wtkx
    incubator/pivot/trunk/tools/src/org/apache/pivot/tools/json/json_viewer.wtkx
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/table_panes.wtkx
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/table_panes_configure_cell.wtkx
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/table_panes_configure_column.wtkx
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/table_panes_configure_row.wtkx
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/tableviews/custom_table_view.wtkx
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/tableviews/json_table_view.wtkx
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/frame.wtkx
    incubator/pivot/trunk/tutorials/www/windows.template.html
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/application_handler_test.wtkx
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.wtkx
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/watermark_decorator_test.wtkx

Modified: incubator/pivot/trunk/demos/src/org/apache/pivot/demos/itunes/search_demo.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/src/org/apache/pivot/demos/itunes/search_demo.wtkx?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/pivot/trunk/demos/src/org/apache/pivot/demos/scripting/scripting_demo.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/src/org/apache/pivot/demos/scripting/scripting_demo.wtkx?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/pivot/trunk/tools/src/org/apache/pivot/tools/json/json_viewer.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tools/src/org/apache/pivot/tools/json/json_viewer.wtkx?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/table_panes.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/table_panes.wtkx?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/table_panes_configure_cell.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/table_panes_configure_cell.wtkx?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/table_panes_configure_column.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/table_panes_configure_column.wtkx?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/table_panes_configure_row.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/table_panes_configure_row.wtkx?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/tableviews/custom_table_view.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/tableviews/custom_table_view.wtkx?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/tableviews/json_table_view.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/tableviews/json_table_view.wtkx?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/frame.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/frame.wtkx?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/frame.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/frame.wtkx Sat Sep 26 14:32:21 2009
@@ -22,5 +22,32 @@
     xmlns:content="org.apache.pivot.wtk.content"
     xmlns="org.apache.pivot.wtk">
     <content>
+        <BoxPane orientation="vertical">
+            <PushButton buttonData="Show Alert">
+                <buttonPressListeners>
+                    <wtkx:script>
+                    <![CDATA[
+                    importPackage(org.apache.pivot.wtk);
+                    function buttonPressed(button) {
+                        Alert.alert("This is an Alert.", button.getWindow());
+                    }
+                    ]]>
+                    </wtkx:script>
+                </buttonPressListeners>
+            </PushButton>
+
+            <PushButton buttonData="Show Prompt">
+                <buttonPressListeners>
+                    <wtkx:script>
+                    <![CDATA[
+                    importPackage(org.apache.pivot.wtk);
+                    function buttonPressed(button) {
+                        Prompt.prompt("This is a Prompt.", button.getWindow());
+                    }
+                    ]]>
+                    </wtkx:script>
+                </buttonPressListeners>
+            </PushButton>
+        </BoxPane>
     </content>
 </Frame>

Modified: incubator/pivot/trunk/tutorials/www/windows.template.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/windows.template.html?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/windows.template.html (original)
+++ incubator/pivot/trunk/tutorials/www/windows.template.html Sat Sep 26 14:32:21 2009
@@ -65,9 +65,7 @@
 prompt
 modal dialog
 sheet
-file browser sheet
 palette
-menu popup
 tooltip
 
 </body>

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java Sat Sep 26 14:32:21 2009
@@ -574,9 +574,6 @@
             Vote vote = windowStateListeners.previewWindowOpen(this, display);
 
             if (vote == Vote.APPROVE) {
-                // Add the window to the display
-                display.add(this);
-
                 // Set the owner and add to the owner's owned window list
                 this.owner = owner;
 
@@ -584,6 +581,9 @@
                     owner.ownedWindows.add(this);
                 }
 
+                // Add the window to the display
+                display.add(this);
+
                 // Notify listeners
                 opening = false;
                 windowStateListeners.windowOpened(this);

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java Sat Sep 26 14:32:21 2009
@@ -124,7 +124,7 @@
             if (descendant != container) {
                 Window window = descendant.getWindow();
 
-                if (window.isOwner(sheet)) {
+                if (sheet.getOwner() == window) {
                     Bounds clientArea = window.getClientArea();
 
                     Point location = window.mapPointFromAncestor(container, x, y);

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java Sat Sep 26 14:32:21 2009
@@ -273,11 +273,8 @@
         }
     }
 
-    private Resources resources;
-    private String language;
-    private XMLInputFactory xmlInputFactory;
-
     private URL location = null;
+    private Resources resources = null;
     private HashMap<String, Object> initialBindings = new HashMap<String, Object>();
 
     private Object root = null;
@@ -285,49 +282,38 @@
     private HashMap<String, WTKXSerializer> includeSerializers = new HashMap<String, WTKXSerializer>();
 
     private ScriptEngineManager scriptEngineManager = null;
+    private String language = "javascript";
 
+    private XMLInputFactory xmlInputFactory;
     private Element element = null;
 
     public static final char URL_PREFIX = '@';
     public static final char RESOURCE_KEY_PREFIX = '%';
     public static final char OBJECT_REFERENCE_PREFIX = '$';
 
+    public static final String LANGUAGE_PROCESSING_INSTRUCTION = "language";
+
     public static final String WTKX_PREFIX = "wtkx";
     public static final String ID_ATTRIBUTE = "id";
 
     public static final String INCLUDE_TAG = "include";
     public static final String INCLUDE_SRC_ATTRIBUTE = "src";
     public static final String INCLUDE_RESOURCES_ATTRIBUTE = "resources";
-    public static final String INCLUDE_LANGUAGE_ATTRIBUTE = "language";
 
     public static final String SCRIPT_TAG = "script";
     public static final String SCRIPT_SRC_ATTRIBUTE = "src";
+    public static final String SCRIPT_LANGUAGE_ATTRIBUTE = "language";
 
     public static final String DEFINE_TAG = "define";
 
     public static final String MIME_TYPE = "application/wtkx";
 
-    public static final String DEFAULT_LANGUAGE = "javascript";
-
     public WTKXSerializer() {
-        this(null, DEFAULT_LANGUAGE);
+        this(null);
     }
 
     public WTKXSerializer(Resources resources) {
-        this(resources, DEFAULT_LANGUAGE);
-    }
-
-    public WTKXSerializer(String language) {
-        this(null, language);
-    }
-
-    public WTKXSerializer(Resources resources, String language) {
-        if (language == null) {
-            throw new IllegalArgumentException();
-        }
-
         this.resources = resources;
-        this.language = language;
 
         xmlInputFactory = XMLInputFactory.newInstance();
         xmlInputFactory.setProperty("javax.xml.stream.isCoalescing", true);
@@ -424,6 +410,17 @@
                     int event = reader.next();
 
                     switch (event) {
+                        case XMLStreamConstants.PROCESSING_INSTRUCTION: {
+                            String piTarget = reader.getPITarget();
+                            String piData = reader.getPIData();
+
+                            if (piTarget.equals(LANGUAGE_PROCESSING_INSTRUCTION)) {
+                                language = piData;
+                            }
+
+                            break;
+                        }
+
                         case XMLStreamConstants.CHARACTERS: {
                             if (!reader.isWhiteSpace()) {
                                 String text = reader.getText();
@@ -451,52 +448,6 @@
                                             break;
                                         }
 
-                                        case READ_ONLY_PROPERTY: {
-                                            if (element.value instanceof ListenerList<?>) {
-                                                // Don't pollute the engine namespace with the listener functions
-                                                ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(language);
-                                                scriptEngine.setBindings(new SimpleBindings(), ScriptContext.ENGINE_SCOPE);
-
-                                                // Execute the script
-                                                try {
-                                                    scriptEngine.eval(text);
-                                                } catch (ScriptException exception) {
-                                                    System.err.println(exception);
-                                                    System.err.println(text);
-                                                }
-
-                                                Class<?> listenerListClass = element.value.getClass();
-
-                                                java.lang.reflect.Type[] genericInterfaces = listenerListClass.getGenericInterfaces();
-                                                Class<?> listenerClass = (Class<?>)genericInterfaces[0];
-
-                                                // Create an invocation handler for this listener
-                                                ElementInvocationHandler handler = new ElementInvocationHandler(scriptEngine);
-                                                Object listener =
-                                                    Proxy.newProxyInstance(ThreadUtilities.getClassLoader(),
-                                                        new Class[]{listenerClass}, handler);
-
-                                                // Add it to the listener list
-                                                Method addMethod;
-                                                try {
-                                                    addMethod = listenerListClass.getMethod("add",
-                                                        new Class<?>[] {Object.class});
-                                                } catch (NoSuchMethodException exception) {
-                                                    throw new RuntimeException(exception);
-                                                }
-
-                                                try {
-                                                    addMethod.invoke(element.value, new Object[] {listener});
-                                                } catch (IllegalAccessException exception) {
-                                                    throw new SerializationException(exception);
-                                                } catch (InvocationTargetException exception) {
-                                                    throw new SerializationException(exception);
-                                                }
-                                            }
-
-                                            break;
-                                        }
-
                                         case SCRIPT:
                                         case WRITABLE_PROPERTY: {
                                             element.value = text;
@@ -648,7 +599,6 @@
                                         // and static property setters only
                                         String src = null;
                                         Resources resources = this.resources;
-                                        String language = this.language;
 
                                         for (Attribute attribute : element.attributes) {
                                             if (attribute.prefix != null
@@ -664,8 +614,6 @@
                                                     src = attribute.value;
                                                 } else if (attribute.localName.equals(INCLUDE_RESOURCES_ATTRIBUTE)) {
                                                     resources = new Resources(resources, attribute.value);
-                                                } else if (attribute.localName.equals(INCLUDE_LANGUAGE_ATTRIBUTE)) {
-                                                    language = attribute.value;
                                                 } else {
                                                     if (!Character.isUpperCase(attribute.localName.charAt(0))) {
                                                         throw new SerializationException("Instance property setters are not"
@@ -685,7 +633,7 @@
                                         }
 
                                         // Read the object
-                                        WTKXSerializer serializer = new WTKXSerializer(resources, language);
+                                        WTKXSerializer serializer = new WTKXSerializer(resources);
                                         if (id != null) {
                                             includeSerializers.put(id, serializer);
                                         }
@@ -911,6 +859,7 @@
                                 case SCRIPT: {
                                     // Process attributes looking for src and language
                                     String src = null;
+                                    String language = this.language;
                                     for (Attribute attribute : element.attributes) {
                                         if (attribute.prefix != null
                                             && attribute.prefix.length() > 0) {
@@ -921,24 +870,43 @@
 
                                         if (attribute.localName.equals(SCRIPT_SRC_ATTRIBUTE)) {
                                             src = attribute.value;
+                                        } else if (attribute.localName.equals(SCRIPT_LANGUAGE_ATTRIBUTE)) {
+                                            language = attribute.value;
                                         } else {
                                             throw new SerializationException(attribute.localName + " is not a valid"
                                                 + " attribute for the " + WTKX_PREFIX + ":" + SCRIPT_TAG + " tag.");
                                         }
                                     }
 
-                                    if (element.value != null
-                                        && language == null) {
-                                        language = "javascript";
+                                    Bindings bindings;
+                                    if (element.parent.value instanceof ListenerList<?>) {
+                                        // Don't pollute the engine namespace with the listener functions
+                                        bindings = new SimpleBindings();
+                                    } else {
+                                        bindings = scriptEngineManager.getBindings();
                                     }
 
                                     // Execute script
-                                    ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(language);
-                                    scriptEngine.setBindings(scriptEngineManager.getBindings(),
-                                        ScriptContext.ENGINE_SCOPE);
+                                    final ScriptEngine scriptEngine;
 
                                     if (src != null) {
                                         // The script is located in an external file
+                                        int i = src.lastIndexOf(".");
+                                        if (i == -1) {
+                                            throw new SerializationException("Cannot determine type of script \""
+                                                + src + "\".");
+                                        }
+
+                                        String extension = src.substring(i + 1);
+                                        scriptEngine = scriptEngineManager.getEngineByExtension(extension);
+
+                                        if (scriptEngine == null) {
+                                            throw new SerializationException("Unable to find scripting engine for"
+                                                + " extension " + extension + ".");
+                                        }
+
+                                        scriptEngine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
+
                                         try {
                                             URL scriptLocation;
                                             if (src.charAt(0) == '/') {
@@ -964,16 +932,54 @@
                                         }
                                     } else {
                                         // The script is inline
+                                        scriptEngine = scriptEngineManager.getEngineByName(language);
+
+                                        if (scriptEngine == null) {
+                                            throw new SerializationException("Unable to find scripting engine for"
+                                                + " language \"" + language + "\".");
+                                        }
+
+                                        scriptEngine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
+
                                         if (element.value != null) {
                                             try {
                                                 scriptEngine.eval((String)element.value);
                                             } catch (ScriptException exception) {
-                                                System.err.println(exception);
-                                                System.err.println(element.value);
+                                                exception.printStackTrace(System.err);
                                             }
                                         }
                                     }
 
+                                    if (element.parent.value instanceof ListenerList<?>) {
+                                        // Create the listener and add it to the list
+                                        Class<?> listenerListClass = element.parent.value.getClass();
+
+                                        java.lang.reflect.Type[] genericInterfaces = listenerListClass.getGenericInterfaces();
+                                        Class<?> listenerClass = (Class<?>)genericInterfaces[0];
+
+                                        ElementInvocationHandler handler = new ElementInvocationHandler(scriptEngine);
+
+                                        Method addMethod;
+                                        try {
+                                            addMethod = listenerListClass.getMethod("add",
+                                                new Class<?>[] {Object.class});
+                                        } catch (NoSuchMethodException exception) {
+                                            throw new RuntimeException(exception);
+                                        }
+
+                                        Object listener =
+                                            Proxy.newProxyInstance(ThreadUtilities.getClassLoader(),
+                                                new Class[]{listenerClass}, handler);
+
+                                        try {
+                                            addMethod.invoke(element.parent.value, new Object[] {listener});
+                                        } catch (IllegalAccessException exception) {
+                                            throw new SerializationException(exception);
+                                        } catch (InvocationTargetException exception) {
+                                            throw new SerializationException(exception);
+                                        }
+                                    }
+
                                     break;
                                 }
 

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/application_handler_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/application_handler_test.wtkx?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.wtkx?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/watermark_decorator_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/watermark_decorator_test.wtkx?rev=819142&r1=819141&r2=819142&view=diff
==============================================================================
Binary files - no diff available.