New Script features

7 views
Skip to first unread message

bsorrentino

unread,
Feb 23, 2012, 6:03:40 AM2/23/12
to swixml2-discuss
I've deployed a new experimental release 2.6-SNAPSHOT to test the new
script features

As shown on issue 79 - http://code.google.com/p/swixml2/issues/detail?id=79
i've delivered the feature outlined below

add support for script evaluation in two different way:

script:<attributeName>="<functionName>" ==> use result of script
function <functionName>()
script:<attributeName>="${<script code>}" ==> use result of script
code evaluation

added support of script evaluation for the following attributes' types

* Action
* Border
* Color
* Dimension
* Font
* Image
* ImageIcon
* Insets
* KeyStroke
* Locale
* Point
* Rectangle
* String
* primitive types

a simple example could be found in
http://code.google.com/p/swixml2/source/browse/trunk/examples/showcase/src/main/resources/examples/script/ScriptDialog.xml

ramesh kapa

unread,
Feb 24, 2012, 4:50:00 PM2/24/12
to swixml2-discuss
Hi,
First of all! Thanks u very much for quick action.

I tried this, for regular attributes it is working, but some reason
it is not working with the "action" attribute.

Here is my Swixml descriptor file:
[code]
<panel xmlns="http://www.swixml.org/2007/Swixml"
xmlns:script="http://www.swixml.org/2007/Swixml/script">
<script> <![CDATA[
importClass(org.swixml.test.Messages);
importClass(org.swixml.test.Handler);

var messages = new Messages();
var actionHandler = new Handler();
]]>
</script>
<vbox>
<panel layout="GridLayout(2,2,1,10)"
border="CompoundBorder(EmptyBorder(10,1,10,10),
TitledBorder(Security information))">
<label id="loginLabelId" script:text="$
{messages.loginLabelText()}" />
<textfield id="loginFieldId" columns="15" />

<label id="passwordLabelId" script:text="$
{messages.passwordLabelText()}" />
<passwordField id="passwordFieldId" columns="15" />
</panel>

<box.vstrut height="10" />

<hbox>
<box.glue />
<button id="submitButtonId" script:text="$
{messages.submitLabelText()}" script:action="$
{actionHandler.submit()}" />
<box.hstrut width="5" />
<button id="exitButtonId" script:text="$
{messages.escapeLabelText()}" script:action="${actionHandler.exit()}" /
>
</hbox>

</vbox>
</panel>
[/code]
The script:text attributes are working fine.
But script:action is not causing exception.

Here is the backing class.
[code]
package org.swixml.test.login;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import org.junit.Before;
import org.junit.Test;
import org.swixml.SwingEngine;
import org.swixml.test.Handler;
import org.swixml.test.Messages;

public class loginXmlTest {
private JPanel parent;
private SwingEngine<JPanel> engine;
private static String SWIXML_DESCRIPTOR = "org/swixml/test/login/
login.xml";
private static String LOGIN_LABEL_ID = "loginLabelId";
private static String LOGIN_FIELD_ID = "loginFieldId";
private static String PASSWORD_LABEL_ID = "passwordLabelId";
private static String PASSWORD_FIELD_ID = "passwordFieldId";
private static String SUBMIT_BUTTON_ID = "submitButtonId";
private static String EXIT_BUTTON_ID = "exitButtonId";
private JPanel swixPanel;
private Messages messages;
private Handler handler;

@Before
public void setUp() throws Exception {
parent = new JPanel();
engine = new SwingEngine<JPanel>(parent);
swixPanel = engine.render(SWIXML_DESCRIPTOR);
messages = new Messages();
handler = new Handler();
}


@Test
public void loginLabel() {
JLabel loginLabel = (JLabel) getComponentById(LOGIN_LABEL_ID);

assertNotNull(loginLabel);


assertEquals(messages.loginLabelText(), loginLabel.getText());
}

@Test
public void loginField() {
JTextField loginField = (JTextField)
getComponentById(LOGIN_FIELD_ID);

assertNotNull(loginField);
}

@Test
public void passwordLabel() {
JLabel passwordLabel = (JLabel) getComponentById(PASSWORD_LABEL_ID);

assertNotNull(passwordLabel);
assertEquals(messages.passwordLabelText(), passwordLabel.getText());
}

@Test
public void passwordField() {
JPasswordField passwordField = (JPasswordField)
getComponentById(PASSWORD_FIELD_ID);

assertNotNull(passwordField);
}

@Test
public void submitButtonLabel() {
JButton submitButton = (JButton) getComponentById(SUBMIT_BUTTON_ID);

assertNotNull(submitButton);
assertEquals(messages.submitLabelText(), submitButton.getText());
}

@Test
public void submitActionHandler() {
JButton submitButton = (JButton) getComponentById(SUBMIT_BUTTON_ID);

assertNotNull(submitButton);
// submitButton.doClick();
// assertTrue(handler.isSubmitted());
}

@Test
public void exitActionHandler() {
JButton exitButton = (JButton) getComponentById(EXIT_BUTTON_ID);

assertNotNull(exitButton);
// exitButton.doClick();
// assertTrue(handler.isEscaped());
}

public JPanel getPanel() {
return swixPanel;
}


public static void main(String[] args) {
loginXmlTest loginTest = new loginXmlTest();
try {
loginTest.setUp();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JFrame frame = new JFrame("Login Dialog");
frame.setContentPane(loginTest.getPanel());

frame.setVisible(true);
frame.pack();
}

private JComponent getComponentById(String componentId) {
return (JComponent) engine.find(componentId);
}
}
[/code]

And here are the supporting classes that are accessed in javascript.

[code]
package org.swixml.test;

public class Handler {

private boolean submitted;
private boolean escaped;

public boolean submit() {
submitted = true;
System.out.println("Submitted...");

return submitted;
}

public boolean exit() {
escaped = true;

System.out.println("Exited...");

return escaped;
}

public boolean isSubmitted() {
return submitted;
}

public boolean isEscaped() {
return escaped;
}
}

package org.swixml.test;

public class Messages {

public String loginLabelText() {
return "Login:";
}

public String passwordLabelText() {
return "Password:";
}

public String submitLabelText() {
return "Submit";
}

public String escapeLabelText() {
return "Escape";
}

}
[/code]

No clue what's going on.

Thanks
-Ramesh
On Feb 23, 6:03 am, bsorrentino <bartolomeo.sorrent...@gmail.com>
wrote:
> I've deployed a new experimental release 2.6-SNAPSHOT to test the new
> script features
>
> As shown on issue 79 -http://code.google.com/p/swixml2/issues/detail?id=79
> i've delivered the feature outlined below
>
> add support for script evaluation in two different way:
>
>  script:<attributeName>="<functionName>" ==> use result of script
> function <functionName>()
>  script:<attributeName>="${<script code>}" ==> use result of script
> code evaluation
>
> added support of script evaluation for the following attributes' types
>
> * Action
> * Border
> * Color
> * Dimension
> * Font
> * Image
> * ImageIcon
> * Insets
> * KeyStroke
> * Locale
> * Point
> * Rectangle
> * String
> * primitive types
>
> a simple  example could be found inhttp://code.google.com/p/swixml2/source/browse/trunk/examples/showcas...
Reply all
Reply to author
Forward
0 new messages