Buix-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
July 2009
- 3 participants
- 68 discussions
r1507 - in trunk/guix-test-swing: . src/main/java/org/nuiton/guix src/main/java/org/nuiton/guix/demo
by kmorin@users.labs.libre-entreprise.org 22 Jul '09
by kmorin@users.labs.libre-entreprise.org 22 Jul '09
22 Jul '09
Author: kmorin
Date: 2009-07-22 15:10:33 +0200 (Wed, 22 Jul 2009)
New Revision: 1507
Added:
trunk/guix-test-swing/nbactions.xml
trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/Controller.java
Removed:
trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo.java
trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo2.java
trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo2Abstract.java
trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo2Impl.java
trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo3.java
trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo3Abstract.java
trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo3Impl.java
trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemoAbstract.java
trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemoImpl.java
trunk/guix-test-swing/src/main/java/org/nuiton/guix/Main.java
Modified:
trunk/guix-test-swing/pom.xml
trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.guix
Log:
example with the binding
Added: trunk/guix-test-swing/nbactions.xml
===================================================================
--- trunk/guix-test-swing/nbactions.xml (rev 0)
+++ trunk/guix-test-swing/nbactions.xml 2009-07-22 13:10:33 UTC (rev 1507)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<actions>
+ <action>
+ <actionName>run</actionName>
+ <packagings>
+ <packaging>jar</packaging>
+ </packagings>
+ <goals>
+ <goal>process-classes</goal>
+ <goal>org.codehaus.mojo:exec-maven-plugin:1.1:exec</goal>
+ </goals>
+ <properties>
+ <exec.args>-classpath %classpath org.nuiton.guix.Main</exec.args>
+ <exec.executable>java</exec.executable>
+ </properties>
+ </action>
+ </actions>
Modified: trunk/guix-test-swing/pom.xml
===================================================================
--- trunk/guix-test-swing/pom.xml 2009-07-22 13:09:22 UTC (rev 1506)
+++ trunk/guix-test-swing/pom.xml 2009-07-22 13:10:33 UTC (rev 1507)
@@ -39,6 +39,14 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
+
+ <!-- sibiling dependencies -->
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>guix-runtime-swing</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
@@ -55,12 +63,36 @@
<packaging>jar</packaging>
+ <properties>
+ <maven.jar.main.class>org.nuiton.guix.Main</maven.jar.main.class>
+ </properties>
+
+
<!-- ************************************************************* -->
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
-
+
+
+
<build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ <classpathPrefix>./lib/</classpathPrefix>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+
+ </plugins>
+
+ </pluginManagement>
<plugins>
<plugin>
Deleted: trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo.java
===================================================================
--- trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo.java 2009-07-22 13:09:22 UTC (rev 1506)
+++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo.java 2009-07-22 13:10:33 UTC (rev 1507)
@@ -1,87 +0,0 @@
-package org.nuiton.guix;
-
-import javax.swing.JMenuBar;
-import javax.swing.JMenu;
-import javax.swing.JMenuItem;
-import javax.swing.JToolBar;
-import javax.swing.JButton;
-import javax.swing.JTabbedPane;
-import javax.swing.JPanel;
-import javax.swing.JTextField;
-import javax.swing.JLabel;
-import org.nuiton.guix.GuixDemo3Abstract;
-import org.nuiton.guix.GuixDemo2Abstract;
-
-/**
- * test javadoc Application
- */
-public interface GuixDemo {
- /*---------------------------------------------------------------------------------*/
- /*-- public acessor methods -------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public JToolBar get$JToolBar5();
-
- public GuixDemo3Abstract getBt3();
-
- public GuixDemo3Abstract getBt31();
-
- public GuixDemo3Abstract getBt32();
-
- public GuixDemo3Abstract getBt34();
-
- public GuixDemo2Abstract getGd2();
-
- public javax.swing.JPanel getTable();
-
- /*---------------------------------------------------------------------------------*/
- /*-- public mutator methods -------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public void set$JToolBar5(JToolBar newValue);
-
- public void setBt3(GuixDemo3Abstract newValue);
-
- public void setBt31(GuixDemo3Abstract newValue);
-
- public void setBt32(GuixDemo3Abstract newValue);
-
- public void setBt34(GuixDemo3Abstract newValue);
-
- public void setGd2(GuixDemo2Abstract newValue);
-
- public void setTable(javax.swing.JPanel newValue);
-
- /*---------------------------------------------------------------------------------*/
- /*-- public mutator methods -------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public void beforeBinding();
-
- public void beforeCreation();
-
- public void beforeInitialization();
-
- /**
- * Components creation
- */
- public void componentsCreation();
-
- /**
- * components layout
- */
- public void componentsTree();
-
- public void inTheEnd();
-
- /**
- * initilization of databinding
- */
- public void initDataBinding();
-
- /**
- * initialization
- */
- public void initialize();
-
-}
\ No newline at end of file
Deleted: trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo2.java
===================================================================
--- trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo2.java 2009-07-22 13:09:22 UTC (rev 1506)
+++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo2.java 2009-07-22 13:10:33 UTC (rev 1507)
@@ -1,41 +0,0 @@
-package org.nuiton.guix;
-
-import javax.swing.JToggleButton;
-
-/**
- * test javadoc Application
- */
-public interface GuixDemo2 {
- /*---------------------------------------------------------------------------------*/
- /*-- public mutator methods -------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public void beforeBinding();
-
- public void beforeCreation();
-
- public void beforeInitialization();
-
- /**
- * Components creation
- */
- public void componentsCreation();
-
- /**
- * components layout
- */
- public void componentsTree();
-
- public void inTheEnd();
-
- /**
- * initilization of databinding
- */
- public void initDataBinding();
-
- /**
- * initialization
- */
- public void initialize();
-
-}
\ No newline at end of file
Deleted: trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo2Abstract.java
===================================================================
--- trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo2Abstract.java 2009-07-22 13:09:22 UTC (rev 1506)
+++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo2Abstract.java 2009-07-22 13:10:33 UTC (rev 1507)
@@ -1,127 +0,0 @@
-package org.nuiton.guix;
-
-import javax.swing.JToggleButton;
-
-/**
- * test javadoc Application
- */
-public abstract class GuixDemo2Abstract extends javax.swing.JPanel implements GuixDemo2 {
- /**
- * bindingGroup for databinding
- */
- private org.jdesktop.beansbinding.BindingGroup bindingGroup;
- /**
- * test javadoc Application
- */
- private JToggleButton button;
-
- /*---------------------------------------------------------------------------------*/
- /*-- Constructors -----------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- /**
- * Constructor
- */
- public GuixDemo2Abstract() {
- initialize();
- }
-
- /*---------------------------------------------------------------------------------*/
- /*-- public acessor methods -------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public org.jdesktop.beansbinding.BindingGroup getBindingGroup() {
- return bindingGroup;
- }
-
- public JToggleButton getButton() {
- return button;
- }
-
- /*---------------------------------------------------------------------------------*/
- /*-- public mutator methods -------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public void setBindingGroup(org.jdesktop.beansbinding.BindingGroup newValue) {
- this.bindingGroup = newValue;
- }
-
- public void setButton(JToggleButton newValue) {
- this.button = newValue;
- }
-
- /*---------------------------------------------------------------------------------*/
- /*-- public mutator methods -------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public void beforeBinding() {
-
- }
-
- public void beforeCreation() {
-
- }
-
- public void beforeInitialization() {
-
- }
-
- /**
- * Components creation
- */
- public void componentsCreation() {
- createButton();
- }
-
- /**
- * components layout
- */
- public void componentsTree() {
- this.setLayout(new java.awt.FlowLayout());
- this.add(button);
- }
-
- public void inTheEnd() {
-
- }
-
- /**
- * initilization of databinding
- */
- public void initDataBinding() {
- bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
- }
-
- /**
- * initialization
- */
- public void initialize() {
- beforeCreation();
- componentsCreation();
-
- beforeInitialization();
- componentsTree();
- beforeBinding();
- initDataBinding();
- inTheEnd();
- }
-
- /*---------------------------------------------------------------------------------*/
- /*-- ui creation methods ----------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- /**
- * button creation
- */
- private void createButton() {
- button = new JToggleButton();
- button.setText("Push me");
- button.setSelected(true);
- button.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent actionEvent){
- System.out.println("test");
- }
- });
- }
-
-}
\ No newline at end of file
Deleted: trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo2Impl.java
===================================================================
--- trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo2Impl.java 2009-07-22 13:09:22 UTC (rev 1506)
+++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo2Impl.java 2009-07-22 13:10:33 UTC (rev 1507)
@@ -1,20 +0,0 @@
-package org.nuiton.guix;
-
-import javax.swing.JToggleButton;
-
-/**
- * test javadoc Application
- */
-public class GuixDemo2Impl extends GuixDemo2Abstract {
- /*---------------------------------------------------------------------------------*/
- /*-- Constructors -----------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- /**
- * Constructor
- */
- public GuixDemo2Impl() {
- super();
- }
-
-}
\ No newline at end of file
Deleted: trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo3.java
===================================================================
--- trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo3.java 2009-07-22 13:09:22 UTC (rev 1506)
+++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo3.java 2009-07-22 13:10:33 UTC (rev 1507)
@@ -1,39 +0,0 @@
-package org.nuiton.guix;
-
-/**
- * test javadoc Application
- */
-public interface GuixDemo3 {
- /*---------------------------------------------------------------------------------*/
- /*-- public mutator methods -------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public void beforeBinding();
-
- public void beforeCreation();
-
- public void beforeInitialization();
-
- /**
- * Components creation
- */
- public void componentsCreation();
-
- /**
- * components layout
- */
- public void componentsTree();
-
- public void inTheEnd();
-
- /**
- * initilization of databinding
- */
- public void initDataBinding();
-
- /**
- * initialization
- */
- public void initialize();
-
-}
\ No newline at end of file
Deleted: trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo3Abstract.java
===================================================================
--- trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo3Abstract.java 2009-07-22 13:09:22 UTC (rev 1506)
+++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo3Abstract.java 2009-07-22 13:10:33 UTC (rev 1507)
@@ -1,95 +0,0 @@
-package org.nuiton.guix;
-
-/**
- * test javadoc Application
- */
-public abstract class GuixDemo3Abstract extends javax.swing.JButton implements GuixDemo3 {
- /**
- * bindingGroup for databinding
- */
- private org.jdesktop.beansbinding.BindingGroup bindingGroup;
-
- /*---------------------------------------------------------------------------------*/
- /*-- Constructors -----------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- /**
- * Constructor
- */
- public GuixDemo3Abstract() {
- initialize();
- }
-
- /*---------------------------------------------------------------------------------*/
- /*-- public acessor methods -------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public org.jdesktop.beansbinding.BindingGroup getBindingGroup() {
- return bindingGroup;
- }
-
- /*---------------------------------------------------------------------------------*/
- /*-- public mutator methods -------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public void setBindingGroup(org.jdesktop.beansbinding.BindingGroup newValue) {
- this.bindingGroup = newValue;
- }
-
- /*---------------------------------------------------------------------------------*/
- /*-- public mutator methods -------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public void beforeBinding() {
-
- }
-
- public void beforeCreation() {
-
- }
-
- public void beforeInitialization() {
-
- }
-
- /**
- * Components creation
- */
- public void componentsCreation() {
-
- }
-
- /**
- * components layout
- */
- public void componentsTree() {
- this.setText("GuixDemo3");
- this.setLayout(new java.awt.FlowLayout());
- }
-
- public void inTheEnd() {
-
- }
-
- /**
- * initilization of databinding
- */
- public void initDataBinding() {
- bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
- }
-
- /**
- * initialization
- */
- public void initialize() {
- beforeCreation();
- componentsCreation();
-
- beforeInitialization();
- componentsTree();
- beforeBinding();
- initDataBinding();
- inTheEnd();
- }
-
-}
\ No newline at end of file
Deleted: trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo3Impl.java
===================================================================
--- trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo3Impl.java 2009-07-22 13:09:22 UTC (rev 1506)
+++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemo3Impl.java 2009-07-22 13:10:33 UTC (rev 1507)
@@ -1,18 +0,0 @@
-package org.nuiton.guix;
-
-/**
- * test javadoc Application
- */
-public class GuixDemo3Impl extends GuixDemo3Abstract {
- /*---------------------------------------------------------------------------------*/
- /*-- Constructors -----------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- /**
- * Constructor
- */
- public GuixDemo3Impl() {
- super();
- }
-
-}
\ No newline at end of file
Deleted: trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemoAbstract.java
===================================================================
--- trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemoAbstract.java 2009-07-22 13:09:22 UTC (rev 1506)
+++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemoAbstract.java 2009-07-22 13:10:33 UTC (rev 1507)
@@ -1,566 +0,0 @@
-package org.nuiton.guix;
-
-import javax.swing.JMenuBar;
-import javax.swing.JMenu;
-import javax.swing.JMenuItem;
-import javax.swing.JToolBar;
-import javax.swing.JButton;
-import javax.swing.JTabbedPane;
-import javax.swing.JPanel;
-import javax.swing.JTextField;
-import javax.swing.JLabel;
-import org.nuiton.guix.GuixDemo3Abstract;
-import org.nuiton.guix.GuixDemo2Abstract;
-import java.awt.Button;
-import java.awt.event.ActionListener;
-import java.awt.event.ActionEvent;
-import java.awt.BorderLayout;
-
-/**
- * test javadoc Application
- */
-public abstract class GuixDemoAbstract extends javax.swing.JFrame implements GuixDemo {
- private JButton $Button6;
- private JButton $Button7;
- private JButton $Button8;
- private JToolBar $JToolBar5;
- private JMenu $Menu2;
- private JMenu $Menu4;
- private JMenuBar $MenuBar1;
- private JMenuItem $MenuItem3;
- private JTabbedPane $TabPanel9;
- /**
- * bindingGroup for databinding
- */
- private org.jdesktop.beansbinding.BindingGroup bindingGroup;
- private GuixDemo3Abstract bt3;
- private GuixDemo3Abstract bt31;
- private GuixDemo3Abstract bt32;
- private GuixDemo3Abstract bt34;
- private GuixDemo2Abstract gd2;
- private JMenuItem item1;
- private JLabel label;
- private JLabel label2;
- private JLabel label3;
- private JPanel table;
- /**
- * javadoc textfield
- */
- private JTextField textfield;
-
- /* begin raw body code */
- private Button b = new Button("test");
- public enum Day {
- SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
- THURSDAY, FRIDAY, SATURDAY
- }
- /* end raw body code */
- /*---------------------------------------------------------------------------------*/
- /*-- Statics methods --------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public static void testSameName() {
- System.out.println("load the script file with the same name");
- }
-
- /*---------------------------------------------------------------------------------*/
- /*-- Constructors -----------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- /**
- * Constructor
- */
- public GuixDemoAbstract() {
- initialize();
- }
-
- /*---------------------------------------------------------------------------------*/
- /*-- public acessor methods -------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public JButton get$Button6() {
- return $Button6;
- }
-
- public JButton get$Button7() {
- return $Button7;
- }
-
- public JButton get$Button8() {
- return $Button8;
- }
-
- public JToolBar get$JToolBar5() {
- return $JToolBar5;
- }
-
- public JMenu get$Menu2() {
- return $Menu2;
- }
-
- public JMenu get$Menu4() {
- return $Menu4;
- }
-
- public JMenuBar get$MenuBar1() {
- return $MenuBar1;
- }
-
- public JMenuItem get$MenuItem3() {
- return $MenuItem3;
- }
-
- public JTabbedPane get$TabPanel9() {
- return $TabPanel9;
- }
-
- public org.jdesktop.beansbinding.BindingGroup getBindingGroup() {
- return bindingGroup;
- }
-
- public GuixDemo3Abstract getBt3() {
- return bt3;
- }
-
- public GuixDemo3Abstract getBt31() {
- return bt31;
- }
-
- public GuixDemo3Abstract getBt32() {
- return bt32;
- }
-
- public GuixDemo3Abstract getBt34() {
- return bt34;
- }
-
- public GuixDemo2Abstract getGd2() {
- return gd2;
- }
-
- public JMenuItem getItem1() {
- return item1;
- }
-
- public JLabel getLabel() {
- return label;
- }
-
- public JLabel getLabel2() {
- return label2;
- }
-
- public JLabel getLabel3() {
- return label3;
- }
-
- public JPanel getTable() {
- return table;
- }
-
- public JTextField getTextfield() {
- return textfield;
- }
-
- /*---------------------------------------------------------------------------------*/
- /*-- public mutator methods -------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public void set$Button6(JButton newValue) {
- this.$Button6 = newValue;
- }
-
- public void set$Button7(JButton newValue) {
- this.$Button7 = newValue;
- }
-
- public void set$Button8(JButton newValue) {
- this.$Button8 = newValue;
- }
-
- public void set$JToolBar5(JToolBar newValue) {
- this.$JToolBar5 = newValue;
- }
-
- public void set$Menu2(JMenu newValue) {
- this.$Menu2 = newValue;
- }
-
- public void set$Menu4(JMenu newValue) {
- this.$Menu4 = newValue;
- }
-
- public void set$MenuBar1(JMenuBar newValue) {
- this.$MenuBar1 = newValue;
- }
-
- public void set$MenuItem3(JMenuItem newValue) {
- this.$MenuItem3 = newValue;
- }
-
- public void set$TabPanel9(JTabbedPane newValue) {
- this.$TabPanel9 = newValue;
- }
-
- public void setBindingGroup(org.jdesktop.beansbinding.BindingGroup newValue) {
- this.bindingGroup = newValue;
- }
-
- public void setBt3(GuixDemo3Abstract newValue) {
- this.bt3 = newValue;
- }
-
- public void setBt31(GuixDemo3Abstract newValue) {
- this.bt31 = newValue;
- }
-
- public void setBt32(GuixDemo3Abstract newValue) {
- this.bt32 = newValue;
- }
-
- public void setBt34(GuixDemo3Abstract newValue) {
- this.bt34 = newValue;
- }
-
- public void setGd2(GuixDemo2Abstract newValue) {
- this.gd2 = newValue;
- }
-
- public void setItem1(JMenuItem newValue) {
- this.item1 = newValue;
- }
-
- public void setLabel(JLabel newValue) {
- this.label = newValue;
- }
-
- public void setLabel2(JLabel newValue) {
- this.label2 = newValue;
- }
-
- public void setLabel3(JLabel newValue) {
- this.label3 = newValue;
- }
-
- public void setTable(JPanel newValue) {
- this.table = newValue;
- }
-
- public void setTextfield(JTextField newValue) {
- this.textfield = newValue;
- }
-
- /*---------------------------------------------------------------------------------*/
- /*-- public mutator methods -------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public void beforeBinding() {
- this.add(b, BorderLayout.SOUTH);
- }
-
- public void beforeCreation() {
- System.out.println("before Creation");
- }
-
- public void beforeInitialization() {
-
- }
-
- /**
- * Components creation
- */
- public void componentsCreation() {
- create$Menu2();
- createItem1();
- create$MenuItem3();
- create$Menu4();
- create$MenuBar1();
- create$JToolBar5();
- create$Button6();
- create$Button7();
- create$Button8();
- create$TabPanel9();
- createTextfield();
- createLabel();
- createLabel2();
- createBt3();
- createBt31();
- createBt32();
- createBt34();
- createLabel3();
- createTable();
- createGd2();
- }
-
- /**
- * components layout
- */
- public void componentsTree() {
- this.setTitle("Guix Swing Demo");
- this.setSize(800,600);
- this.setLayout(new BorderLayout());
- this.setJMenuBar($MenuBar1);
- $MenuBar1.add($Menu2);
- $Menu2.add(item1);
- $Menu2.add($MenuItem3);
- $MenuBar1.add($Menu4);
- this.add($JToolBar5,BorderLayout.NORTH);
- $JToolBar5.add($Button6);
- $JToolBar5.add($Button7);
- $JToolBar5.add($Button8);
- this.add($TabPanel9,BorderLayout.CENTER);
- $TabPanel9.add(table);
- table.add(textfield, new java.awt.GridBagConstraints (0,0,1,1,0.0,0.0,java.awt.GridBagConstraints.FIRST_LINE_START,java.awt.GridBagConstraints.BOTH, new java.awt.Insets(1,1,1,1),1,1));
- table.add(label, new java.awt.GridBagConstraints (1,0,1,1,0.0,0.0,java.awt.GridBagConstraints.FIRST_LINE_START,java.awt.GridBagConstraints.BOTH, new java.awt.Insets(1,1,1,1),1,1));
- table.add(label2, new java.awt.GridBagConstraints (2,0,1,3,0.0,0.0,java.awt.GridBagConstraints.FIRST_LINE_START,java.awt.GridBagConstraints.BOTH, new java.awt.Insets(1,1,1,1),1,1));
- table.add(bt3, new java.awt.GridBagConstraints (3,1,3,1,0.0,0.0,java.awt.GridBagConstraints.FIRST_LINE_START,java.awt.GridBagConstraints.BOTH, new java.awt.Insets(0,0,0,0),1,1));
- table.add(bt31, new java.awt.GridBagConstraints (0,2,2,1,0.0,0.0,java.awt.GridBagConstraints.FIRST_LINE_START,java.awt.GridBagConstraints.BOTH, new java.awt.Insets(0,0,0,0),1,1));
- table.add(bt32, new java.awt.GridBagConstraints (3,2,1,1,0.0,0.0,java.awt.GridBagConstraints.FIRST_LINE_START,java.awt.GridBagConstraints.BOTH, new java.awt.Insets(2,2,2,2),1,1));
- table.add(bt34, new java.awt.GridBagConstraints (0,3,3,1,0.0,0.0,java.awt.GridBagConstraints.FIRST_LINE_START,java.awt.GridBagConstraints.BOTH, new java.awt.Insets(1,1,1,1),1,1));
- table.add(label3, new java.awt.GridBagConstraints (0,4,2,1,0.0,0.0,java.awt.GridBagConstraints.FIRST_LINE_START,java.awt.GridBagConstraints.BOTH, new java.awt.Insets(1,1,1,1),1,1));
- $TabPanel9.add(gd2);
- }
-
- public void inTheEnd() {
-
- }
-
- /**
- * initilization of databinding
- */
- public void initDataBinding() {
- bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
- bindingGroup.addBinding(
- org.jdesktop.beansbinding.Bindings.createAutoBinding(
- org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ,this,org.jdesktop.beansbinding.ELProperty.create("${gd2.button.selected}"),textfield,org.jdesktop.beansbinding.BeanProperty.create("enabled")));
- bindingGroup.bind();
- bindingGroup.addBinding(
- org.jdesktop.beansbinding.Bindings.createAutoBinding(
- org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ,this,org.jdesktop.beansbinding.ELProperty.create("${textfield.text}"),label,org.jdesktop.beansbinding.BeanProperty.create("text")));
- bindingGroup.bind();
- }
-
- /**
- * initialization
- */
- public void initialize() {
- beforeCreation();
- componentsCreation();
- b.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- if(gd2.getButton().isSelected()) {
- java.util.Random r = new java.util.Random();
- table.setBackground(new java.awt.Color(r.nextInt(255), r.nextInt(255), r.nextInt(255)));
- }
- }
- });
- beforeInitialization();
- componentsTree();
- beforeBinding();
- initDataBinding();
- inTheEnd();
- }
-
- /**
- *
- * test
- * @since 0.0.1
- *
- */
- public void test2(String test) throws NullPointerException, ArrayIndexOutOfBoundsException {
- System.out.println(test);
- }
-
- /*---------------------------------------------------------------------------------*/
- /*-- ui creation methods ----------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- /**
- * $Button6 creation
- */
- private void create$Button6() {
- $Button6 = new JButton();
- $Button6.setText("bouton1");
- $Button6.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent actionEvent){
- System.out.println("Action [" + actionEvent.getActionCommand() + "] performed!");
- }
- });
- }
-
- /**
- * $Button7 creation
- */
- private void create$Button7() {
- $Button7 = new JButton();
- $Button7.setText("bouton2");
- $Button7.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent actionEvent){
- System.out.println("Action [" + actionEvent.getActionCommand() + "] performed!");
- }
- });
- }
-
- /**
- * $Button8 creation
- */
- private void create$Button8() {
- $Button8 = new JButton();
- $Button8.setText("bouton3");
- $Button8.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent actionEvent){
- System.out.println("Action [" + actionEvent.getActionCommand() + "] performed!");
- }
- });
- }
-
- /**
- * $JToolBar5 creation
- */
- private void create$JToolBar5() {
- $JToolBar5 = new JToolBar();
- $JToolBar5.setBorder(new javax.swing.border.EtchedBorder());
- }
-
- /**
- * $Menu2 creation
- */
- private void create$Menu2() {
- $Menu2 = new JMenu("menu 1");
- }
-
- /**
- * $Menu4 creation
- */
- private void create$Menu4() {
- $Menu4 = new JMenu("menu 2");
- }
-
- /**
- * $MenuBar1 creation
- */
- private void create$MenuBar1() {
- $MenuBar1 = new javax.swing.JMenuBar();
- $MenuBar1.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
- }
-
- /**
- * $MenuItem3 creation
- */
- private void create$MenuItem3() {
- $MenuItem3 = new JMenuItem();
- $MenuItem3.setText("item2");
- $MenuItem3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent actionEvent){
- System.out.println("Action [" + actionEvent.getActionCommand() + "] performed!");
- }
- });
- }
-
- /**
- * $TabPanel9 creation
- */
- private void create$TabPanel9() {
- $TabPanel9 = new JTabbedPane();
- $TabPanel9.setSize(800,400);
- }
-
- /**
- * bt3 creation
- */
- private void createBt3() {
- bt3 = new GuixDemo3Impl();
- bt3.setText("bt3");
- bt3.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent mouseEvent){
- System.out.println("beau gosse");
- }
- });
- }
-
- /**
- * bt31 creation
- */
- private void createBt31() {
- bt31 = new GuixDemo3Impl();
- bt31.setText("bt31");
- }
-
- /**
- * bt32 creation
- */
- private void createBt32() {
- bt32 = new GuixDemo3Impl();
- bt32.setText("bt32");
- }
-
- /**
- * bt34 creation
- */
- private void createBt34() {
- bt34 = new GuixDemo3Impl();
- bt34.setText("bt34");
- }
-
- /**
- * gd2 creation
- */
- private void createGd2() {
- gd2 = new GuixDemo2Impl();
- gd2.setName("GD2");
- }
-
- /**
- * item1 creation
- */
- private void createItem1() {
- item1 = new JMenuItem();
- item1.setText("item1");
- }
-
- /**
- * label creation
- */
- private void createLabel() {
- label = new JLabel();
- }
-
- /**
- * label2 creation
- */
- private void createLabel2() {
- label2 = new JLabel();
- label2.setText("color");
- label2.setBackground(java.awt.Color.BLUE);
- }
-
- /**
- * label3 creation
- */
- private void createLabel3() {
- label3 = new JLabel();
- label3.setText("color");
- label3.setForeground(java.awt.Color.YELLOW);
- }
-
- /**
- * table creation
- */
- private void createTable() {
- table = new javax.swing.JPanel(new java.awt.GridBagLayout());
- table.setName("Table");
- }
-
- /**
- * textfield creation
- */
- private void createTextfield() {
- textfield = new JTextField("test");
- textfield.addFocusListener(new java.awt.event.FocusAdapter() {
- public void focusGained(java.awt.event.FocusEvent focusEvent){
- System.out.println("dude !");
- }
- });
- }
-
-}
\ No newline at end of file
Deleted: trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemoImpl.java
===================================================================
--- trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemoImpl.java 2009-07-22 13:09:22 UTC (rev 1506)
+++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/GuixDemoImpl.java 2009-07-22 13:10:33 UTC (rev 1507)
@@ -1,30 +0,0 @@
-package org.nuiton.guix;
-
-import javax.swing.JMenuBar;
-import javax.swing.JMenu;
-import javax.swing.JMenuItem;
-import javax.swing.JToolBar;
-import javax.swing.JButton;
-import javax.swing.JTabbedPane;
-import javax.swing.JPanel;
-import javax.swing.JTextField;
-import javax.swing.JLabel;
-import org.nuiton.guix.GuixDemo3Abstract;
-import org.nuiton.guix.GuixDemo2Abstract;
-
-/**
- * test javadoc Application
- */
-public class GuixDemoImpl extends GuixDemoAbstract {
- /*---------------------------------------------------------------------------------*/
- /*-- Constructors -----------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- /**
- * Constructor
- */
- public GuixDemoImpl() {
- super();
- }
-
-}
\ No newline at end of file
Deleted: trunk/guix-test-swing/src/main/java/org/nuiton/guix/Main.java
===================================================================
--- trunk/guix-test-swing/src/main/java/org/nuiton/guix/Main.java 2009-07-22 13:09:22 UTC (rev 1506)
+++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/Main.java 2009-07-22 13:10:33 UTC (rev 1507)
@@ -1,19 +0,0 @@
-package org.nuiton.guix;
-
-import java.io.File;
-import org.springframework.beans.factory.ListableBeanFactory;
-import org.springframework.beans.factory.xml.XmlBeanFactory;
-import org.springframework.core.io.FileSystemResource;
-
-public class Main {
- /*---------------------------------------------------------------------------------*/
- /*-- Statics methods --------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------*/
-
- public static void main(String[] args) {
- javax.swing.SwingUtilities.invokeLater(new Runnable() {public void run() {GuixDemoImpl main = new GuixDemoImpl();
- main.pack();
- main.setVisible(true);}});
- }
-
-}
\ No newline at end of file
Added: trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/Controller.java
===================================================================
--- trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/Controller.java (rev 0)
+++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/Controller.java 2009-07-22 13:10:33 UTC (rev 1507)
@@ -0,0 +1,9 @@
+package org.nuiton.guix.demo;
+
+public class Controller {
+
+ public Controller() {
+ System.out.println("Dude, it's bloody raining");
+ }
+
+}
Modified: trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.guix
===================================================================
--- trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.guix 2009-07-22 13:09:22 UTC (rev 1506)
+++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.guix 2009-07-22 13:10:33 UTC (rev 1507)
@@ -1,6 +1,7 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!-- test javadoc Application -->
<Application title="Guix Swing Demo" size="800,600" layout="new BorderLayout()" xmlns:swing='javax.swing.*'>
+<style source="JButton.css" />
<script><![CDATA[
import java.awt.Button;
import java.awt.event.ActionListener;
@@ -40,33 +41,34 @@
}
]]></script>
+ <java.util.ArrayList id="controller" />
<MenuBar border="new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED)">
<Menu constructor='"menu 1"'>
<MenuItem id="item1" text="item1" />
- <MenuItem text="item2" onActionPerformed='{System.out.println("Action [" + actionEvent.getActionCommand()
+ <MenuItem text="item2" action='{System.out.println("Action [" + actionEvent.getActionCommand()
+ "] performed!");}' />
</Menu>
<Menu constructor='"menu 2"'>
</Menu>
</MenuBar>
- <swing:JToolBar border="new javax.swing.border.EtchedBorder()" constraint="BorderLayout.NORTH">
- <Button onActionPerformed='{System.out.println("Action [" + actionEvent.getActionCommand()
+ <swing:JToolBar>
+ <Button id="bouton1" onActionPerformed='{System.out.println("Action [" + actionEvent.getActionCommand()
+ "] performed!");}' text="bouton1" />
<Button onActionPerformed='{System.out.println("Action [" + actionEvent.getActionCommand()
+ "] performed!");}' text="bouton2" />
<Button onActionPerformed='{System.out.println("Action [" + actionEvent.getActionCommand()
+ "] performed!");}' text="bouton3" />
</swing:JToolBar>
- <TabPanel constraint="BorderLayout.CENTER" size="800,400">
+ <TabPanel id="tabPanel">
<Table id="table" insets="1,1,1,1" name="Table">
<Row>
<Cell>
<!-- javadoc textfield -->
- <TextField id="textfield" constructor='"test"' enabled="{gd2.getButton().isSelected()}" onFocusGained='{System.out.println("dude !")}'/>
+ <TextField id="textfield" constructor='"test"' enabled="{getGd2().getButton().isSelected() && getGd22().getButton().isSelected()}" onFocus='{System.out.println("dude !")}'/>
</Cell>
<Cell>
- <Label id="label" text="{textfield.getText()}" styleClass="bold" />
+ <Label id="label" text="label : {textfield.getText()}" styleClass="bold" />
</Cell>
<Cell rows='3'>
<Label id="label2" text="color" background="java.awt.Color.BLUE" />
@@ -74,7 +76,7 @@
</Row>
<Row insets="0,0,0,0">
<Cell columns="3">
- <GuixDemo3 id="bt3" text="bt3" onMouseClicked='{System.out.println("beau gosse")}'/>
+ <GuixDemo3 id="bt3" text="bt3" onClick='{System.out.println("beau gosse")}'/>
</Cell>
</Row>
<Row insets="0,0,0,0">
@@ -97,5 +99,6 @@
</Row>
</Table>
<GuixDemo2 id="gd2" name="GD2" />
+ <GuixDemo2 id="gd22" name="GD22" />
</TabPanel>
</Application>
1
0
22 Jul '09
Author: kmorin
Date: 2009-07-22 15:09:22 +0200 (Wed, 22 Jul 2009)
New Revision: 1506
Added:
trunk/guix-runtime-swing/
trunk/guix-runtime-swing/pom.xml
trunk/guix-runtime-swing/src/
trunk/guix-runtime-swing/src/main/
trunk/guix-runtime-swing/src/main/java/
trunk/guix-runtime-swing/src/main/java/org/
trunk/guix-runtime-swing/src/main/java/org/nuiton/
trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/
trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/
trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/
trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/DataBindingListener.java
trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/DataBindingUpdateListener.java
trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/GuixObject.java
trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/Util.java
trunk/guix-runtime-swing/src/main/resources/
trunk/guix-runtime-swing/src/test/
trunk/guix-runtime-swing/src/test/java/
trunk/guix-runtime-swing/src/test/java/org/
trunk/guix-runtime-swing/src/test/java/org/nuiton/
trunk/guix-runtime-swing/src/test/java/org/nuiton/guix/
trunk/guix-runtime-swing/src/test/java/org/nuiton/guix/AppTest.java
Log:
unuseful module
Property changes on: trunk/guix-runtime-swing
___________________________________________________________________
Added: svn:ignore
+ target
Added: trunk/guix-runtime-swing/pom.xml
===================================================================
--- trunk/guix-runtime-swing/pom.xml (rev 0)
+++ trunk/guix-runtime-swing/pom.xml 2009-07-22 13:09:22 UTC (rev 1506)
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+ <parent>
+ <groupId>org.nuiton</groupId>
+ <artifactId>guix</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.nuiton.guix</groupId>
+ <artifactId>guix-runtime-swing</artifactId>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+ <name>guix-runtime-swing</name>
+ <description>Guix runtime</description>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>jar</packaging>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+
+</project>
Added: trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/DataBindingListener.java
===================================================================
--- trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/DataBindingListener.java (rev 0)
+++ trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/DataBindingListener.java 2009-07-22 13:09:22 UTC (rev 1506)
@@ -0,0 +1,42 @@
+package org.nuiton.guix.runtime.swing;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+
+/**
+ * A <code>PropertyChangeListener</code> which processes a data binding when it receives a
+ * <code>PropertyChangeEvent</code>.
+ */
+public class DataBindingListener implements PropertyChangeListener {
+ private GuixObject object;
+ private String dest;
+
+ /**
+ * Creates a new <code>DataBindingListener</code> which will run the given data binding
+ * when it receives a <code>PropertyChangeEvent</code>.
+ *
+ * @param object the object in which the data binding exists
+ * @param dest the name of the data binding to run
+ */
+ public DataBindingListener(GuixObject object, String dest) {
+ this.object = object;
+ this.dest = dest;
+ }
+
+
+ /**
+ * Processes the data binding in response to a <code>PropertyChangeEvent</code>.
+ *
+ * @param e the event which triggered the binding
+ */
+ public void propertyChange(PropertyChangeEvent e) {
+ object.processDataBinding(dest);
+
+ // for now, handle dependency changes by always removing & reapplying
+ // the binding. We should be more efficient and only do this when it's
+ // actually necessary
+ object.removeDataBinding(dest);
+ object.applyDataBinding(dest);
+ }
+}
\ No newline at end of file
Added: trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/DataBindingUpdateListener.java
===================================================================
--- trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/DataBindingUpdateListener.java (rev 0)
+++ trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/DataBindingUpdateListener.java 2009-07-22 13:09:22 UTC (rev 1506)
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2006 Ethan Nicholas. All rights reserved.
+ * Use is subject to license terms.
+ */
+package org.nuiton.guix.runtime.swing;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+
+/**
+ * A <code>PropertyChangeListener</code> which removes and re-applies a data binding
+ * when it receives a <code>PropertyChangeEvent</code>.
+ */
+public class DataBindingUpdateListener implements PropertyChangeListener {
+ private GuixObject object;
+ private String dest;
+
+ /**
+ * Creates a new <code>DataBindingUpdateListener</code> which will remove and re-apply a
+ * data binding when it receives a <code>PropertyChangeEvent</code>.
+ *
+ * @param object the object in which the data binding exists
+ * @param dest the name of the data binding to reapply
+ */
+ public DataBindingUpdateListener(GuixObject object, String dest) {
+ this.object = object;
+ this.dest = dest;
+ }
+
+
+ public String getBindingName() {
+ return dest;
+ }
+
+
+ /**
+ * Updates the data binding in response to a <code>PropertyChangeEvent</code>.
+ *
+ * @param e the event which triggered the binding
+ */
+ public void propertyChange(PropertyChangeEvent e) {
+ object.removeDataBinding(dest);
+ object.applyDataBinding(dest);
+ }
+}
\ No newline at end of file
Added: trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/GuixObject.java
===================================================================
--- trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/GuixObject.java (rev 0)
+++ trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/GuixObject.java 2009-07-22 13:09:22 UTC (rev 1506)
@@ -0,0 +1,46 @@
+package org.nuiton.guix.runtime.swing;
+
+/** The <code>GuixObject</code> interface is implemented by all classes produced by the Guix compiler. */
+public interface GuixObject {
+ /**
+ * Retrieves an object defined in an XML tag by its ID.
+ *
+ * @param id the id of the component to retrieve
+ * @return the object
+ */
+ //public Object getObjectById(String id);
+
+ /**
+ * Pretrieves the dictonary of knwon objects indexed by their ids.
+ *
+ * @return the dictonary of objects.
+ */
+ //public java.util.Map<String, Object> get$objectMap();
+
+ public void applyDataBinding(String id);
+
+
+ public void removeDataBinding(String id);
+
+ /**
+ * Processes a data binding by name. Data binding names are comprised of an object ID and a property name:
+ * for example, the data binding in the tag <code><JLabel id='label' text='{foo.getText()}'/></code> is
+ * named <code>"label.text"</code>. Processing a data binding causes it to reevaluate its expression, in this
+ * case <code>foo.getText()</code>.
+ *
+ * @param dest the name of the data binding to run
+ */
+ public void processDataBinding(String dest);
+
+
+ /**
+ * All <code>GuixObject</code> implements are capable of broadcasting <code>PropertyChangeEvent</code>, and
+ * furthermore (for technical reasons) must allow code in outside packages, specifically the Guix runtime,
+ * to trigger these events.
+ *
+ * @param name the name of the property which changed
+ * @param oldValue the old value of the property
+ * @param newValue the new value of the property
+ */
+ public void firePropertyChange(String name, Object oldValue, Object newValue);
+}
\ No newline at end of file
Added: trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/Util.java
===================================================================
--- trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/Util.java (rev 0)
+++ trunk/guix-runtime-swing/src/main/java/org/nuiton/guix/runtime/swing/Util.java 2009-07-22 13:09:22 UTC (rev 1506)
@@ -0,0 +1,117 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.nuiton.guix.runtime.swing;
+
+import java.awt.Event;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EventListener;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+/**
+ *
+ * @author kevin
+ */
+public class Util {
+ // Maps root objects to lists of event listeners
+ private static Map<Object, WeakReference<List<EventListenerDescriptor>>> eventListeners = new WeakHashMap<Object, WeakReference<List<EventListenerDescriptor>>>();
+
+
+
+ private static class EventListenerDescriptor {
+ Class listenerClass;
+ String listenerMethodName;
+ String methodName;
+ Object eventListener;
+ }
+
+ public static Object getEventListener(Class<? extends EventListener> listenerClass, final Object methodContainer, final String methodName) {
+ return getEventListener(listenerClass, null, methodContainer, methodName);
+ }
+
+
+ public static Object getEventListener(Class<? extends EventListener> listenerClass, final String listenerMethodName, final Object methodContainer, final String methodName) {
+ WeakReference<List<EventListenerDescriptor>> ref = eventListeners.get(methodContainer);
+ List<EventListenerDescriptor> descriptors = ref != null ? ref.get() : null;
+ if (descriptors == null) {
+ descriptors = new ArrayList<EventListenerDescriptor>();
+ eventListeners.put(methodContainer, new WeakReference<List<EventListenerDescriptor>>(descriptors));
+ } else {
+ for (EventListenerDescriptor descriptor : descriptors) {
+ if (listenerClass == descriptor.listenerClass &&
+ (listenerMethodName == null ? descriptor.listenerMethodName == null : listenerMethodName.equals(descriptor.listenerMethodName)) &&
+ methodName.equals(descriptor.methodName)) {
+ return descriptor.eventListener;
+ }
+ }
+ }
+
+ // else we need to create a new listener
+ final EventListenerDescriptor descriptor = new EventListenerDescriptor();
+ descriptor.listenerClass = listenerClass;
+ descriptor.listenerMethodName = listenerMethodName;
+ descriptor.methodName = methodName;
+ try {
+ final List<Method> listenerMethods = Arrays.asList(listenerClass.getMethods());
+ Method listenerMethod = null;
+ if (listenerMethodName != null) {
+ for (Method listenerMethod1 : listenerMethods) {
+ if ((listenerMethod1).getName().equals(listenerMethodName)) {
+ listenerMethod = listenerMethod1;
+ break;
+ }
+ }
+ }
+ if (listenerMethodName != null && listenerMethod == null) {
+ throw new IllegalArgumentException("no method named " + listenerMethodName + " found in class " + listenerClass.getName());
+ }
+ Class[] parameterTypes = listenerMethods.get(0).getParameterTypes();
+ Class<?> methodContainerClass = methodContainer.getClass();
+ final Method targetMethod = methodContainerClass.getMethod(methodName, parameterTypes);
+ descriptor.eventListener = Proxy.newProxyInstance(listenerClass.getClassLoader(),
+ new Class[]{listenerClass},
+ new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args) {
+ String methodName = method.getName();
+ if ((listenerMethodName == null && listenerMethods.contains(method)) || methodName.equals(listenerMethodName)) {
+ try {
+ return targetMethod.invoke(methodContainer, args);
+ }
+ catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (methodName.equals("toString")) {
+ return toString();
+ }
+ if (methodName.equals("equals")) {
+ return descriptor.eventListener == args[0];
+ }
+ if (methodName.equals("hashCode")) {
+ return hashCode();
+ }
+ return null;
+ }
+ });
+ descriptors.add(descriptor);
+ return descriptor.eventListener;
+ }
+ catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Added: trunk/guix-runtime-swing/src/test/java/org/nuiton/guix/AppTest.java
===================================================================
--- trunk/guix-runtime-swing/src/test/java/org/nuiton/guix/AppTest.java (rev 0)
+++ trunk/guix-runtime-swing/src/test/java/org/nuiton/guix/AppTest.java 2009-07-22 13:09:22 UTC (rev 1506)
@@ -0,0 +1,38 @@
+package org.nuiton.guix;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
1
0
22 Jul '09
Author: kmorin
Date: 2009-07-22 15:09:02 +0200 (Wed, 22 Jul 2009)
New Revision: 1505
Added:
trunk/guix-runtime-gwt/
trunk/guix-runtime-gwt/pom.xml
trunk/guix-runtime-gwt/src/
trunk/guix-runtime-gwt/src/main/
trunk/guix-runtime-gwt/src/main/java/
trunk/guix-runtime-gwt/src/main/java/org/
trunk/guix-runtime-gwt/src/main/java/org/nuiton/
trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/
trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/
trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/
trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/DataBindingListener.java
trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/DataBindingUpdateListener.java
trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/GuixObject.java
trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/Runtime.gwt.xml
trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/Util.java
trunk/guix-runtime-gwt/src/main/resources/
trunk/guix-runtime-gwt/src/test/
trunk/guix-runtime-gwt/src/test/java/
trunk/guix-runtime-gwt/src/test/java/org/
trunk/guix-runtime-gwt/src/test/java/org/nuiton/
trunk/guix-runtime-gwt/src/test/java/org/nuiton/guix/
trunk/guix-runtime-gwt/src/test/java/org/nuiton/guix/AppTest.java
Log:
unuseful module
Property changes on: trunk/guix-runtime-gwt
___________________________________________________________________
Added: svn:ignore
+ target
Added: trunk/guix-runtime-gwt/pom.xml
===================================================================
--- trunk/guix-runtime-gwt/pom.xml (rev 0)
+++ trunk/guix-runtime-gwt/pom.xml 2009-07-22 13:09:02 UTC (rev 1505)
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+ <parent>
+ <groupId>org.nuiton</groupId>
+ <artifactId>guix</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.nuiton.guix</groupId>
+ <artifactId>guix-runtime-gwt</artifactId>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+ <name>guix-runtime-gwt</name>
+ <description>Guix runtime</description>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>jar</packaging>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+
+</project>
Added: trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/DataBindingListener.java
===================================================================
--- trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/DataBindingListener.java (rev 0)
+++ trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/DataBindingListener.java 2009-07-22 13:09:02 UTC (rev 1505)
@@ -0,0 +1,42 @@
+package org.nuiton.guix.runtime.gwt;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+
+/**
+ * A <code>PropertyChangeListener</code> which processes a data binding when it receives a
+ * <code>PropertyChangeEvent</code>.
+ */
+public class DataBindingListener implements PropertyChangeListener {
+ private GuixObject object;
+ private String dest;
+
+ /**
+ * Creates a new <code>DataBindingListener</code> which will run the given data binding
+ * when it receives a <code>PropertyChangeEvent</code>.
+ *
+ * @param object the object in which the data binding exists
+ * @param dest the name of the data binding to run
+ */
+ public DataBindingListener(GuixObject object, String dest) {
+ this.object = object;
+ this.dest = dest;
+ }
+
+
+ /**
+ * Processes the data binding in response to a <code>PropertyChangeEvent</code>.
+ *
+ * @param e the event which triggered the binding
+ */
+ public void propertyChange(PropertyChangeEvent e) {
+ object.processDataBinding(dest);
+
+ // for now, handle dependency changes by always removing & reapplying
+ // the binding. We should be more efficient and only do this when it's
+ // actually necessary
+ object.removeDataBinding(dest);
+ object.applyDataBinding(dest);
+ }
+}
\ No newline at end of file
Added: trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/DataBindingUpdateListener.java
===================================================================
--- trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/DataBindingUpdateListener.java (rev 0)
+++ trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/DataBindingUpdateListener.java 2009-07-22 13:09:02 UTC (rev 1505)
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2006 Ethan Nicholas. All rights reserved.
+ * Use is subject to license terms.
+ */
+package org.nuiton.guix.runtime.gwt;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+
+/**
+ * A <code>PropertyChangeListener</code> which removes and re-applies a data binding
+ * when it receives a <code>PropertyChangeEvent</code>.
+ */
+public class DataBindingUpdateListener implements PropertyChangeListener {
+ private GuixObject object;
+ private String dest;
+
+ /**
+ * Creates a new <code>DataBindingUpdateListener</code> which will remove and re-apply a
+ * data binding when it receives a <code>PropertyChangeEvent</code>.
+ *
+ * @param object the object in which the data binding exists
+ * @param dest the name of the data binding to reapply
+ */
+ public DataBindingUpdateListener(GuixObject object, String dest) {
+ this.object = object;
+ this.dest = dest;
+ }
+
+
+ public String getBindingName() {
+ return dest;
+ }
+
+
+ /**
+ * Updates the data binding in response to a <code>PropertyChangeEvent</code>.
+ *
+ * @param e the event which triggered the binding
+ */
+ public void propertyChange(PropertyChangeEvent e) {
+ object.removeDataBinding(dest);
+ object.applyDataBinding(dest);
+ }
+}
\ No newline at end of file
Added: trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/GuixObject.java
===================================================================
--- trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/GuixObject.java (rev 0)
+++ trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/GuixObject.java 2009-07-22 13:09:02 UTC (rev 1505)
@@ -0,0 +1,35 @@
+package org.nuiton.guix.runtime.gwt;
+
+/** The <code>GuixObject</code> interface is implemented by all classes produced by the Guix compiler. */
+public interface GuixObject {
+ /**
+ * Retrieves an object defined in an XML tag by its ID.
+ *
+ * @param id the id of the component to retrieve
+ * @return the object
+ */
+ //public Object getObjectById(String id);
+
+ /**
+ * Pretrieves the dictonary of knwon objects indexed by their ids.
+ *
+ * @return the dictonary of objects.
+ */
+ //public java.util.Map<String, Object> get$objectMap();
+
+ public void applyDataBinding(String id);
+
+
+ public void removeDataBinding(String id);
+
+ /**
+ * Processes a data binding by name. Data binding names are comprised of an object ID and a property name:
+ * for example, the data binding in the tag <code><JLabel id='label' text='{foo.getText()}'/></code> is
+ * named <code>"label.text"</code>. Processing a data binding causes it to reevaluate its expression, in this
+ * case <code>foo.getText()</code>.
+ *
+ * @param dest the name of the data binding to run
+ */
+ public void processDataBinding(String dest);
+
+}
\ No newline at end of file
Added: trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/Runtime.gwt.xml
===================================================================
--- trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/Runtime.gwt.xml (rev 0)
+++ trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/Runtime.gwt.xml 2009-07-22 13:09:02 UTC (rev 1505)
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module>
+ <source path="org.nuiton.guix.runtime.gwt" />
+</module>
\ No newline at end of file
Added: trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/Util.java
===================================================================
--- trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/Util.java (rev 0)
+++ trunk/guix-runtime-gwt/src/main/java/org/nuiton/guix/runtime/gwt/Util.java 2009-07-22 13:09:02 UTC (rev 1505)
@@ -0,0 +1,117 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.nuiton.guix.runtime.gwt;
+
+import java.awt.Event;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EventListener;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+/**
+ *
+ * @author kevin
+ */
+public class Util {
+ // Maps root objects to lists of event listeners
+ private static Map<Object, WeakReference<List<EventListenerDescriptor>>> eventListeners = new WeakHashMap<Object, WeakReference<List<EventListenerDescriptor>>>();
+
+
+
+ private static class EventListenerDescriptor {
+ Class listenerClass;
+ String listenerMethodName;
+ String methodName;
+ Object eventListener;
+ }
+
+ public static Object getEventListener(Class<? extends EventListener> listenerClass, final Object methodContainer, final String methodName) {
+ return getEventListener(listenerClass, null, methodContainer, methodName);
+ }
+
+
+ public static Object getEventListener(Class<? extends EventListener> listenerClass, final String listenerMethodName, final Object methodContainer, final String methodName) {
+ WeakReference<List<EventListenerDescriptor>> ref = eventListeners.get(methodContainer);
+ List<EventListenerDescriptor> descriptors = ref != null ? ref.get() : null;
+ if (descriptors == null) {
+ descriptors = new ArrayList<EventListenerDescriptor>();
+ eventListeners.put(methodContainer, new WeakReference<List<EventListenerDescriptor>>(descriptors));
+ } else {
+ for (EventListenerDescriptor descriptor : descriptors) {
+ if (listenerClass == descriptor.listenerClass &&
+ (listenerMethodName == null ? descriptor.listenerMethodName == null : listenerMethodName.equals(descriptor.listenerMethodName)) &&
+ methodName.equals(descriptor.methodName)) {
+ return descriptor.eventListener;
+ }
+ }
+ }
+
+ // else we need to create a new listener
+ final EventListenerDescriptor descriptor = new EventListenerDescriptor();
+ descriptor.listenerClass = listenerClass;
+ descriptor.listenerMethodName = listenerMethodName;
+ descriptor.methodName = methodName;
+ try {
+ final List<Method> listenerMethods = Arrays.asList(listenerClass.getMethods());
+ Method listenerMethod = null;
+ if (listenerMethodName != null) {
+ for (Method listenerMethod1 : listenerMethods) {
+ if ((listenerMethod1).getName().equals(listenerMethodName)) {
+ listenerMethod = listenerMethod1;
+ break;
+ }
+ }
+ }
+ if (listenerMethodName != null && listenerMethod == null) {
+ throw new IllegalArgumentException("no method named " + listenerMethodName + " found in class " + listenerClass.getName());
+ }
+ Class[] parameterTypes = listenerMethods.get(0).getParameterTypes();
+ Class<?> methodContainerClass = methodContainer.getClass();
+ final Method targetMethod = methodContainerClass.getMethod(methodName, parameterTypes);
+ descriptor.eventListener = Proxy.newProxyInstance(listenerClass.getClassLoader(),
+ new Class[]{listenerClass},
+ new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args) {
+ String methodName = method.getName();
+ if ((listenerMethodName == null && listenerMethods.contains(method)) || methodName.equals(listenerMethodName)) {
+ try {
+ return targetMethod.invoke(methodContainer, args);
+ }
+ catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (methodName.equals("toString")) {
+ return toString();
+ }
+ if (methodName.equals("equals")) {
+ return descriptor.eventListener == args[0];
+ }
+ if (methodName.equals("hashCode")) {
+ return hashCode();
+ }
+ return null;
+ }
+ });
+ descriptors.add(descriptor);
+ return descriptor.eventListener;
+ }
+ catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Added: trunk/guix-runtime-gwt/src/test/java/org/nuiton/guix/AppTest.java
===================================================================
--- trunk/guix-runtime-gwt/src/test/java/org/nuiton/guix/AppTest.java (rev 0)
+++ trunk/guix-runtime-gwt/src/test/java/org/nuiton/guix/AppTest.java 2009-07-22 13:09:02 UTC (rev 1505)
@@ -0,0 +1,38 @@
+package org.nuiton.guix;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
1
0
r1504 - trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing
by kmorin@users.labs.libre-entreprise.org 22 Jul '09
by kmorin@users.labs.libre-entreprise.org 22 Jul '09
22 Jul '09
Author: kmorin
Date: 2009-07-22 15:08:35 +0200 (Wed, 22 Jul 2009)
New Revision: 1504
Added:
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ApplicationHandler.java
Log:
I removed ApplicationHandler by mistake, recommit it
Added: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ApplicationHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ApplicationHandler.java (rev 0)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ApplicationHandler.java 2009-07-22 13:08:35 UTC (rev 1504)
@@ -0,0 +1,22 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.nuiton.guix.tags.swing;
+
+/**
+ *
+ * @author kevin
+ */
+public class ApplicationHandler extends ComponentHandler {
+
+ public ApplicationHandler() {
+ super();
+ }
+
+ public Class getClassToGenerate() {
+ return javax.swing.JFrame.class;
+ }
+
+}
1
0
r1503 - in trunk/guix-compiler-swing/src/main/java/org/nuiton/guix: . events generator tags/swing
by kmorin@users.labs.libre-entreprise.org 22 Jul '09
by kmorin@users.labs.libre-entreprise.org 22 Jul '09
22 Jul '09
Author: kmorin
Date: 2009-07-22 15:08:00 +0200 (Wed, 22 Jul 2009)
New Revision: 1503
Added:
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ComponentHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/FrameHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/SelectableButtonHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TextComponentHandler.java
Removed:
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ApplicationHandler.java
Modified:
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/SwingGuixInitializer.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/events/SwingEventHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingAbstractClassGenerator.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingGenerator.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ButtonHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/CellHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/LabelHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/MenuBarHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/MenuHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/MenuItemHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/PanelHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/RowHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TabPanelHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TableHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TextFieldHandler.java
trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ToggleButtonHandler.java
Log:
Added the proxyEventInfo (to generate the binding)
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/SwingGuixInitializer.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/SwingGuixInitializer.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/SwingGuixInitializer.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -22,7 +22,7 @@
//~--- non-JDK imports --------------------------------------------------------
import org.nuiton.guix.tags.swing.PanelHandler;
-import org.nuiton.guix.tags.swing.ApplicationHandler;
+import org.nuiton.guix.tags.swing.FrameHandler;
import org.nuiton.guix.tags.swing.CellHandler;
import org.nuiton.guix.tags.swing.RowHandler;
import org.nuiton.guix.tags.swing.TableHandler;
@@ -43,7 +43,8 @@
*/
public class SwingGuixInitializer {
public static void initialize() {
- TagManager.registerGuixClassHandler("Application", ApplicationHandler.class);
+ TagManager.registerGuixClassHandler("Application", FrameHandler.class);
+ TagManager.registerGuixClassHandler("Frame", FrameHandler.class);
TagManager.registerGuixClassHandler("Table", TableHandler.class);
TagManager.registerGuixClassHandler("Row", RowHandler.class);
TagManager.registerGuixClassHandler("Cell", CellHandler.class);
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/events/SwingEventHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/events/SwingEventHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/events/SwingEventHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -89,6 +89,9 @@
methods.put(method, value);
map.put(esd, methods);
}
+ else if(map.get(esd).get(method) != null) {
+ map.get(esd).put(method, map.get(esd).get(method) + value);
+ }
else {
map.get(esd).put(method, value);
}
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingAbstractClassGenerator.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingAbstractClassGenerator.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingAbstractClassGenerator.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -19,7 +19,10 @@
package org.nuiton.guix.generator;
//~--- non-JDK imports --------------------------------------------------------
-import java.beans.IntrospectionException;import org.nuiton.guix.tags.swing.MenuBarHandler;
+import java.beans.IntrospectionException;
+import java.io.File;
+import java.util.Map;
+import org.nuiton.guix.tags.swing.MenuBarHandler;
;
import org.nuiton.guix.model.GuixModelObject;
@@ -58,6 +61,8 @@
List<StyleSheet> styleSheets = new ArrayList<StyleSheet>();
/** map of the different parts of the script associated with gmo */
Map<ScriptPart, Object> script;
+ /** Bindings to generate */
+ Map<String,Map<String, String>> bindings2Generate = new HashMap<String,Map<String, String>>();
/**
* Constructor
@@ -77,8 +82,7 @@
script = sh.decomposeScript(gmo.getClassDescriptor().getScript());
}
- @Override
- public void generate(File out) {
+ public JavaFile generates() {
super.generate();
//add imports
@@ -89,13 +93,11 @@
//add bodycode
jf.addBodyCode((String) script.get(ScriptPart.BODYCODE));
- //add bindinggroup
- jf.addField(new JavaField(Modifier.PRIVATE,
- "org.jdesktop.beansbinding.BindingGroup",
- "bindingGroup", "bindingGroup for databinding"),
- true);
- //add fields
- addFields(gmo);
+ //add implementation of firePropertyChange
+ JavaArgument[] args = new JavaArgument[]{new JavaArgument("String", "name"),
+ new JavaArgument("Object", "oldValue"),
+ new JavaArgument("Object", "newValue")};
+ jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "firePropertyChange", args, null, "super.firePropertyChange(name, oldValue, newValue);", null));
//add constructor
jf.addMethod(new JavaMethod(Modifier.PUBLIC, null, gmo.getClassDescriptor().getName() + "Abstract",
@@ -124,7 +126,7 @@
jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.COMPONENTS_TREE), null, null, methodBodies.get(Method.COMPONENTS_TREE), "components layout"));
//add databinding method
- StringBuffer dataBinding = new StringBuffer("bindingGroup = new org.jdesktop.beansbinding.BindingGroup();\n");
+ StringBuffer dataBinding = new StringBuffer();
dataBinding.append(methodBodies.get(Method.DATABINDING_INIT));
jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.DATABINDING_INIT), null, null, dataBinding.toString(), "initilization of databinding"));
@@ -151,62 +153,18 @@
jf.addMethod(m);
}
}
- //set superclass and interface
- jf.setSuperClass(gmo.getClassDescriptor().getSuperClass().getPackageName() + "." + gmo.getClassDescriptor().getSuperClass().getName());
- jf.addInterface(gmo.getClassDescriptor().getName());
//saves the file
- saveFile(out);
+ //saveFile(out);
}
catch (ClassNotFoundException eee) {
if (log.isErrorEnabled()) {
log.error(eee);
}
}
+ return jf;
}
/**
- * Adds fields to the file to generate
- *
- * @param gmo the GuixModelObject to analyze
- */
- private void addFields(GuixModelObject gmo) {
- for (GuixModelObject child : gmo.getChildren()) {
- //if gmo represents a Guix tag
- if (child.getClassDescriptor().getPackageName() == null
- && TagManager.getGuixClassHandler(child.getClassDescriptor().getName()) != null) {
- Class clazz;
- try {
- TagHandler th = (TagHandler)TagManager.getGuixClassHandler(child.getClassDescriptor().getName()).newInstance();
- if(th.getClassToGenerate() != null) {
- clazz = th.getClassToGenerate();
- jf.addField(new JavaField(Modifier.PRIVATE,
- clazz.getSimpleName(),
- child.getId(), child.getJavadoc()),
- true);
- }
- }
- catch (InstantiationException eee) {
- if(log.isErrorEnabled()) {
- log.error(eee);
- }
- }
- catch (IllegalAccessException eee) {
- if(log.isErrorEnabled()) {
- log.error(eee);
- }
- }
- }
- else {
- jf.addField(new JavaField(Modifier.PRIVATE,
- (classes != null && classes.contains(child.getClassDescriptor().toString())) ? child.getClassDescriptor().getName() + "Abstract" : child.getClassDescriptor().getName(),
- child.getId(), child.getJavadoc()),
- true);
- }
- addFields(child);
- }
- }
-
- /**
* Browse the GuixModelObjects to add the creation, initialization and bindings methods to the file to gnerate
*
* @param gmo the GuixModelObject to analyze
@@ -233,11 +191,16 @@
TableHandler table = new TableHandler(gmo);
//the table is a JPanel
clazz = table.getClassToGenerate();
+
+ jf.addField(new JavaField(Modifier.PRIVATE,
+ clazz.getName(),
+ gmo.getId(), gmo.getJavadoc(), table),
+ true);
//the layout of the table is the GridBagLayout
creationMethod.append(gmo.getId()).append(" = new ")
.append(clazz.getName()).append("(new java.awt.GridBagLayout());\n");
- constraint = processAttributes(clazz, gmo, bindings, creationMethod, null, seh, null);
+ constraint = processAttributes(clazz, gmo, bindings, creationMethod, null, seh, null, table);
//add the component to its parent
componentsTree.append(gmo.getParent().getId() == null ? "this" : gmo.getParent().getId()).append(".add(").append(gmo.getId());
@@ -296,11 +259,16 @@
StringBuffer creationMethod = new StringBuffer();
MenuBarHandler menuBar = new MenuBarHandler();
clazz = menuBar.getClassToGenerate();
- //the layout of the table is the GridBagLayout
+
+ jf.addField(new JavaField(Modifier.PRIVATE,
+ clazz.getName(),
+ gmo.getId(), gmo.getJavadoc(), menuBar),
+ true);
+ //
creationMethod.append(gmo.getId()).append(" = new ")
.append(clazz.getName()).append("();\n");
- constraint = processAttributes(clazz, gmo, bindings, creationMethod, null, seh, null);
+ constraint = processAttributes(clazz, gmo, bindings, creationMethod, null, seh, null, menuBar);
//add the component to its parent
componentsTree.append(gmo.getParent().getId() == null ? "this" : gmo.getParent().getId()).append(".setJMenuBar(").append(gmo.getId()).append(");\n");
@@ -317,11 +285,11 @@
componentsCreation.append("create").append(capitalizedId).append("();\n");
}
else {
+ TagHandler th = null;
if(TagManager.getGuixClassHandler(gmo.getClassDescriptor().getName()) != null) {
try {
- clazz = ((TagHandler)TagManager.getGuixClassHandler(gmo.getClassDescriptor().getName()).newInstance()).getClassToGenerate();
- gmo.getClassDescriptor().setPackageName(clazz.getPackage().getName());
- gmo.getClassDescriptor().setName(clazz.getSimpleName());
+ th = (TagHandler)TagManager.getGuixClassHandler(gmo.getClassDescriptor().getName()).newInstance();
+ clazz = th.getClassToGenerate();
}
catch (InstantiationException eee) {
if(log.isErrorEnabled()) {
@@ -336,10 +304,8 @@
}
else if(gmo.getClassDescriptor().getSuperClass() != null && TagManager.getGuixClassHandler(gmo.getClassDescriptor().getSuperClass().getName()) != null) {
try {
- TagHandler th = (TagHandler)TagManager.getGuixClassHandler(gmo.getClassDescriptor().getSuperClass().getName()).newInstance();
+ th = (TagHandler)TagManager.getGuixClassHandler(gmo.getClassDescriptor().getSuperClass().getName()).newInstance();
clazz = th.getClassToGenerate();
- gmo.getClassDescriptor().getSuperClass().setPackageName(clazz.getPackage().getName());
- gmo.getClassDescriptor().getSuperClass().setName(clazz.getSimpleName());
}
catch (InstantiationException eee) {
if(log.isErrorEnabled()) {
@@ -352,6 +318,7 @@
}
}
}
+
ClassDescriptor cd = gmo.getClassDescriptor();
//while the class hasn't been found and the classDescriptor is not null
while (clazz == null && cd != null) {
@@ -366,19 +333,51 @@
}
//if the class hasn't been found
if (clazz == null) {
- throw new ClassNotFoundException();
+ File f = new File(gmo.getClassDescriptor().toString().replace('.', File.separatorChar));
+ if(f.exists()) {
+
+ }
+ else {
+ throw new ClassNotFoundException();
+ }
}
+ if(gmo.getClassDescriptor().getPackageName() == null
+ && th != null && th.getClassToGenerate() != null) {
+ jf.addField(new JavaField(Modifier.PRIVATE,
+ clazz.getName(),
+ gmo.getId(), gmo.getJavadoc(), th),
+ true);
+ }
+ else if(gmo.getId() == null) {
+ jf.addField(new JavaField(Modifier.PRIVATE,
+ (classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().toString() + "Abstract" : gmo.getClassDescriptor().toString(),
+ gmo.getClassDescriptor().getName().toLowerCase(), "this", gmo.getJavadoc(), th),
+ true);
+ }
+ else {
+ jf.addField(new JavaField(Modifier.PRIVATE,
+ (classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().toString() + "Abstract" : gmo.getClassDescriptor().toString(),
+ gmo.getId(), gmo.getJavadoc(), th),
+ true);
+ }
+
//if gmo does not represents the first tag
if (gmo.getParent() != null) {
//id with the first letter capitalized
String capitalizedId = (gmo.getId().length() > 0) ? Character.toUpperCase(gmo.getId().charAt(0)) + gmo.getId().substring(1) : gmo.getId();
StringBuffer creationMethod = new StringBuffer();
- creationMethod.append(gmo.getId()).append(" = new ").append(classes.contains(gmo.getClassDescriptor().toString()) ? gmo.getClassDescriptor().getName() + "Impl" : gmo.getClassDescriptor().getName()).append("(").append(gmo.getConstructor() != null ? gmo.getConstructor() : "").append(");\n");
+ creationMethod.append(gmo.getId()).append(" = new ").append(classes.contains(gmo.getClassDescriptor().toString()) ? gmo.getClassDescriptor().toString() + "Impl" : clazz.getName()).append("(").append(gmo.getConstructor() != null ? gmo.getConstructor() : "").append(");\n");
componentsCreation.append("create").append(capitalizedId).append("();\n");
- constraint = processAttributes(clazz, gmo, bindings, creationMethod, null, seh, null);
+ //FIXME
+ if (gmo.getStyleSheets() != null) {
+ styleSheets.addAll(gmo.getStyleSheets());
+ }
+
+ constraint = processAttributes(clazz, gmo, bindings, creationMethod, null, seh, null, th);
+
//if gmo is the child of a cell
if (!((gmo.getParent().getClassDescriptor().getPackageName() == null || gmo.getParent().getClassDescriptor().getPackageName().equals("org.nuiton.guix.tags.swing")) && gmo.getParent().getClassDescriptor().getName().equalsIgnoreCase("Cell"))) {
//if gmo represents a JMenuBar
@@ -388,29 +387,13 @@
}
else {
//add the component to its parent
- componentsTree.append(gmo.getParent().getId() == null ? "this" : gmo.getParent().getId()).append(".add(").append(gmo.getId());
- //with a constraint if it is not null
- if (constraint != null) {
- componentsTree.append(",").append(constraint);
- }
- componentsTree.append(");\n");
- }
- }
- //FIXME
- if (gmo.getStyleSheets() != null) {
- styleSheets.addAll(gmo.getStyleSheets());
- }
-
- for (StyleSheet ss : styleSheets) {
- for (Selector sel : ss.getSelectors()) {
- if ((sel.getJavaClassName() == null || sel.getJavaClassName().equals(gmo.getClassDescriptor().getPackageName() + "." + gmo.getClassDescriptor().getName())) && (sel.getId() == null || sel.getId().equals(gmo.getId())) //&& sel.getPseudoClass().equals("")
- && (sel.getStyleClass() == null || sel.getStyleClass().equals(gmo.getStyleClass()))) {
- for (Rule rule : sel.getRules()) {
- for (Entry<String, String> entry : rule.getProperties().entrySet()) {
- String capitalizedAttribute = (entry.getKey().length() > 0) ? Character.toUpperCase(entry.getKey().charAt(0)) + entry.getKey().substring(1) : entry.getKey();
- creationMethod.append(gmo.getId()).append(".set").append(capitalizedAttribute).append("(").append(entry.getValue()).append(");\n");
- }
+ if(java.awt.Component.class.isAssignableFrom(clazz)) {
+ componentsTree.append(gmo.getParent().getId() == null ? "this" : gmo.getParent().getId()).append(".add(").append(gmo.getId());
+ //with a constraint if it is not null
+ if (constraint != null) {
+ componentsTree.append(",").append(constraint);
}
+ componentsTree.append(");\n");
}
}
}
@@ -419,7 +402,21 @@
//if gmo represents the first tag
else {
boolean layoutDefined = false;
- constraint = processAttributes(clazz, gmo, bindings, null, componentsTree, seh, layoutDefined);
+ //set superclass and interface
+ if(th != null) {
+ jf.setSuperClass(th.getClassToGenerate().getName());
+ }
+ else {
+ jf.setSuperClass(gmo.getClassDescriptor().getSuperClass().getPackageName() + "." + gmo.getClassDescriptor().getSuperClass().getName());
+ }
+ jf.addInterface(gmo.getClassDescriptor().getName());
+
+ //FIXME
+ if (gmo.getStyleSheets() != null) {
+ styleSheets.addAll(gmo.getStyleSheets());
+ }
+
+ constraint = processAttributes(clazz, gmo, bindings, null, componentsTree, seh, layoutDefined, th);
}
//browse the children of gmo
for (GuixModelObject child : gmo.getChildren()) {
@@ -449,11 +446,15 @@
* @param layoutDefined true if a layout has been defined
* @return
*/
- private String processAttributes(Class clazz, GuixModelObject gmo, StringBuffer bindings, StringBuffer creationMethod, StringBuffer componentsTree, SwingEventHandler seh, Boolean layoutDefined) {
+ private String processAttributes(Class clazz, GuixModelObject gmo, StringBuffer bindings, StringBuffer creationMethod,
+ StringBuffer componentsTree, SwingEventHandler seh, Boolean layoutDefined, TagHandler th) {
String constraint = null;
+ processCSSAttributes(gmo, seh, clazz);
//browses the attributes
for (AttributeDescriptor attr : gmo.getAttributeDescriptors()) {
-
+ if(th != null && th.getAttrToGenerate(attr.getName()) != null) {
+ attr.setName(th.getAttrToGenerate(attr.getName()));
+ }
boolean addQuote = false;
//the attribute name with the first letter capitalized
String capitalizedAttribute = (attr.getName().length() > 0) ? Character.toUpperCase(attr.getName().charAt(0)) + attr.getName().substring(1) : attr.getName();
@@ -476,20 +477,23 @@
if (realAttribute) {
//get the code of the binding (removes braces mostly)
String binding = BindingUtils.processDataBindings(attr.getValue());
- //if the attribute binds the value of another component attribute
- if (binding != null) {
- bindings.append("bindingGroup.addBinding(\n").append("org.jdesktop.beansbinding.Bindings.createAutoBinding(\n" +
- "org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ,").append("this").append(",org.jdesktop.beansbinding.ELProperty.create(\"${").append(binding).append("}\"),").append(gmo.getId()).append(",org.jdesktop.beansbinding.BeanProperty.create(\"").append(attr.getName()).append("\")").append("));\n").append("bindingGroup.bind();\n");
+
+ java.lang.reflect.Method[] methods = clazz.getMethods();
+ int m = 0;
+ //checks if the setter for this attribute exists
+ while(m < methods.length && !methods[m].getName().equals("set" + capitalizedAttribute)) {
+ m++;
}
- else {
- java.lang.reflect.Method[] methods = clazz.getMethods();
- int m = 0;
- //checks if the setter for this attribute exists
- while(m < methods.length && !methods[m].getName().equals("set" + capitalizedAttribute))
- m++;
- //if yes
- if(m < methods.length) {
- //checks if the parameter of the setter is a String
+ //if yes
+ if(m < methods.length) {
+ //if the attribute binds the value of another component attribute
+ if (binding != null) {
+ if(!bindings2Generate.containsKey(gmo.getId())) {
+ bindings2Generate.put(gmo.getId(), new HashMap<String, String>());
+ }
+ bindings2Generate.get(gmo.getId()).put(attr.getName(), binding);
+ }
+ else { //checks if the parameter of the setter is a String
addQuote = methods[m].getParameterTypes()[0].equals(String.class);
//generates the code to set the attribute to object
if(creationMethod != null)
@@ -502,10 +506,10 @@
layoutDefined = true;
}
}
- else if(log.isErrorEnabled()) {
- log.error(attr.getName() + " cannot be set.");
- }
}
+ else if(log.isErrorEnabled()) {
+ log.error(attr.getName() + " cannot be set.");
+ }
}
}
catch (IntrospectionException ex) {
@@ -532,5 +536,103 @@
//return the constraint to put the object into its parent
return constraint;
}
+
+ private void processCSSAttributes(GuixModelObject gmo, SwingEventHandler seh, Class clazz) {
+ Map<String, String> cssIds = new HashMap<String, String>();
+ Map<String, String> cssStyleClasses = new HashMap<String, String>();
+ Map<String, String> cssJavaClasses = new HashMap<String, String>();
+ List<AttributeDescriptor> ads = new ArrayList<AttributeDescriptor>();
+ for (StyleSheet ss : styleSheets) {
+ for (Selector sel : ss.getSelectors()) {
+ if((sel.getId() == null || sel.getId().equals(gmo.getId()))
+ && (sel.getStyleClass() == null || sel.getStyleClass().equals(gmo.getStyleClass()))
+ && (sel.getJavaClassName() == null || sel.getJavaClassName().equals(gmo.getClassDescriptor().getName()))) {
+ boolean realAttribute = true;
+ if (sel.getPseudoClass() != null && sel.getPseudoClass().startsWith("on") && Character.isUpperCase(sel.getPseudoClass().charAt(2))) {
+ //the swing event does not start by "on"
+ String lowerCaseAttribute = (sel.getPseudoClass().length() > 2) ? Character.toLowerCase(sel.getPseudoClass().charAt(2)) + sel.getPseudoClass().substring(3) : sel.getPseudoClass();
+ StringBuffer eventAction = new StringBuffer();
+
+ for (Rule rule : sel.getRules()) {
+ for (Entry<String, String> entry : rule.getProperties().entrySet()) {
+ java.lang.reflect.Method[] methods = clazz.getMethods();
+ String capitalizedAttribute = (entry.getKey().length() > 0) ? Character.toUpperCase(entry.getKey().charAt(0)) + entry.getKey().substring(1) : entry.getKey();
+ int m = 0;
+ //checks if the setter for this attribute exists
+ while(m < methods.length && !methods[m].getName().equals("set" + capitalizedAttribute)) {
+ m++;
+ }
+ //if yes
+ if(m < methods.length) {
+ //checks if the parameter of the setter is a String
+ boolean addQuote = methods[m].getParameterTypes()[0].equals(String.class);
+ //generates the code to set the attribute to object
+ eventAction.append(gmo.getId()).append(".set").append(capitalizedAttribute).append("(").append(addQuote ? "\"" : "").append(entry.getValue()).append(addQuote ? "\"" : "").append(");\n");
+ }
+ else if(log.isErrorEnabled()) {
+ log.error(entry.getKey() + " cannot be set.");
+ }
+ }
+ }
+ try {
+ realAttribute = !seh.addEvent(clazz, lowerCaseAttribute, eventAction.toString());
+ }
+ catch (IntrospectionException ex) {
+ if(log.isErrorEnabled()) {
+ log.error("Error while adding event " + sel.getPseudoClass());
+ }
+ }
+ }
+ if(realAttribute) {
+ if (sel.getId() != null && sel.getId().equals(gmo.getId())) {
+ for (Rule rule : sel.getRules()) {
+ for (Entry<String, String> entry : rule.getProperties().entrySet()) {
+ cssIds.put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ else if (sel.getStyleClass() != null && sel.getStyleClass().equals(gmo.getStyleClass())) {
+ for (Rule rule : sel.getRules()) {
+ for (Entry<String, String> entry : rule.getProperties().entrySet()) {
+ cssStyleClasses.put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ else if (sel.getJavaClassName() != null && sel.getJavaClassName().equals(gmo.getClassDescriptor().getName())) {
+ for (Rule rule : sel.getRules()) {
+ for (Entry<String, String> entry : rule.getProperties().entrySet()) {
+ cssJavaClasses.put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ for(Entry<String, String> entry : cssIds.entrySet()) {
+ ads.add(new AttributeDescriptor(entry.getKey(), entry.getValue()));
+ }
+ for(Entry<String, String> entry : cssStyleClasses.entrySet()) {
+ if(!cssIds.containsKey(entry.getKey())) {
+ ads.add(new AttributeDescriptor(entry.getKey(), entry.getValue()));
+ }
+ }
+ for(Entry<String, String> entry : cssJavaClasses.entrySet()) {
+ if(!cssIds.containsKey(entry.getKey()) && !cssStyleClasses.containsKey(entry.getKey())) {
+ ads.add(new AttributeDescriptor(entry.getKey(), entry.getValue()));
+ }
+ }
+ gmo.getAttributeDescriptors().addAll(ads);
+ }
+
+ @Override
+ public void generate(File out) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Map<String, Map<String, String>> getBindings2Generate() {
+ return bindings2Generate;
+ }
+
}
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingGenerator.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingGenerator.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/generator/SwingGenerator.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -18,10 +18,21 @@
*/
package org.nuiton.guix.generator;
+import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.swing.JComponent;
+import javax.swing.JPanel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.guix.tags.TagHandler;
/**
* Generates the interface, abstract class and implementation class
@@ -34,11 +45,14 @@
/** log */
protected Log log = LogFactory.getLog(SwingGenerator.class);
+ Map<SwingJavaFileGenerator, File> generators = new HashMap<SwingJavaFileGenerator, File>();
+
/**
* Generates the interface, abstract class and implementation class
* corresponding to the class described by the user.
*/
- public void generate() {
+ @Override
+ public JavaFile generate() {
String gmoClassName = gmo.getClassDescriptor().getName();
File out = new File(destDir, gmoClassName + ".java");
File outAbstract = new File(destDir, gmoClassName + "Abstract.java");
@@ -64,8 +78,11 @@
SwingImplementationGenerator simg = new SwingImplementationGenerator(gmo, classes);
sing.generate(out);
- sacg.generate(outAbstract);
+ generators.put(sing, out);
+ JavaFile jf = sacg.generates();
+ generators.put(sacg, outAbstract);
simg.generate(outImpl);
+ generators.put(simg, outImpl);
if (mainClass) {
SwingMainClassGenerator smcg = new SwingMainClassGenerator(gmo);
@@ -76,6 +93,10 @@
serializer.startTag("", "bean");
serializer.attribute("", "id", gmoClassName.replace(out.getName().charAt(0),
Character.toLowerCase(out.getName().charAt(0)))).attribute("", "class", gmoClassName + "Impl").attribute("", "singleton", "false").endTag("", "bean");
+
+ setBindingsToGenerate(sacg.getBindings2Generate());
+
+ return jf;
}
catch (IllegalArgumentException ex) {
log.error(ex);
@@ -90,5 +111,274 @@
else if (log.isWarnEnabled()) {
log.warn(gmo.getClassDescriptor().getName() + " has already been generated and is up to date.");
}
+ return null;
}
+
+ @Override
+ public void saveFiles() {
+ for(JavaFileGenerator gen : generators.keySet()) {
+ gen.saveFile(generators.get(gen));
+ }
+ }
+
+ @Override
+ public List<Class> generateBindings(StringBuffer dbCreation, StringBuffer dbDeletion, TagHandler prevTh, JavaFile jf, Class clazz,
+ String[] binding, int i, List<String> alreadyChecked, String methodToInvoke, Map<GuixGenerator,JavaFile> generatedFiles) {
+ boolean bindingExists = false;
+ String returnType = null;
+ String getter = null;
+ JavaFile nextFile = null;
+ Class nextClazz = null;
+ TagHandler th = null;
+ String model = null;
+ Class listener = null;
+ String addMethod = null;
+ String removeMethod = null;
+ List<Class> result = new ArrayList<Class>();
+
+ if(binding[i].endsWith(")")) {
+ String realMethodName = binding[i].substring(0, binding[i].indexOf("("));
+ String realAttributename = null;
+ if(prevTh != null) {
+ if(binding[i].startsWith("get")) {
+ realAttributename = prevTh.getAttrToGenerate(Character.toLowerCase(binding[i].charAt(3)) + binding[i].substring(4, binding[i].indexOf("(")));
+ if(realAttributename != null) {
+ realMethodName = "get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1);
+ }
+ }
+ else if(binding[i].startsWith("is")){
+ realAttributename = prevTh.getAttrToGenerate(Character.toLowerCase(binding[i].charAt(2)) + binding[i].substring(3, binding[i].indexOf("(")));
+ if(realAttributename != null) {
+ realMethodName = "is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1);
+ }
+ }
+ }
+ if(realAttributename == null) {
+ if(binding[i].startsWith("get")) {
+ realAttributename = Character.toLowerCase(binding[i].charAt(3)) + binding[i].substring(4, binding[i].indexOf("("));
+ }
+ else if(binding[i].startsWith("is")){
+ realAttributename = Character.toLowerCase(binding[i].charAt(2)) + binding[i].substring(3, binding[i].indexOf("("));
+ }
+ else {
+ realAttributename = binding[i].substring(0, binding[i].indexOf("("));
+ }
+ }
+ if (jf != null) {
+ bindingExists = jf.getMethod(realMethodName, null) != null;
+ if (bindingExists) {
+ returnType = jf.getMethod(realMethodName, null).getReturnType();
+ JavaField f = jf.getField(realAttributename);
+ if (f != null) {
+ th = f.getTagHandler();
+ }
+ }
+ }
+ else {
+ try {
+ clazz.getMethod(realMethodName, null);
+ returnType = clazz.getMethod(realMethodName, null).getReturnType().getName();
+ bindingExists = true;
+ }
+ catch (NoSuchMethodException eee) {
+ bindingExists = false;
+ }
+ }
+ getter = realMethodName + binding[i].substring(binding[i].indexOf("("));
+ }
+ else {
+ String realAttributename = null;
+ if(prevTh != null) {
+ realAttributename = prevTh.getAttrToGenerate(binding[i]);
+ }
+ if(realAttributename == null) {
+ realAttributename = binding[i];
+ }
+ if (jf != null) {
+ bindingExists = jf.getMethod("get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null) != null || jf.getMethod("is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null) != null;
+ if (bindingExists) {
+ returnType = jf.getMethod("get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null) != null ? jf.getMethod("get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null).getReturnType()
+ : jf.getMethod("is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null).getReturnType();
+ }
+
+ getter = jf.getMethod("get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null) != null ? "get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1) + "()"
+ : "is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1) + "()";
+
+ JavaField f = jf.getField(realAttributename);
+ if (f != null) {
+ th = f.getTagHandler();
+ }
+ }
+ else {
+ try {
+ clazz.getMethod("get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null);
+ returnType = clazz.getMethod("get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null).getReturnType().getName();
+ getter = "get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1) + "()";
+ bindingExists = true;
+ }
+ catch (NoSuchMethodException eee) {
+ try {
+ clazz.getMethod("is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null);
+ returnType = clazz.getMethod("is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null).getReturnType().getName();
+ getter = "is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1) + "()";
+ bindingExists = true;
+ }
+ catch (NoSuchMethodException eee2) {
+ bindingExists = false;
+ }
+ }
+ }
+ }
+ if(bindingExists) {
+ if(th != null) {
+ String getterWoBraces = getter.substring(0, getter.indexOf("("));
+ if(th.hasEventInfosAboutMethod(getterWoBraces)) {
+ model = th.getEventInfosModelName(getterWoBraces);
+ listener = th.getEventInfosListenerClass(getterWoBraces);
+ addMethod = th.getEventInfosAddListenerMethodName(getterWoBraces);
+ removeMethod = th.getEventInfosRemoveListenerMethodName(getterWoBraces);
+ }
+ else {
+ listener = PropertyChangeListener.class;
+ addMethod = "addPropertyChangeListener";
+ removeMethod = "removePropertyChangeListener";
+ }
+ }
+ else if(i == binding.length - 1 && prevTh != null) {
+ String getterWoBraces = getter.substring(0, getter.indexOf("("));
+ if(prevTh.hasEventInfosAboutMethod(getterWoBraces)) {
+ model = prevTh.getEventInfosModelName(getterWoBraces);
+ listener = prevTh.getEventInfosListenerClass(getterWoBraces);
+ addMethod = prevTh.getEventInfosAddListenerMethodName(getterWoBraces);
+ removeMethod = prevTh.getEventInfosRemoveListenerMethodName(getterWoBraces);
+ }
+ else {
+ listener = PropertyChangeListener.class;
+ addMethod = "addPropertyChangeListener";
+ removeMethod = "removePropertyChangeListener";
+ }
+ }
+ else {
+ listener = PropertyChangeListener.class;
+ addMethod = "addPropertyChangeListener";
+ removeMethod = "removePropertyChangeListener";
+ }
+
+ dbCreation.append("if(");
+ dbDeletion.append("if(");
+ if(alreadyChecked != null && !alreadyChecked.isEmpty()) {
+ for(int j = 0 ; j < alreadyChecked.size() ; j++) {
+ dbCreation.append(alreadyChecked.get(0));
+ dbDeletion.append(alreadyChecked.get(0));
+ for(int k = 1 ; k <= j ; k++) {
+ dbCreation.append(".").append(alreadyChecked.get(k));
+ dbDeletion.append(".").append(alreadyChecked.get(k));
+ }
+ dbCreation.append(" != null && ");
+ dbDeletion.append(" != null && ");
+ }
+
+ if(binding.length > alreadyChecked.size() + 1) {
+ for(int j = 0 ; j < alreadyChecked.size() ; j++) {
+ dbCreation.append(alreadyChecked.get(j)).append(".");
+ dbDeletion.append(alreadyChecked.get(j)).append(".");
+ }
+ dbCreation.append(getter).append(" != null");
+ dbDeletion.append(getter).append(" != null");
+ }
+ else {
+ dbCreation.delete(dbCreation.length() - 4, dbCreation.length());
+ dbDeletion.delete(dbDeletion.length() - 4, dbDeletion.length());
+ }
+ }
+ else {
+ dbCreation.append(getter).append(" != null");
+ dbDeletion.append(getter).append(" != null");
+ }
+ dbCreation.append(") {\n");
+ dbDeletion.append(") {\n");
+
+ if(alreadyChecked != null) {
+ for(int j = 0 ; j < alreadyChecked.size() ; j++) {
+ dbCreation.append(alreadyChecked.get(j)).append(".");
+ dbDeletion.append(alreadyChecked.get(j)).append(".");
+ }
+ }
+ if(model != null) {
+ dbCreation.append("get").append(Character.toUpperCase(model.charAt(0)))
+ .append(model.substring(1)).append("()");
+ dbDeletion.append("get").append(Character.toUpperCase(model.charAt(0)))
+ .append(model.substring(1)).append("()");
+ }
+ else {
+ dbCreation.append(getter);
+ dbDeletion.append(getter);
+ }
+// dbCreation.append(".").append(addMethod).append("((")
+// .append(listener.getName()).append(") org.nuiton.guix.runtime.Util.getEventListener(")
+// .append(listener.getName()).append(".class,this,\"onChangeFrom")
+// .append(methodToInvoke).append("\"));\n}\n");
+// dbDeletion.append(".").append(removeMethod).append("((")
+// .append(listener.getName()).append(") org.nuiton.guix.runtime.Util.getEventListener(")
+// .append(listener.getName()).append(".class,this,\"onChangeFrom")
+// .append(methodToInvoke).append("\"));\n}\n");
+
+ dbCreation.append(".").append(addMethod).append("(new ").append(listener.getName()).append("() {\n");
+ dbDeletion.append(".").append(removeMethod).append("(new ").append(listener.getName()).append("() {\n");
+ for(Method m : listener.getMethods()) {
+ StringBuffer sb = new StringBuffer();
+ for(Annotation a : m.getDeclaredAnnotations()) {
+ dbCreation.append(a.toString()).append("\n");
+ }
+ //add the method that handles the event
+ sb.append("public ")
+ .append(m.getReturnType().getCanonicalName())
+ .append(" ")
+ .append(m.getName())
+ .append("(");
+ for(int n = 0 ; n < m.getParameterTypes().length ; n++) {
+ sb.append(m.getParameterTypes()[n].getCanonicalName())
+ .append(" arg")
+ .append(n)
+ .append(", ");
+ }
+ sb.delete(sb.length() - 2, sb.length())
+ .append(")")
+ .append(" {\n")
+ .append("onChangeFrom").append(methodToInvoke)
+ .append("();\n}\n");
+ dbCreation.append(sb);
+ dbDeletion.append(sb);
+ }
+ dbCreation.append("});\n}\n");
+ dbDeletion.append("});\n}\n");
+
+ try {
+ nextClazz = Class.forName(returnType);
+ }
+ catch (ClassNotFoundException eee) {
+ for(JavaFile javaFile : generatedFiles.values()) {
+ if(returnType.equals(javaFile.getPackageName() + "." + javaFile.getClassName())) {
+ nextFile = javaFile;
+ break;
+ }
+ }
+ }
+ if(alreadyChecked == null){
+ alreadyChecked = new ArrayList<String>();
+ }
+ alreadyChecked.add(getter);
+ if(i + 1 < binding.length) {
+ result.addAll(generateBindings(dbCreation, dbDeletion, th, nextFile, nextClazz, binding, i+1, alreadyChecked, methodToInvoke, generatedFiles));
+ }
+ if(!result.contains(listener)) {
+ result.add(listener);
+ }
+ }
+ else if(log.isErrorEnabled()) {
+ log.error("unable to bind " + binding[i]);
+ }
+ return result;
+ }
+
}
Deleted: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ApplicationHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ApplicationHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ApplicationHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -1,22 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.nuiton.guix.tags.swing;
-
-/**
- *
- * @author kevin
- */
-public class ApplicationHandler extends org.nuiton.guix.tags.ApplicationHandler {
-
- public ApplicationHandler() {
- super();
- }
-
- public Class getClassToGenerate() {
- return javax.swing.JFrame.class;
- }
-
-}
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ButtonHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ButtonHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ButtonHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -9,8 +9,15 @@
*
* @author kevin
*/
-public class ButtonHandler extends org.nuiton.guix.tags.ButtonHandler {
+public class ButtonHandler extends ComponentHandler {
+ public ButtonHandler() {
+ super();
+ attrMap.put("onClick", "onActionPerformed");
+ attrMap.put("onLostFocus", "onFocusLost");
+ attrMap.put("onFocus", "onFocusGained");
+ }
+
@Override
public Class getClassToGenerate() {
return javax.swing.JButton.class;
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/CellHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/CellHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/CellHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -18,6 +18,7 @@
*/
package org.nuiton.guix.tags.swing;
+import org.nuiton.guix.model.AttributeDescriptor;
import org.nuiton.guix.model.GuixModelObject;
/**
@@ -25,8 +26,19 @@
*
* @author kevin
*/
-public class CellHandler extends org.nuiton.guix.tags.CellHandler {
+public class CellHandler extends TableHandler {
+ /** id of the object contained by the cell */
+ private String id = null;
+ /** number of columns of the cell */
+ private int columns = 1;
+ /** number of rows of the cell */
+ private int rows = 1;
+ /** index of the row */
+ private int row = -1;
+ /** index of the column */
+ private int column = -1;
+
/**
* Constructor
*/
@@ -40,7 +52,43 @@
* @param cell the GuixModelObject which represents the cell
*/
public CellHandler(GuixModelObject cell) {
- super(cell);
+ assert cell.getChildren().size() == 1;
+ id = cell.getChildren().get(0).getId();
+ for (AttributeDescriptor attr : cell.getAttributeDescriptors()) {
+ if (attr.getName().equals("columns")) {
+ columns = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("column")) {
+ column = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("rows")) {
+ rows = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("weightx")) {
+ weightx = Double.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("weighty")) {
+ weighty = Double.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("ipadx")) {
+ ipadx = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("ipady")) {
+ ipady = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("halign")) {
+ horizontalAlignment = getHalign(attr.getValue());
+ }
+ else if (attr.getName().equals("valign")) {
+ verticalAlignment = getValign(attr.getValue());
+ }
+ else if (attr.getName().equals("fill")) {
+ fill = attr.getValue();
+ }
+ else if (attr.getName().equals("insets")) {
+ insets = attr.getValue();
+ }
+ }
}
/**
@@ -50,11 +98,81 @@
* @param row the row which contains the cell
*/
public CellHandler(GuixModelObject cell, RowHandler row) {
- super(cell,row);
+ this(cell);
+ //if the attributes that the row contains too have not been defined by the user within the cell,
+ //but have been defined in the row (or the table), set them
+ if (horizontalAlignment == null) {
+ horizontalAlignment = row.getHorizontalAlignment() == null ? TableHandler.DEFAULT_HORIZONTAL_ALIGNMENT : row.getHorizontalAlignment();
+ }
+ if (verticalAlignment == null) {
+ verticalAlignment = row.getVerticalAlignment() == null ? TableHandler.DEFAULT_VERTICAL_ALIGNMENT : row.getVerticalAlignment();
+ }
+ if (fill == null) {
+ fill = row.getFill() == null ? TableHandler.DEFAULT_FILL : row.getFill();
+ }
+ if (insets == null) {
+ insets = row.getInsets() == null ? TableHandler.DEFAULT_INSETS : row.getInsets();
+ }
+ if (ipadx == null) {
+ ipadx = row.getIpadx() == null ? TableHandler.DEFAULT_IPADX : row.getIpadx();
+ }
+ if (ipady == null) {
+ ipady = row.getIpady() == null ? TableHandler.DEFAULT_IPADY : row.getIpady();
+ }
+ if (weightx == null) {
+ weightx = row.getWeightx() == null ? TableHandler.DEFAULT_WEIGHTX : row.getWeightx();
+ }
+ if (weighty == null) {
+ weighty = row.getWeighty() == null ? TableHandler.DEFAULT_WEIGHTY : row.getWeighty();
+ }
+ if(this.row == -1) {
+ this.row = row.getRow() < 0 ? -1 : row.getRow();
+ }
}
@Override
public Class getClassToGenerate() {
return null;
}
+
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public int getColumn() {
+ return column;
+ }
+
+ public void setColumn(int column) {
+ this.column = column;
+ }
+
+ public int getColumns() {
+ return columns;
+ }
+
+ public void setColumns(int columns) {
+ this.columns = columns;
+ }
+
+ public int getRow() {
+ return row;
+ }
+
+ public void setRow(int row) {
+ this.row = row;
+ }
+
+ public int getRows() {
+ return rows;
+ }
+
+ public void setRows(int rows) {
+ this.rows = rows;
+ }
}
Added: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ComponentHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ComponentHandler.java (rev 0)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ComponentHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -0,0 +1,39 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.nuiton.guix.tags.swing;
+import java.awt.event.ComponentListener;
+import java.awt.event.FocusListener;
+import org.nuiton.guix.tags.DefaultTagHandler;
+
+/**
+ *
+ * @author kevin
+ */
+public abstract class ComponentHandler extends DefaultTagHandler {
+
+ public ComponentHandler() {
+ super();
+ configureProxyEventInfo();
+ attrMap.put("onLostFocus", "onFocusLost");
+ attrMap.put("onFocus", "onFocusGained");
+ }
+
+ @Override
+ protected void configureProxyEventInfo() {
+ super.configureProxyEventInfo();
+ addProxyEventInfo("hasFocus", FocusListener.class);
+ addProxyEventInfo("isVisible", ComponentListener.class);
+ addProxyEventInfo("getBounds", ComponentListener.class);
+ addProxyEventInfo("getLocation", ComponentListener.class);
+ addProxyEventInfo("getLocationOnScreen", ComponentListener.class);
+ addProxyEventInfo("getSize", ComponentListener.class);
+ addProxyEventInfo("getX", ComponentListener.class);
+ addProxyEventInfo("getY", ComponentListener.class);
+ addProxyEventInfo("getWidth", ComponentListener.class);
+ addProxyEventInfo("getHeight", ComponentListener.class);
+ }
+
+}
Added: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/FrameHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/FrameHandler.java (rev 0)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/FrameHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -0,0 +1,22 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.nuiton.guix.tags.swing;
+
+/**
+ *
+ * @author kevin
+ */
+public class FrameHandler extends ComponentHandler {
+
+ public FrameHandler() {
+ super();
+ }
+
+ public Class getClassToGenerate() {
+ return javax.swing.JFrame.class;
+ }
+
+}
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/LabelHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/LabelHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/LabelHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -9,7 +9,7 @@
*
* @author kevin
*/
-public class LabelHandler extends org.nuiton.guix.tags.LabelHandler {
+public class LabelHandler extends ComponentHandler {
/**
* Constructor
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/MenuBarHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/MenuBarHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/MenuBarHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -9,7 +9,7 @@
*
* @author kevin
*/
-public class MenuBarHandler extends org.nuiton.guix.tags.MenuBarHandler {
+public class MenuBarHandler extends ComponentHandler {
/**
* Constructor
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/MenuHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/MenuHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/MenuHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -4,12 +4,13 @@
*/
package org.nuiton.guix.tags.swing;
+import javax.swing.event.MenuListener;
/**
*
* @author kevin
*/
-public class MenuHandler extends org.nuiton.guix.tags.MenuHandler {
+public class MenuHandler extends ComponentHandler {
/**
* Constructor
@@ -23,4 +24,9 @@
return javax.swing.JMenu.class;
}
+ @Override
+ protected void configureProxyEventInfo() {
+ super.configureProxyEventInfo();
+ addProxyEventInfo("isSelected", MenuListener.class);
+ }
}
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/MenuItemHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/MenuItemHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/MenuItemHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -9,13 +9,14 @@
*
* @author kevin
*/
-public class MenuItemHandler extends org.nuiton.guix.tags.MenuItemHandler {
+public class MenuItemHandler extends ComponentHandler {
/**
* Constructor
*/
public MenuItemHandler() {
super();
+ attrMap.put("action", "onActionPerformed");
}
@Override
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/PanelHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/PanelHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/PanelHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -9,7 +9,7 @@
*
* @author kevin
*/
-public class PanelHandler extends org.nuiton.guix.tags.PanelHandler {
+public class PanelHandler extends ComponentHandler {
/**
* Constructor
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/RowHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/RowHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/RowHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -18,6 +18,7 @@
*/
package org.nuiton.guix.tags.swing;
+import org.nuiton.guix.model.AttributeDescriptor;
import org.nuiton.guix.model.GuixModelObject;
/**
@@ -25,7 +26,10 @@
*
* @author kevin
*/
-public class RowHandler extends org.nuiton.guix.tags.RowHandler {
+public class RowHandler extends TableHandler {
+
+ /** index of the row */
+ private int row = -1;
/**
* Constructor
@@ -34,25 +38,87 @@
super();
}
- /**
+ /**
* Constructor
*
* @param row the GuixModelObject which represents the row
*/
- public RowHandler(GuixModelObject row) {
- super(row);
- }
+ public RowHandler(GuixModelObject row) {
+ for (AttributeDescriptor attr : row.getAttributeDescriptors()) {
+ if (attr.getName().equals("row")) {
+ this.row = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("weightx")) {
+ weightx = Double.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("weighty")) {
+ weighty = Double.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("ipadx")) {
+ ipadx = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("ipady")) {
+ ipady = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("halign")) {
+ horizontalAlignment = getHalign(attr.getValue());
+ }
+ else if (attr.getName().equals("valign")) {
+ verticalAlignment = getValign(attr.getValue());
+ }
+ else if (attr.getName().equals("fill")) {
+ fill = attr.getValue();
+ }
+ else if (attr.getName().equals("insets")) {
+ insets = attr.getValue();
+ }
+ }
+ }
- /**
+ /**
* Constructor
*
* @param row the GuixModelObject which represents the row
* @param table the table which contains the row
*/
- public RowHandler(GuixModelObject row, TableHandler table) {
- super(row, table);
+ public RowHandler(GuixModelObject row, TableHandler table) {
+ this(row);
+ //if the attributes that the table contains too have not been defined by the user within the row,
+ //but have been defined in the table, set them
+ if (horizontalAlignment == null) {
+ horizontalAlignment = table.getHorizontalAlignment() == null ? TableHandler.DEFAULT_HORIZONTAL_ALIGNMENT : table.getHorizontalAlignment();
+ }
+ if (verticalAlignment == null) {
+ verticalAlignment = table.getVerticalAlignment() == null ? TableHandler.DEFAULT_VERTICAL_ALIGNMENT : table.getVerticalAlignment();
+ }
+ if (fill == null) {
+ fill = table.getFill() == null ? TableHandler.DEFAULT_FILL : table.getFill();
+ }
+ if (insets == null) {
+ insets = table.getInsets() == null ? TableHandler.DEFAULT_INSETS : table.getInsets();
+ }
+ if (ipadx == null) {
+ ipadx = table.getIpadx() == null ? TableHandler.DEFAULT_IPADX : table.getIpadx();
+ }
+ if (ipady == null) {
+ ipady = table.getIpady() == null ? TableHandler.DEFAULT_IPADY : table.getIpady();
+ }
+ if (weightx == null) {
+ weightx = table.getWeightx() == null ? TableHandler.DEFAULT_WEIGHTX : table.getWeightx();
+ }
+ if (weighty == null) {
+ weighty = table.getWeighty() == null ? TableHandler.DEFAULT_WEIGHTY : table.getWeighty();
+ }
}
+ public int getRow() {
+ return row;
+ }
+
+ public void setRow(int row) {
+ this.row = row;
+ }
+
@Override
public Class getClassToGenerate() {
return null;
Added: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/SelectableButtonHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/SelectableButtonHandler.java (rev 0)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/SelectableButtonHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -0,0 +1,24 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.nuiton.guix.tags.swing;
+import javax.swing.event.ChangeListener;
+
+/**
+ *
+ * @author kevin
+ */
+public class SelectableButtonHandler extends ButtonHandler {
+
+ public SelectableButtonHandler() {
+ super();
+ }
+
+ @Override
+ public void configureProxyEventInfo() {
+ super.configureProxyEventInfo();
+ addProxyEventInfo("isSelected", ChangeListener.class, "model");
+ }
+}
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TabPanelHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TabPanelHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TabPanelHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -4,12 +4,14 @@
*/
package org.nuiton.guix.tags.swing;
+import java.awt.event.ContainerListener;
+import javax.swing.event.ChangeListener;
/**
*
* @author kevin
*/
-public class TabPanelHandler extends org.nuiton.guix.tags.TabPanelHandler {
+public class TabPanelHandler extends ComponentHandler {
/**
* Constructor
@@ -23,4 +25,12 @@
return javax.swing.JTabbedPane.class;
}
+ @Override
+ public void configureProxyEventInfo() {
+ super.configureProxyEventInfo();
+ addProxyEventInfo("getSelectedIndex", ChangeListener.class);
+ addProxyEventInfo("getSelectedComponent", ChangeListener.class);
+ addProxyEventInfo("getTabCount", ContainerListener.class);
+ }
+
}
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TableHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TableHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TableHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -22,6 +22,7 @@
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.guix.model.AttributeDescriptor;
import org.nuiton.guix.model.GuixModelObject;
/**
@@ -29,17 +30,41 @@
*
* @author kevin
*/
-public class TableHandler extends org.nuiton.guix.tags.TableHandler {
+public class TableHandler extends PanelHandler {
private static Log log = LogFactory.getLog(TableHandler.class);
public static String DEFAULT_ANCHOR = "java.awt.GridBagConstraints.FIRST_LINE_START";
+ protected enum VerticalAlignment {
+
+ ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM
+ }
+ protected enum HorizontalAlignment {
+
+ ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_DEFAULT
+ }
+ public static final String DEFAULT_INSETS = "3, 3, 3, 3";
+ public static final HorizontalAlignment DEFAULT_HORIZONTAL_ALIGNMENT = HorizontalAlignment.ALIGN_DEFAULT;
+ public static final VerticalAlignment DEFAULT_VERTICAL_ALIGNMENT = VerticalAlignment.ALIGN_TOP;
+ public static final String DEFAULT_FILL = "java.awt.GridBagConstraints.BOTH";
+ public static final Integer DEFAULT_IPADX = 1;
+ public static final Integer DEFAULT_IPADY = 1;
+ public static final Double DEFAULT_WEIGHTX = 0.0;
+ public static final Double DEFAULT_WEIGHTY = 0.0;
+ protected Double weightx = null;
+ protected Double weighty = null;
+ protected Integer ipadx = null;
+ protected Integer ipady = null;
+ protected HorizontalAlignment horizontalAlignment = null;
+ protected VerticalAlignment verticalAlignment = null;
+ protected String fill = null;
+ protected String insets = null;
+
/**
* Constructor
*/
public TableHandler() {
- super();
}
/**
@@ -48,8 +73,136 @@
* @param table the GuixModelObject which represents the table
*/
public TableHandler(GuixModelObject table) {
- super(table);
+
+ for (AttributeDescriptor attr : table.getAttributeDescriptors()) {
+ if (attr.getName().equals("weightx")) {
+ weightx = Double.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("weighty")) {
+ weighty = Double.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("ipadx")) {
+ ipadx = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("ipady")) {
+ ipady = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("halign")) {
+ horizontalAlignment = getHalign(attr.getValue());
+ if (horizontalAlignment == null) {
+ if (log.isErrorEnabled()) {
+ log.error(table.getId() + "'s halign attribute has a wrong value : " + attr.getValue());
+ }
+ horizontalAlignment = HorizontalAlignment.ALIGN_DEFAULT;
+ }
+ }
+ else if (attr.getName().equals("valign")) {
+ verticalAlignment = getValign(attr.getValue());
+ if (verticalAlignment == null) {
+ if (log.isErrorEnabled()) {
+ log.error(table.getId() + "'s halign attribute has a wrong value : " + attr.getValue());
+ }
+ verticalAlignment = VerticalAlignment.ALIGN_TOP;
+ }
+ }
+ else if (attr.getName().equals("fill")) {
+ fill = attr.getValue();
+ }
+ else if (attr.getName().equals("insets")) {
+ insets = attr.getValue();
+ }
+ }
}
+
+ public HorizontalAlignment getHorizontalAlignment() {
+ return horizontalAlignment;
+ }
+
+ public void setHorizontalAlignment(HorizontalAlignment horizontalAlignment) {
+ this.horizontalAlignment = horizontalAlignment;
+ }
+
+ public VerticalAlignment getVerticalAlignment() {
+ return verticalAlignment;
+ }
+
+ public void setVerticalAlignment(VerticalAlignment verticalAlignment) {
+ this.verticalAlignment = verticalAlignment;
+ }
+
+ public String getFill() {
+ return fill;
+ }
+
+ public void setFill(String fill) {
+ this.fill = fill;
+ }
+
+ public String getInsets() {
+ return insets;
+ }
+
+ public void setInsets(String insets) {
+ this.insets = insets;
+ }
+
+ public Integer getIpadx() {
+ return ipadx;
+ }
+
+ public void setIpadx(Integer ipadx) {
+ this.ipadx = ipadx;
+ }
+
+ public Integer getIpady() {
+ return ipady;
+ }
+
+ public void setIpady(Integer ipady) {
+ this.ipady = ipady;
+ }
+
+ public Double getWeightx() {
+ return weightx;
+ }
+
+ public void setWeightx(Double weightx) {
+ this.weightx = weightx;
+ }
+
+ public Double getWeighty() {
+ return weighty;
+ }
+
+ public void setWeighty(Double weighty) {
+ this.weighty = weighty;
+ }
+
+ public HorizontalAlignment getHalign(String halign) {
+ if (halign.equalsIgnoreCase("left")) {
+ return HorizontalAlignment.ALIGN_LEFT;
+ }
+ if (halign.equalsIgnoreCase("right")) {
+ return HorizontalAlignment.ALIGN_RIGHT;
+ }
+ if (halign.equalsIgnoreCase("center")) {
+ return HorizontalAlignment.ALIGN_CENTER;
+ }
+ return null;
+ }
+
+ public VerticalAlignment getValign(String valign) {
+ if (valign.equalsIgnoreCase("top")) {
+ return VerticalAlignment.ALIGN_TOP;
+ }
+ if (valign.equalsIgnoreCase("bottom")) {
+ return VerticalAlignment.ALIGN_BOTTOM;
+ }
+ if (valign.equalsIgnoreCase("middle")) {
+ return VerticalAlignment.ALIGN_MIDDLE;
+ }
+ return null;
+ }
/**
* Creates a cell with the right column and generates the code to add it to the table
@@ -208,9 +361,4 @@
return null;
}
- @Override
- public Class getClassToGenerate() {
- return javax.swing.JPanel.class;
- }
-
}
Added: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TextComponentHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TextComponentHandler.java (rev 0)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TextComponentHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -0,0 +1,24 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.nuiton.guix.tags.swing;
+import javax.swing.event.DocumentListener;
+
+/**
+ *
+ * @author kevin
+ */
+public abstract class TextComponentHandler extends ComponentHandler {
+
+ public TextComponentHandler() {
+ super();
+ }
+
+ @Override
+ public void configureProxyEventInfo() {
+ super.configureProxyEventInfo();
+ addProxyEventInfo("getText", DocumentListener.class, "document");
+ }
+}
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TextFieldHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TextFieldHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/TextFieldHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -9,7 +9,7 @@
*
* @author kevin
*/
-public class TextFieldHandler extends org.nuiton.guix.tags.TextFieldHandler {
+public class TextFieldHandler extends TextComponentHandler {
/**
* Constructor
Modified: trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ToggleButtonHandler.java
===================================================================
--- trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ToggleButtonHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
+++ trunk/guix-compiler-swing/src/main/java/org/nuiton/guix/tags/swing/ToggleButtonHandler.java 2009-07-22 13:08:00 UTC (rev 1503)
@@ -4,16 +4,20 @@
*/
package org.nuiton.guix.tags.swing;
+import javax.swing.event.ChangeListener;
/**
*
* @author kevin
*/
-public class ToggleButtonHandler extends org.nuiton.guix.tags.ToggleButtonHandler {
+public class ToggleButtonHandler extends SelectableButtonHandler {
+ public ToggleButtonHandler() {
+ super();
+ }
+
@Override
public Class getClassToGenerate() {
return javax.swing.JToggleButton.class;
}
-
}
1
0
r1502 - in trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix: events generator tags/gwt
by kmorin@users.labs.libre-entreprise.org 22 Jul '09
by kmorin@users.labs.libre-entreprise.org 22 Jul '09
22 Jul '09
Author: kmorin
Date: 2009-07-22 15:07:30 +0200 (Wed, 22 Jul 2009)
New Revision: 1502
Added:
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator1.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/UIObjectHandler.java
Modified:
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/events/GwtEventHandler.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtAbstractClassGenerator.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtInterfaceGenerator.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ApplicationHandler.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ButtonHandler.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/CellHandler.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/LabelHandler.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/MenuBarHandler.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/MenuHandler.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/MenuItemHandler.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/PanelHandler.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/RowHandler.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TabPanelHandler.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TableHandler.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TextFieldHandler.java
trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ToggleButtonHandler.java
Log:
Added the proxyEventInfo
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/events/GwtEventHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/events/GwtEventHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/events/GwtEventHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -128,12 +128,12 @@
.append(" ")
.append(m.getName())
.append("(");
- for(Class clazz : m.getParameterTypes())
- result.append(clazz.getCanonicalName())
- .append(" ")
- .append(Character.toLowerCase(clazz.getName().charAt(clazz.getName().lastIndexOf('.') + 1)))
- .append(clazz.getName().substring(clazz.getName().lastIndexOf('.') + 2))
- .append(", ");
+ for(int n = 0 ; n < m.getParameterTypes().length ; n++) {
+ result.append(m.getParameterTypes()[n].getCanonicalName())
+ .append(" arg")
+ .append(n)
+ .append(", ");
+ }
result.delete(result.length() - 2, result.length())
.append(")")
.append("{\n")
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtAbstractClassGenerator.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtAbstractClassGenerator.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtAbstractClassGenerator.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -19,10 +19,8 @@
package org.nuiton.guix.generator;
//~--- non-JDK imports --------------------------------------------------------
-import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MenuBar;
-import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.TabPanel;
import java.beans.IntrospectionException;
import org.nuiton.guix.model.GuixModelObject;
@@ -46,6 +44,8 @@
import org.nuiton.guix.tags.TagManager;
import org.nuiton.guix.tags.gwt.CellHandler;
import org.nuiton.guix.tags.gwt.MenuBarHandler;
+import org.nuiton.guix.tags.gwt.MenuHandler;
+import org.nuiton.guix.tags.gwt.MenuItemHandler;
import org.nuiton.guix.tags.gwt.RowHandler;
import org.nuiton.guix.tags.gwt.TabPanelHandler;
import org.nuiton.guix.tags.gwt.TableHandler;
@@ -61,6 +61,8 @@
List<StyleSheet> styleSheets = new ArrayList<StyleSheet>();
/** map of the different parts of the script associated with gmo */
Map<ScriptPart, Object> script;
+ /** Bindings to generate */
+ Map<String,Map<String, String>> bindings2Generate = new HashMap<String,Map<String, String>>();
/**
* Constructor
@@ -80,8 +82,8 @@
script = sh.decomposeScript(gmo.getClassDescriptor().getScript());
}
- @Override
- public void generate(File out) {
+ //@Override
+ public JavaFile generates() {
super.generate();
//add imports
@@ -92,8 +94,11 @@
//add bodycode
jf.addBodyCode((String) script.get(ScriptPart.BODYCODE));
- //add fields
- addFields(gmo);
+// //add implementation of firePropertyChange
+// JavaArgument[] args = new JavaArgument[]{new JavaArgument("String", "name"),
+// new JavaArgument("Object", "oldValue"),
+// new JavaArgument("Object", "newValue")};
+// jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "firePropertyChange", args, null, "super.firePropertyChange(name, oldValue, newValue);", null));
//add constructor
jf.addMethod(new JavaMethod(Modifier.PUBLIC, null, gmo.getClassDescriptor().getName() + "Abstract",
@@ -141,65 +146,18 @@
jf.addMethod(m);
}
}
- //set superclass and interface
- jf.setSuperClass(gmo.getClassDescriptor().getSuperClass().getPackageName() + "." + gmo.getClassDescriptor().getSuperClass().getName());
- jf.addInterface(gmo.getClassDescriptor().getName());
-
- //save the file
- saveFile(out);
+
+ return jf;
}
catch (ClassNotFoundException eee) {
if (log.isErrorEnabled()) {
log.error(eee);
}
}
+ return null;
}
/**
- * Adds fields to the file to generate
- *
- * @param gmo the GuixModelObject to analyze
- */
- private void addFields(GuixModelObject gmo) {
- for (GuixModelObject child : gmo.getChildren()) {
- //if gmo represents a Guix tag
- if (child.getClassDescriptor().getPackageName() == null
- && TagManager.getGuixClassHandler(child.getClassDescriptor().getName()) != null) {
- Class clazz;
- try {
- TagHandler th = (TagHandler)TagManager.getGuixClassHandler(child.getClassDescriptor().getName()).newInstance();
- if(th.getClassToGenerate() != null) {
- clazz = th.getClassToGenerate();
- jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE,
- clazz.getSimpleName(), child.getId(),
- " new " + clazz.getSimpleName() + "(" +
- ((child.getConstructor() != null) ? child.getConstructor() : "") + ")", child.getJavadoc()),
- false);
- }
- }
- catch (InstantiationException eee) {
- if(log.isErrorEnabled()) {
- log.error(eee);
- }
- }
- catch (IllegalAccessException eee) {
- if(log.isErrorEnabled()) {
- log.error(eee);
- }
- }
- }
- else {
- jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE,
- (classes != null && classes.contains(child.getClassDescriptor().toString())) ? child.getClassDescriptor().getName() + "Abstract" : child.getClassDescriptor().getName(),
- child.getId(), "new " + ((classes != null && classes.contains(child.getClassDescriptor().toString())) ? child.getClassDescriptor().getName() + "Impl" : child.getClassDescriptor().getName()) + "(" +
- ((child.getConstructor() != null) ? child.getConstructor() : "") + ")", child.getJavadoc()),
- false);
- }
- addFields(child);
- }
- }
-
- /**
* Browse the GuixModelObjects to add the creation, initialization and bindings methods to the file to gnerate
*
* @param gmo the GuixModelObject to analyze
@@ -214,7 +172,10 @@
String tabName = null;
Class clazz = null;
- if(gmo.getParent() != null && gmo.getParent().getClassDescriptor().toString().equals(TabPanel.class.getName())) {
+ if(gmo.getParent() != null
+ && (gmo.getParent().getClassDescriptor().toString().equals(TabPanel.class.getName())
+ || (gmo.getParent().getClassDescriptor().getPackageName() == null
+ && gmo.getParent().getClassDescriptor().getName().equals("TabPanel")))) {
int i = 0;
while(i < gmo.getAttributeDescriptors().size() && tabName == null) {
if(gmo.getAttributeDescriptors().get(i).getName().equalsIgnoreCase("name")) {
@@ -233,9 +194,15 @@
TableHandler table = new TableHandler(gmo);
//the table is a FlexPanel
clazz = table.getClassToGenerate();
+ jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE,
+ clazz.getSimpleName(), gmo.getId(),
+ " new " + clazz.getSimpleName() + "(" +
+ ((gmo.getConstructor() != null) ? gmo.getConstructor() : "") + ")", gmo.getJavadoc(), table),
+ false);
+
creationMethod.append(gmo.getId())
.append(".addStyleName(\"Table\");\n");
- processAttributes(clazz, gmo, creationMethod, null, geh);
+ processAttributes(clazz, gmo, creationMethod, null, geh, table);
//add the component to its parent
componentsTree.append(gmo.getParent().getId() == null ? "this" : gmo.getParent().getId()).append(".add(").append(gmo.getId());
@@ -270,7 +237,7 @@
//the cell can contain only one component
else if (cell.getChildren().size() != 1) {
if (log.isErrorEnabled()) {
- log.error("Cells must contain only one tag !");
+ log.error("Cells must contain only one tag ! : " + cell.getId() + " has " + cell.getChildren().size() + "children");
}
}
else {
@@ -295,8 +262,13 @@
StringBuffer creationMethod = new StringBuffer();
MenuBarHandler menuBar = new MenuBarHandler();
clazz = menuBar.getClassToGenerate();
+ jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE,
+ clazz.getSimpleName(), gmo.getId(),
+ " new " + clazz.getSimpleName() + "(" +
+ ((gmo.getConstructor() != null) ? gmo.getConstructor() : "") + ")", gmo.getJavadoc(), menuBar),
+ false);
- processAttributes(clazz, gmo, creationMethod, null, geh);
+ processAttributes(clazz, gmo, creationMethod, null, geh, menuBar);
//add the component to its parent
componentsTree.append(gmo.getParent().getId() == null ? "this" : gmo.getParent().getId()).append(".add(").append(gmo.getId());
@@ -318,11 +290,12 @@
}
//if gmo represents a "normal" tag
else {
+ TagHandler th = null;
+
if(TagManager.getGuixClassHandler(gmo.getClassDescriptor().getName()) != null) {
try {
- clazz = ((TagHandler)TagManager.getGuixClassHandler(gmo.getClassDescriptor().getName()).newInstance()).getClassToGenerate();
- gmo.getClassDescriptor().setPackageName(clazz.getPackage().getName());
- gmo.getClassDescriptor().setName(clazz.getSimpleName());
+ th = (TagHandler) TagManager.getGuixClassHandler(gmo.getClassDescriptor().getName()).newInstance();
+ clazz = th.getClassToGenerate();
}
catch (InstantiationException eee) {
if(log.isErrorEnabled()) {
@@ -337,10 +310,8 @@
}
else if(gmo.getClassDescriptor().getSuperClass() != null && TagManager.getGuixClassHandler(gmo.getClassDescriptor().getSuperClass().getName()) != null) {
try {
- TagHandler th = (TagHandler)TagManager.getGuixClassHandler(gmo.getClassDescriptor().getSuperClass().getName()).newInstance();
+ th = (TagHandler) TagManager.getGuixClassHandler(gmo.getClassDescriptor().getSuperClass().getName()).newInstance();
clazz = th.getClassToGenerate();
- gmo.getClassDescriptor().getSuperClass().setPackageName(clazz.getPackage().getName());
- gmo.getClassDescriptor().getSuperClass().setName(clazz.getSimpleName());
}
catch (InstantiationException eee) {
if(log.isErrorEnabled()) {
@@ -353,13 +324,14 @@
}
}
}
+
ClassLoader cl = Label.class.getClassLoader();
ClassDescriptor cd = gmo.getClassDescriptor();
while (clazz == null && cd != null) {
try {
clazz = cl.loadClass(cd.getPackageName() + "." + cd.getName());
}
- catch (ClassNotFoundException ex) {
+ catch (ClassNotFoundException eee) {
cd = cd.getSuperClass();
}
}
@@ -370,7 +342,7 @@
try {
clazz = cl.loadClass(cd.getPackageName() + "." + cd.getName());
}
- catch (ClassNotFoundException ex) {
+ catch (ClassNotFoundException eee) {
cd = cd.getSuperClass();
}
}
@@ -379,6 +351,28 @@
throw new ClassNotFoundException();
}
+ if (gmo.getClassDescriptor().getPackageName() == null
+ && TagManager.getGuixClassHandler(gmo.getClassDescriptor().getName()) != null) {
+ jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE,
+ clazz.getName(), gmo.getId(),
+ " new " + clazz.getSimpleName() + "(" +
+ ((gmo.getConstructor() != null) ? gmo.getConstructor() : "") + ")", gmo.getJavadoc(), th),
+ false);
+ }
+ else if(gmo.getId() == null) {
+ jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE,
+ (classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().getPackageName() + ".client." + gmo.getClassDescriptor().getName() + "Abstract" : gmo.getClassDescriptor().getPackageName() + "." + gmo.getClassDescriptor().getName(),
+ gmo.getClassDescriptor().getName().toLowerCase(), "this", gmo.getJavadoc(), th),
+ false);
+ }
+ else {
+ jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE,
+ (classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().getPackageName() + ".client." + gmo.getClassDescriptor().getName() + "Abstract" : gmo.getClassDescriptor().getPackageName() + "." + gmo.getClassDescriptor().getName(),
+ gmo.getId(), "new " + ((classes != null && classes.contains(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().getName() + "Impl" : gmo.getClassDescriptor().getName()) + "(" +
+ ((gmo.getConstructor() != null) ? gmo.getConstructor() : "") + ")", gmo.getJavadoc(), th),
+ false);
+ }
+
if (gmo.getParent() != null) {
String capitalizedId = (gmo.getId().length() > 0) ? Character.toUpperCase(gmo.getId().charAt(0)) + gmo.getId().substring(1) : gmo.getId();
StringBuffer creationMethod = new StringBuffer();
@@ -392,11 +386,19 @@
}
componentsTree.append(");\n");
}
- processAttributes(clazz, gmo, creationMethod, null, geh);
+ processAttributes(clazz, gmo, creationMethod, null, geh, th);
}
else {
- processAttributes(clazz, gmo, null, componentsTree, geh);
+ processAttributes(clazz, gmo, null, componentsTree, geh, th);
+ //set superclass and interface
+ if(th != null) {
+ jf.setSuperClass(th.getClassToGenerate().getName());
+ }
+ else {
+ jf.setSuperClass(gmo.getClassDescriptor().getSuperClass().getPackageName() + "." + gmo.getClassDescriptor().getSuperClass().getName());
+ }
+ jf.addInterface(gmo.getClassDescriptor().getName());
}
for (GuixModelObject child : gmo.getChildren()) {
Map<Method, String> methodBodies = browseModelObjects(child);
@@ -422,11 +424,13 @@
* @param geh the event handler
* @return
*/
- private void processAttributes(Class clazz, GuixModelObject gmo, StringBuffer creationMethod, StringBuffer componentsTree, GwtEventHandler geh) {
+ private void processAttributes(Class clazz, GuixModelObject gmo, StringBuffer creationMethod, StringBuffer componentsTree, GwtEventHandler geh, TagHandler th) {
//browses the attributes
for (AttributeDescriptor attr : gmo.getAttributeDescriptors()) {
-
boolean addQuote = false;
+ if(th != null && th.getAttrToGenerate(attr.getName()) != null) {
+ attr.setName(th.getAttrToGenerate(attr.getName()));
+ }
//the attribute name with the first letter capitalized
String capitalizedAttribute = (attr.getName().length() > 0) ? Character.toUpperCase(attr.getName().charAt(0)) + attr.getName().substring(1) : attr.getName();
//is the attribute a "real" attribute ? false if it represents an event or a constraint
@@ -444,8 +448,10 @@
String binding = BindingUtils.processDataBindings(attr.getValue());
//if the attribute binds the value of another component attribute
if (binding != null) {
-// bindings.append("bindingGroup.addBinding(\n").append("org.jdesktop.beansbinding.Bindings.createAutoBinding(\n" +
-// "org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ,").append("this").append(",org.jdesktop.beansbinding.ELProperty.create(\"${").append(binding).append("}\"),").append(gmo.getId()).append(",org.jdesktop.beansbinding.BeanProperty.create(\"").append(attr.getName()).append("\")").append("));\n").append("bindingGroup.bind();\n");
+ if(!bindings2Generate.containsKey(gmo.getId())) {
+ bindings2Generate.put(gmo.getId(), new HashMap<String, String>());
+ }
+ bindings2Generate.get(gmo.getId()).put(attr.getName(), binding);
}
else {
java.lang.reflect.Method[] methods = clazz.getMethods();
@@ -500,11 +506,21 @@
String text = null, cmd = null;
if(gmo.getClassDescriptor().getPackageName() == null && gmo.getClassDescriptor().getName().equals("Menu")) {
+ TagHandler th = new MenuHandler();
+ Class clazz = th.getClassToGenerate();
+ jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE,
+ clazz.getName(), gmo.getId(),
+ " new " + clazz.getSimpleName() + "(" +
+ ((gmo.getConstructor() != null) ? gmo.getConstructor() : "") + ")", gmo.getJavadoc(), th),
+ false);
for(AttributeDescriptor attr : gmo.getAttributeDescriptors()) {
if(attr.getName().equalsIgnoreCase("text")) {
text = attr.getValue();
}
else {
+ if(th.getAttrToGenerate(attr.getName()) != null) {
+ attr.setName(th.getAttrToGenerate(attr.getName()));
+ }
//the attribute name with the first letter capitalized
String capitalizedAttribute = (attr.getName().length() > 0) ? Character.toUpperCase(attr.getName().charAt(0)) + attr.getName().substring(1) : attr.getName();
@@ -536,14 +552,18 @@
}
}
else if(gmo.getClassDescriptor().getPackageName() == null && gmo.getClassDescriptor().getName().equals("MenuItem")) {
+ TagHandler th = new MenuItemHandler();
for(AttributeDescriptor attr : gmo.getAttributeDescriptors()) {
if(attr.getName().equalsIgnoreCase("text")) {
text = attr.getValue();
}
- if(attr.getName().equalsIgnoreCase("command")) {
+ if(attr.getName().equalsIgnoreCase("action")) {
cmd = attr.getValue();
}
else {
+ if(th.getAttrToGenerate(attr.getName()) != null) {
+ attr.setName(th.getAttrToGenerate(attr.getName()));
+ }
if (log.isErrorEnabled()) {
log.error(attr.getName() + " cannot be set.");
}
@@ -563,5 +583,14 @@
result.put(Method.DATABINDING_INIT, bindings.toString());
return result;
}
+
+ public Map<String, Map<String, String>> getBindings2Generate() {
+ return bindings2Generate;
+ }
+
+ @Override
+ public void generate(File out) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
}
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -18,10 +18,18 @@
*/
package org.nuiton.guix.generator;
+import com.google.gwt.user.client.ui.Label;
import java.io.File;
import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.guix.tags.TagHandler;
/**
* Generates the interface, abstract class and implementation class
@@ -34,13 +42,15 @@
/** log */
private Log log = LogFactory.getLog(GwtGenerator.class);
-
+ Map<GwtJavaFileGenerator, File> generators = new HashMap<GwtJavaFileGenerator, File>();
+
@Override
- public void generate() {
+ public JavaFile generate() {
String gmoClassName = gmo.getClassDescriptor().getName();
File outDir = new File(destDir, "client");
- if(!outDir.exists())
+ if (!outDir.exists()) {
outDir.mkdir();
+ }
File out = new File(outDir, gmoClassName + ".java");
File outAbstract = new File(outDir, gmoClassName + "Abstract.java");
File outImpl = new File(outDir, gmoClassName + "Impl.java");
@@ -69,21 +79,28 @@
GwtConfigGenerator gcg = new GwtConfigGenerator(gmo);
GwtHtmlGenerator ghg = new GwtHtmlGenerator(gmo, launcherName);
File outConfigMain = new File(destDir, launcherName.substring(launcherName.lastIndexOf('.') + 1) + ".gwt.xml");
- File publicDir = new File(destDir,"public");
- if(!publicDir.exists())
+ File publicDir = new File(destDir, "public");
+ if (!publicDir.exists()) {
publicDir.mkdir();
+ }
File outHtmlMain = new File(publicDir, launcherName.substring(launcherName.lastIndexOf('.') + 1) + ".html");
gcg.generate(outConfigMain);
ghg.generate(outHtmlMain);
}
ging.generate(out);
- gacg.generate(outAbstract);
+ generators.put(ging, out);
+ JavaFile jf = gacg.generates();
+ generators.put(gacg, outAbstract);
gimg.generate(outImpl);
+ generators.put(gimg, outImpl);
serializer.startTag("", "bean");
serializer.attribute("", "id", gmoClassName.replace(out.getName().charAt(0),
Character.toLowerCase(out.getName().charAt(0)))).attribute("", "class", gmoClassName + "Impl").attribute("", "singleton", "false").endTag("", "bean");
+ setBindingsToGenerate(gacg.getBindings2Generate());
+
+ return jf;
}
catch (IllegalArgumentException ex) {
log.error(ex);
@@ -98,6 +115,248 @@
else if (log.isWarnEnabled()) {
log.warn(gmo.getClassDescriptor().getName() + " has already been generated and is up to date.");
}
+ return null;
}
+ @Override
+ public void saveFiles() {
+ for (JavaFileGenerator gen : generators.keySet()) {
+ gen.saveFile(generators.get(gen));
+ }
+ }
+
+ @Override
+ public List<Class> generateBindings(StringBuffer dbCreation, StringBuffer dbDeletion, TagHandler prevTh, JavaFile jf, Class clazz,
+ String[] binding, int i, List<String> alreadyChecked, String methodToInvoke, Map<GuixGenerator, JavaFile> generatedFiles) {
+ boolean bindingExists = false;
+ String returnType = null;
+ String getter = null;
+ JavaFile nextFile = null;
+ Class nextClazz = null;
+ TagHandler th = null;
+ String model = null;
+ Class listener = null;
+ String addMethod = null;
+ String removeMethod = null;
+ List<Class> result = new ArrayList<Class>();
+
+ if (binding[i].endsWith(")")) {
+ String realMethodName = binding[i].substring(0, binding[i].indexOf("("));
+ String realAttributename = null;
+ if(prevTh != null) {
+ if(binding[i].startsWith("get")) {
+ realAttributename = prevTh.getAttrToGenerate(Character.toLowerCase(binding[i].charAt(3)) + binding[i].substring(4, binding[i].indexOf("(")));
+ if(realAttributename != null) {
+ realMethodName = "get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1);
+ }
+ }
+ else if(binding[i].startsWith("is")){
+ realAttributename = prevTh.getAttrToGenerate(Character.toLowerCase(binding[i].charAt(2)) + binding[i].substring(3, binding[i].indexOf("(")));
+ if(realAttributename != null) {
+ realMethodName = "is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1);
+ }
+ }
+ }
+ if(realAttributename == null) {
+ if(binding[i].startsWith("get")) {
+ realAttributename = Character.toLowerCase(binding[i].charAt(3)) + binding[i].substring(4, binding[i].indexOf("("));
+ }
+ else if(binding[i].startsWith("is")){
+ realAttributename = Character.toLowerCase(binding[i].charAt(2)) + binding[i].substring(3, binding[i].indexOf("("));
+ }
+ else {
+ realAttributename = binding[i].substring(0, binding[i].indexOf("("));
+ }
+ }
+ if (jf != null) {
+ bindingExists = jf.getMethod(realMethodName, null) != null;
+ if (bindingExists) {
+ returnType = jf.getMethod(realMethodName, null).getReturnType();
+ JavaField f = jf.getField(realAttributename);
+ if (f != null) {
+ th = f.getTagHandler();
+ }
+ }
+ }
+ else {
+ try {
+ clazz.getMethod(realMethodName, null);
+ returnType = clazz.getMethod(realMethodName, null).getReturnType().getName();
+ bindingExists = true;
+ }
+ catch (NoSuchMethodException eee) {
+ bindingExists = false;
+ }
+ }
+ getter = realMethodName + binding[i].substring(binding[i].indexOf("("));
+ binding[i] = getter;
+ }
+ else {
+ String realAttributename = null;
+ if(prevTh != null) {
+ realAttributename = prevTh.getAttrToGenerate(binding[i]);
+ }
+ if(realAttributename == null) {
+ realAttributename = binding[i];
+ }
+ if (jf != null) {
+ bindingExists = jf.getMethod("get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null) != null || jf.getMethod("is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null) != null;
+ if (bindingExists) {
+ returnType = jf.getMethod("get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null) != null ? jf.getMethod("get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null).getReturnType()
+ : jf.getMethod("is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null).getReturnType();
+ }
+
+ getter = jf.getMethod("get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null) != null ? "get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1) + "()"
+ : "is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1) + "()";
+
+ JavaField f = jf.getField(realAttributename);
+ if (f != null) {
+ th = f.getTagHandler();
+ }
+ }
+ else {
+ try {
+ clazz.getMethod("get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null);
+ returnType = clazz.getMethod("get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null).getReturnType().getName();
+ getter = "get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1) + "()";
+ bindingExists = true;
+ }
+ catch (NoSuchMethodException eee) {
+ try {
+ clazz.getMethod("is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null);
+ returnType = clazz.getMethod("is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), null).getReturnType().getName();
+ getter = "is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1) + "()";
+ bindingExists = true;
+ }
+ catch (NoSuchMethodException eee2) {
+ bindingExists = false;
+ }
+ }
+ }
+ binding[i] = getter;
+ }
+ if (bindingExists) {
+ if (i == binding.length - 1 && prevTh != null) {
+ String getterWoBraces = getter.substring(0, getter.indexOf("("));
+ if (prevTh.hasEventInfosAboutMethod(getterWoBraces)) {
+ model = prevTh.getEventInfosModelName(getterWoBraces);
+ listener = prevTh.getEventInfosListenerClass(getterWoBraces);
+ addMethod = prevTh.getEventInfosAddListenerMethodName(getterWoBraces);
+ removeMethod = prevTh.getEventInfosRemoveListenerMethodName(getterWoBraces);
+ }
+ else {
+ log.error("Impossible binding");
+ return null;
+ }
+
+ dbCreation.append("if(");
+ dbDeletion.append("if(");
+ if (alreadyChecked != null && !alreadyChecked.isEmpty()) {
+ for (int j = 0; j < alreadyChecked.size(); j++) {
+ dbCreation.append(alreadyChecked.get(0));
+ dbDeletion.append(alreadyChecked.get(0));
+ for (int k = 1; k <= j; k++) {
+ dbCreation.append(".").append(alreadyChecked.get(k));
+ dbDeletion.append(".").append(alreadyChecked.get(k));
+ }
+ dbCreation.append(" != null && ");
+ dbDeletion.append(" != null && ");
+ }
+
+ if (binding.length > alreadyChecked.size() + 1) {
+ for (int j = 0; j < alreadyChecked.size(); j++) {
+ dbCreation.append(alreadyChecked.get(j)).append(".");
+ dbDeletion.append(alreadyChecked.get(j)).append(".");
+ }
+ dbCreation.append(getter).append(" != null");
+ dbDeletion.append(getter).append(" != null");
+ }
+ else {
+ dbCreation.delete(dbCreation.length() - 4, dbCreation.length());
+ dbDeletion.delete(dbDeletion.length() - 4, dbDeletion.length());
+ }
+ }
+ else {
+ dbCreation.append(getter).append(" != null");
+ dbDeletion.append(getter).append(" != null");
+ }
+ dbCreation.append(") {\n");
+ dbDeletion.append(") {\n");
+
+ if (alreadyChecked != null) {
+ for (int j = 0; j < alreadyChecked.size(); j++) {
+ dbCreation.append(alreadyChecked.get(j)).append(".");
+ dbDeletion.append(alreadyChecked.get(j)).append(".");
+ }
+ }
+ if (model != null) {
+ dbCreation.append("get").append(Character.toUpperCase(model.charAt(0))).append(model.substring(1)).append("()").append(".");
+ dbDeletion.append("get").append(Character.toUpperCase(model.charAt(0))).append(model.substring(1)).append("()").append(".");
+ }
+// dbCreation.append(addMethod).append("((").append(listener.getName()).append(") org.nuiton.guix.runtime.Util.getEventListener(").append(listener.getName()).append(".class,this,\"onChangeFrom").append(methodToInvoke).append("\"));\n}\n");
+// dbDeletion.append(removeMethod).append("((").append(listener.getName()).append(") org.nuiton.guix.runtime.Util.getEventListener(").append(listener.getName()).append(".class,this,\"onChangeFrom").append(methodToInvoke).append("\"));\n}\n");
+ dbCreation.append(addMethod).append("(new ").append(listener.getName()).append("() {\n");
+ dbDeletion.append(removeMethod).append("(new ").append(listener.getName()).append("() {\n");
+ for(Method m : listener.getMethods()) {
+ StringBuffer sb = new StringBuffer();
+ for(Annotation a : m.getDeclaredAnnotations()) {
+ dbCreation.append(a.toString()).append("\n");
+ }
+ //add the method that handles the event
+ sb.append("public ")
+ .append(m.getReturnType().getCanonicalName())
+ .append(" ")
+ .append(m.getName())
+ .append("(");
+ for(int n = 0 ; n < m.getParameterTypes().length ; n++) {
+ sb.append(m.getParameterTypes()[n].getCanonicalName())
+ .append(" arg")
+ .append(n)
+ .append(", ");
+ }
+ sb.delete(sb.length() - 2, sb.length())
+ .append(")")
+ .append(" {\n")
+ .append("onChangeFrom").append(methodToInvoke)
+ .append("();\n}\n");
+ dbCreation.append(sb);
+ dbDeletion.append(sb);
+ }
+ dbCreation.append("});\n}\n");
+ dbDeletion.append("});\n}\n");
+ }
+
+ try {
+ nextClazz = Label.class.getClassLoader().loadClass(returnType);
+ }
+ catch (ClassNotFoundException eee) {
+ try {
+ nextClazz = ClassLoader.getSystemClassLoader().loadClass(returnType);
+ }
+ catch (ClassNotFoundException eee2) {
+ for (JavaFile javaFile : generatedFiles.values()) {
+ if (returnType.equals(javaFile.getPackageName() + "." + javaFile.getClassName())) {
+ nextFile = javaFile;
+ break;
+ }
+ }
+ }
+ }
+ if (alreadyChecked == null) {
+ alreadyChecked = new ArrayList<String>();
+ }
+ alreadyChecked.add(getter);
+ if (i + 1 < binding.length) {
+ return generateBindings(dbCreation, dbDeletion, th, nextFile, nextClazz, binding, i + 1, alreadyChecked, methodToInvoke, generatedFiles);
+ }
+ else {
+ result.add(listener);
+ return result;
+ }
+ }
+ else if (log.isErrorEnabled()) {
+ log.error("unable to bind " + binding[i]);
+ }
+ return result;
+ }
}
Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator1.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator1.java (rev 0)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator1.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -0,0 +1,303 @@
+/**
+ * *##% guix-compiler-gwt
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.guix.generator;
+
+import com.google.gwt.user.client.ui.Label;
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.guix.tags.TagHandler;
+
+/**
+ * Generates the interface, abstract class and implementation class
+ * corresponding to the class described by the user,
+ * as well as the configuation file and html file if this class is the main class.
+ *
+ * @author kmorin
+ */
+public class GwtGenerator1 extends GuixGenerator {
+
+ /** log */
+ private Log log = LogFactory.getLog(GwtGenerator1.class);
+ Map<GwtJavaFileGenerator, File> generators = new HashMap<GwtJavaFileGenerator, File>();
+
+ @Override
+ public JavaFile generate() {
+ String gmoClassName = gmo.getClassDescriptor().getName();
+ File outDir = new File(destDir, "client");
+ if (!outDir.exists()) {
+ outDir.mkdir();
+ }
+ File out = new File(outDir, gmoClassName + ".java");
+ File outAbstract = new File(outDir, gmoClassName + "Abstract.java");
+ File outImpl = new File(outDir, gmoClassName + "Impl.java");
+
+ if (lastModification > out.lastModified()) {
+ try {
+ if (log.isInfoEnabled()) {
+ log.info("Generation of " + gmo.getClassDescriptor().getName());
+ }
+ if (!out.exists()) {
+ try {
+ out.createNewFile();
+ outAbstract.createNewFile();
+ outImpl.createNewFile();
+ }
+ catch (IOException ex) {
+ log.error(ex);
+ }
+ }
+ GwtInterfaceGenerator ging = new GwtInterfaceGenerator(gmo, classes);
+ GwtAbstractClassGenerator gacg = new GwtAbstractClassGenerator(gmo, classes);
+ GwtImplementationGenerator gimg = new GwtImplementationGenerator(gmo, classes);
+
+ if (mainClass) {
+ gimg.addMainMethod();
+ GwtConfigGenerator gcg = new GwtConfigGenerator(gmo);
+ GwtHtmlGenerator ghg = new GwtHtmlGenerator(gmo, launcherName);
+ File outConfigMain = new File(destDir, launcherName.substring(launcherName.lastIndexOf('.') + 1) + ".gwt.xml");
+ File publicDir = new File(destDir, "public");
+ if (!publicDir.exists()) {
+ publicDir.mkdir();
+ }
+ File outHtmlMain = new File(publicDir, launcherName.substring(launcherName.lastIndexOf('.') + 1) + ".html");
+ gcg.generate(outConfigMain);
+ ghg.generate(outHtmlMain);
+ }
+
+ ging.generate(out);
+ generators.put(ging, out);
+ JavaFile jf = gacg.generates();
+ generators.put(gacg, outAbstract);
+ gimg.generate(outImpl);
+ generators.put(gimg, outImpl);
+
+ serializer.startTag("", "bean");
+ serializer.attribute("", "id", gmoClassName.replace(out.getName().charAt(0),
+ Character.toLowerCase(out.getName().charAt(0)))).attribute("", "class", gmoClassName + "Impl").attribute("", "singleton", "false").endTag("", "bean");
+ setBindingsToGenerate(gacg.getBindings2Generate());
+
+ return jf;
+ }
+ catch (IllegalArgumentException ex) {
+ log.error(ex);
+ }
+ catch (IllegalStateException ex) {
+ log.error(ex);
+ }
+ catch (IOException ex) {
+ log.error(ex);
+ }
+ }
+ else if (log.isWarnEnabled()) {
+ log.warn(gmo.getClassDescriptor().getName() + " has already been generated and is up to date.");
+ }
+ return null;
+ }
+
+ @Override
+ public void saveFiles() {
+ for (JavaFileGenerator gen : generators.keySet()) {
+ gen.saveFile(generators.get(gen));
+ }
+ }
+
+ @Override
+ public List<Class> generateBindings(StringBuffer dbCreation, StringBuffer dbDeletion, TagHandler prevTh,
+ JavaFile jf, Class clazz,String[] binding, int i, List<String> alreadyChecked, String methodToInvoke, Map<GuixGenerator, JavaFile> generatedFiles) {
+ boolean bindingExists = false;
+ String returnType = null;
+ String getter = null;
+ JavaFile nextFile = null;
+ Class nextClazz = null;
+ TagHandler th = null;
+ String model = null;
+ Class listener = null;
+ String addMethod = null;
+ String removeMethod = null;
+ List<Class> result = new ArrayList<Class>();
+
+ if (binding[i].endsWith(")")) {
+ if (jf != null) {
+ bindingExists = jf.getMethod(binding[i].substring(0, binding[i].lastIndexOf("(")), null) != null;
+ if (bindingExists) {
+ returnType = jf.getMethod(binding[i].substring(0, binding[i].lastIndexOf("(")), null).getReturnType();
+ String s = binding[i];
+ if (s.startsWith("get")) {
+ s = Character.toLowerCase(s.charAt(3)) + s.substring(4, s.lastIndexOf("("));
+ }
+ else if (s.startsWith("is")) {
+ s = Character.toLowerCase(s.charAt(2)) + s.substring(3, s.lastIndexOf("("));
+ }
+ JavaField f = jf.getField(s);
+ if (f != null) {
+ th = f.getTagHandler();
+ }
+ }
+ }
+ else {
+ try {
+ clazz.getMethod(binding[i].substring(0, binding[i].lastIndexOf("(")), null);
+ returnType = clazz.getMethod(binding[i].substring(0, binding[i].lastIndexOf("(")), null).getReturnType().getName();
+ bindingExists = true;
+ }
+ catch (NoSuchMethodException eee) {
+ bindingExists = false;
+ }
+ }
+ getter = binding[i];
+ }
+ else {
+ if (jf != null) {
+ bindingExists = jf.getMethod("get" + Character.toUpperCase(binding[i].charAt(0)) + binding[i].substring(1), null) != null || jf.getMethod("is" + Character.toUpperCase(binding[i].charAt(0)) + binding[i].substring(1), null) != null;
+ if (bindingExists) {
+ returnType = jf.getMethod("get" + Character.toUpperCase(binding[i].charAt(0)) + binding[i].substring(1), null) != null ? jf.getMethod("get" + Character.toUpperCase(binding[i].charAt(0)) + binding[i].substring(1), null).getReturnType()
+ : jf.getMethod("is" + Character.toUpperCase(binding[i].charAt(0)) + binding[i].substring(1), null).getReturnType();
+ }
+
+ getter = jf.getMethod("get" + Character.toUpperCase(binding[i].charAt(0)) + binding[i].substring(1), null) != null ? "get" + Character.toUpperCase(binding[i].charAt(0)) + binding[i].substring(1) + "()"
+ : "is" + Character.toUpperCase(binding[i].charAt(0)) + binding[i].substring(1) + "()";
+
+ JavaField f = jf.getField(binding[i]);
+ if (f != null) {
+ th = f.getTagHandler();
+ }
+ }
+ else {
+ try {
+ clazz.getMethod("get" + Character.toUpperCase(binding[i].charAt(0)) + binding[i].substring(1), null);
+ returnType = clazz.getMethod("get" + Character.toUpperCase(binding[i].charAt(0)) + binding[i].substring(1), null).getReturnType().getName();
+ getter = "get" + Character.toUpperCase(binding[i].charAt(0)) + binding[i].substring(1) + "()";
+ bindingExists = true;
+ }
+ catch (NoSuchMethodException eee) {
+ try {
+ clazz.getMethod("is" + Character.toUpperCase(binding[i].charAt(0)) + binding[i].substring(1), null);
+ returnType = clazz.getMethod("is" + Character.toUpperCase(binding[i].charAt(0)) + binding[i].substring(1), null).getReturnType().getName();
+ getter = "is" + Character.toUpperCase(binding[i].charAt(0)) + binding[i].substring(1) + "()";
+ bindingExists = true;
+ }
+ catch (NoSuchMethodException eee2) {
+ bindingExists = false;
+ }
+ }
+ }
+ }
+ if (bindingExists) {
+ if (i == binding.length - 1 && prevTh != null) {
+ String getterWoBraces = getter.substring(0, getter.lastIndexOf("("));
+ if (prevTh.hasEventInfosAboutMethod(getterWoBraces)) {
+ model = prevTh.getEventInfosModelName(getterWoBraces);
+ listener = prevTh.getEventInfosListenerClass(getterWoBraces);
+ addMethod = prevTh.getEventInfosAddListenerMethodName(getterWoBraces);
+ removeMethod = prevTh.getEventInfosRemoveListenerMethodName(getterWoBraces);
+ }
+ else {
+ log.error("Impossible binding");
+ return null;
+ }
+
+ dbCreation.append("if(");
+ dbDeletion.append("if(");
+ if (alreadyChecked != null && !alreadyChecked.isEmpty()) {
+ for (int j = 0; j < alreadyChecked.size(); j++) {
+ dbCreation.append(alreadyChecked.get(0));
+ dbDeletion.append(alreadyChecked.get(0));
+ for (int k = 1; k <= j; k++) {
+ dbCreation.append(".").append(alreadyChecked.get(k));
+ dbDeletion.append(".").append(alreadyChecked.get(k));
+ }
+ dbCreation.append(" != null && ");
+ dbDeletion.append(" != null && ");
+ }
+
+ if (binding.length > alreadyChecked.size() + 1) {
+ for (int j = 0; j < alreadyChecked.size(); j++) {
+ dbCreation.append(alreadyChecked.get(j)).append(".");
+ dbDeletion.append(alreadyChecked.get(j)).append(".");
+ }
+ dbCreation.append(getter).append(" != null");
+ dbDeletion.append(getter).append(" != null");
+ }
+ else {
+ dbCreation.delete(dbCreation.length() - 4, dbCreation.length());
+ dbDeletion.delete(dbDeletion.length() - 4, dbDeletion.length());
+ }
+ }
+ else {
+ dbCreation.append(getter).append(" != null");
+ dbDeletion.append(getter).append(" != null");
+ }
+ dbCreation.append(") {\n");
+ dbDeletion.append(") {\n");
+
+ if (alreadyChecked != null) {
+ for (int j = 0; j < alreadyChecked.size(); j++) {
+ dbCreation.append(alreadyChecked.get(j)).append(".");
+ dbDeletion.append(alreadyChecked.get(j)).append(".");
+ }
+ }
+ if (model != null) {
+ dbCreation.append("get").append(Character.toUpperCase(model.charAt(0))).append(model.substring(1)).append("()").append(".");
+ dbDeletion.append("get").append(Character.toUpperCase(model.charAt(0))).append(model.substring(1)).append("()").append(".");
+ }
+ dbCreation.append(addMethod).append("((").append(listener.getName()).append(") org.nuiton.guix.runtime.Util.getEventListener(").append(listener.getName()).append(".class,this,\"onChangeFrom").append(methodToInvoke).append("\"));\n}\n");
+ dbDeletion.append(removeMethod).append("((").append(listener.getName()).append(") org.nuiton.guix.runtime.Util.getEventListener(").append(listener.getName()).append(".class,this,\"onChangeFrom").append(methodToInvoke).append("\"));\n}\n");
+ }
+
+ try {
+ nextClazz = Label.class.getClassLoader().loadClass(returnType);
+ }
+ catch (ClassNotFoundException eee) {
+ try {
+ nextClazz = ClassLoader.getSystemClassLoader().loadClass(returnType);
+ }
+ catch (ClassNotFoundException eee2) {
+ for (JavaFile javaFile : generatedFiles.values()) {
+ if (returnType.equals(javaFile.getPackageName() + "." + javaFile.getClassName())) {
+ nextFile = javaFile;
+ break;
+ }
+ }
+ }
+ }
+ if (alreadyChecked == null) {
+ alreadyChecked = new ArrayList<String>();
+ }
+ alreadyChecked.add(getter);
+ if (i + 1 < binding.length) {
+ return generateBindings(dbCreation, dbDeletion, th, nextFile, nextClazz,null, i + 1, alreadyChecked, methodToInvoke, generatedFiles);
+ }
+ else {
+ result.add(listener);
+ return result;
+ }
+ }
+ else if (log.isErrorEnabled()) {
+ log.error("unable to bind " + binding[i]);
+ }
+ return result;
+ }
+}
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtInterfaceGenerator.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtInterfaceGenerator.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtInterfaceGenerator.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -48,8 +48,7 @@
JavaFile.INTERFACE,
gmo.getClassDescriptor().getPackageName() + ".client",
gmo.getClassDescriptor().getName(),
- null,
- gmo.getJavadoc());
+ null, gmo.getJavadoc());
}
@Override
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ApplicationHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ApplicationHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ApplicationHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -9,7 +9,7 @@
*
* @author kevin
*/
-public class ApplicationHandler extends org.nuiton.guix.tags.ApplicationHandler {
+public class ApplicationHandler extends UIObjectHandler {
public ApplicationHandler() {
super();
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ButtonHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ButtonHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ButtonHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -9,8 +9,12 @@
*
* @author kevin
*/
-public class ButtonHandler extends org.nuiton.guix.tags.ButtonHandler {
+public class ButtonHandler extends UIObjectHandler {
+ public ButtonHandler() {
+ super();
+ }
+
@Override
public Class getClassToGenerate() {
return com.google.gwt.user.client.ui.Button.class;
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/CellHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/CellHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/CellHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -18,6 +18,7 @@
*/
package org.nuiton.guix.tags.gwt;
+import org.nuiton.guix.model.AttributeDescriptor;
import org.nuiton.guix.model.GuixModelObject;
/**
@@ -25,8 +26,18 @@
*
* @author kevin
*/
-public class CellHandler extends org.nuiton.guix.tags.CellHandler {
-
+public class CellHandler extends TableHandler {
+ /** id of the object contained by the cell */
+ private String id = null;
+ /** number of columns of the cell */
+ private int columns = 1;
+ /** number of rows of the cell */
+ private int rows = 1;
+ /** index of the row */
+ private int row = -1;
+ /** index of the column */
+ private int column = -1;
+
/**
* Constructor
*/
@@ -40,7 +51,43 @@
* @param cell the GuixModelObject which represents the cell
*/
public CellHandler(GuixModelObject cell) {
- super(cell);
+ assert cell.getChildren().size() == 1;
+ id = cell.getChildren().get(0).getId();
+ for (AttributeDescriptor attr : cell.getAttributeDescriptors()) {
+ if (attr.getName().equals("columns")) {
+ columns = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("column")) {
+ column = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("rows")) {
+ rows = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("weightx")) {
+ weightx = Double.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("weighty")) {
+ weighty = Double.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("ipadx")) {
+ ipadx = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("ipady")) {
+ ipady = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("halign")) {
+ horizontalAlignment = getHalign(attr.getValue());
+ }
+ else if (attr.getName().equals("valign")) {
+ verticalAlignment = getValign(attr.getValue());
+ }
+ else if (attr.getName().equals("fill")) {
+ fill = attr.getValue();
+ }
+ else if (attr.getName().equals("insets")) {
+ insets = attr.getValue();
+ }
+ }
}
/**
@@ -50,13 +97,82 @@
* @param row the row which contains the cell
*/
public CellHandler(GuixModelObject cell, RowHandler row) {
- super(cell,row);
+ this(cell);
+ //if the attributes that the row contains too have not been defined by the user within the cell,
+ //but have been defined in the row (or the table), set them
+ if (horizontalAlignment == null) {
+ horizontalAlignment = row.getHorizontalAlignment() == null ? TableHandler.DEFAULT_HORIZONTAL_ALIGNMENT : row.getHorizontalAlignment();
+ }
+ if (verticalAlignment == null) {
+ verticalAlignment = row.getVerticalAlignment() == null ? TableHandler.DEFAULT_VERTICAL_ALIGNMENT : row.getVerticalAlignment();
+ }
+ if (fill == null) {
+ fill = row.getFill() == null ? TableHandler.DEFAULT_FILL : row.getFill();
+ }
+ if (insets == null) {
+ insets = row.getInsets() == null ? TableHandler.DEFAULT_INSETS : row.getInsets();
+ }
+ if (ipadx == null) {
+ ipadx = row.getIpadx() == null ? TableHandler.DEFAULT_IPADX : row.getIpadx();
+ }
+ if (ipady == null) {
+ ipady = row.getIpady() == null ? TableHandler.DEFAULT_IPADY : row.getIpady();
+ }
+ if (weightx == null) {
+ weightx = row.getWeightx() == null ? TableHandler.DEFAULT_WEIGHTX : row.getWeightx();
+ }
+ if (weighty == null) {
+ weighty = row.getWeighty() == null ? TableHandler.DEFAULT_WEIGHTY : row.getWeighty();
+ }
+ if(this.row == -1) {
+ this.row = row.getRow() < 0 ? -1 : row.getRow();
+ }
}
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public int getColumn() {
+ return column;
+ }
+
+ public void setColumn(int column) {
+ this.column = column;
+ }
+
+ public int getColumns() {
+ return columns;
+ }
+
+ public void setColumns(int columns) {
+ this.columns = columns;
+ }
+
+ public int getRow() {
+ return row;
+ }
+
+ public void setRow(int row) {
+ this.row = row;
+ }
+
+ public int getRows() {
+ return rows;
+ }
+
+ public void setRows(int rows) {
+ this.rows = rows;
+ }
+
@Override
public Class getClassToGenerate() {
return null;
}
-
}
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/LabelHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/LabelHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/LabelHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -4,12 +4,13 @@
*/
package org.nuiton.guix.tags.gwt;
+import com.google.gwt.user.client.EventListener;
/**
*
* @author kevin
*/
-public class LabelHandler extends org.nuiton.guix.tags.LabelHandler {
+public class LabelHandler extends UIObjectHandler {
/**
* Constructor
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/MenuBarHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/MenuBarHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/MenuBarHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -4,12 +4,13 @@
*/
package org.nuiton.guix.tags.gwt;
+import com.google.gwt.user.client.EventListener;
/**
*
* @author kevin
*/
-public class MenuBarHandler extends org.nuiton.guix.tags.MenuBarHandler {
+public class MenuBarHandler extends UIObjectHandler {
/**
* Constructor
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/MenuHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/MenuHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/MenuHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -9,7 +9,7 @@
*
* @author kevin
*/
-public class MenuHandler extends org.nuiton.guix.tags.MenuHandler {
+public class MenuHandler extends UIObjectHandler {
/**
* Constructor
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/MenuItemHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/MenuItemHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/MenuItemHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -9,13 +9,14 @@
*
* @author kevin
*/
-public class MenuItemHandler extends org.nuiton.guix.tags.MenuItemHandler {
+public class MenuItemHandler extends UIObjectHandler {
/**
* Constructor
*/
public MenuItemHandler() {
super();
+ attrMap.put("action", "command");
}
@Override
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/PanelHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/PanelHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/PanelHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -9,7 +9,7 @@
*
* @author kevin
*/
-public class PanelHandler extends org.nuiton.guix.tags.PanelHandler {
+public class PanelHandler extends UIObjectHandler {
/**
* Constructor
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/RowHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/RowHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/RowHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -18,6 +18,7 @@
*/
package org.nuiton.guix.tags.gwt;
+import org.nuiton.guix.model.AttributeDescriptor;
import org.nuiton.guix.model.GuixModelObject;
/**
@@ -25,7 +26,10 @@
*
* @author kevin
*/
-public class RowHandler extends org.nuiton.guix.tags.RowHandler {
+public class RowHandler extends TableHandler {
+
+ /** index of the row */
+ private int row = -1;
/**
* Constructor
@@ -40,7 +44,35 @@
* @param row the GuixModelObject which represents the row
*/
public RowHandler(GuixModelObject row) {
- super(row);
+ for (AttributeDescriptor attr : row.getAttributeDescriptors()) {
+ if (attr.getName().equals("row")) {
+ this.row = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("weightx")) {
+ weightx = Double.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("weighty")) {
+ weighty = Double.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("ipadx")) {
+ ipadx = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("ipady")) {
+ ipady = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("halign")) {
+ horizontalAlignment = getHalign(attr.getValue());
+ }
+ else if (attr.getName().equals("valign")) {
+ verticalAlignment = getValign(attr.getValue());
+ }
+ else if (attr.getName().equals("fill")) {
+ fill = attr.getValue();
+ }
+ else if (attr.getName().equals("insets")) {
+ insets = attr.getValue();
+ }
+ }
}
/**
@@ -50,11 +82,45 @@
* @param table the table which contains the row
*/
public RowHandler(GuixModelObject row, TableHandler table) {
- super(row, table);
+ this(row);
+ //if the attributes that the table contains too have not been defined by the user within the row,
+ //but have been defined in the table, set them
+ if (horizontalAlignment == null) {
+ horizontalAlignment = table.getHorizontalAlignment() == null ? TableHandler.DEFAULT_HORIZONTAL_ALIGNMENT : table.getHorizontalAlignment();
+ }
+ if (verticalAlignment == null) {
+ verticalAlignment = table.getVerticalAlignment() == null ? TableHandler.DEFAULT_VERTICAL_ALIGNMENT : table.getVerticalAlignment();
+ }
+ if (fill == null) {
+ fill = table.getFill() == null ? TableHandler.DEFAULT_FILL : table.getFill();
+ }
+ if (insets == null) {
+ insets = table.getInsets() == null ? TableHandler.DEFAULT_INSETS : table.getInsets();
+ }
+ if (ipadx == null) {
+ ipadx = table.getIpadx() == null ? TableHandler.DEFAULT_IPADX : table.getIpadx();
+ }
+ if (ipady == null) {
+ ipady = table.getIpady() == null ? TableHandler.DEFAULT_IPADY : table.getIpady();
+ }
+ if (weightx == null) {
+ weightx = table.getWeightx() == null ? TableHandler.DEFAULT_WEIGHTX : table.getWeightx();
+ }
+ if (weighty == null) {
+ weighty = table.getWeighty() == null ? TableHandler.DEFAULT_WEIGHTY : table.getWeighty();
+ }
}
@Override
public Class getClassToGenerate() {
return null;
}
+
+ public int getRow() {
+ return row;
+ }
+
+ public void setRow(int row) {
+ this.row = row;
+ }
}
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TabPanelHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TabPanelHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TabPanelHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -9,7 +9,7 @@
*
* @author kevin
*/
-public class TabPanelHandler extends org.nuiton.guix.tags.TabPanelHandler {
+public class TabPanelHandler extends UIObjectHandler {
/**
* Constructor
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TableHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TableHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TableHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -22,6 +22,7 @@
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.guix.model.AttributeDescriptor;
import org.nuiton.guix.model.GuixModelObject;
/**
@@ -29,10 +30,35 @@
*
* @author kevin
*/
-public class TableHandler extends org.nuiton.guix.tags.TableHandler {
+public class TableHandler extends UIObjectHandler {
private static Log log = LogFactory.getLog(TableHandler.class);
+ protected enum VerticalAlignment {
+
+ ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM
+ }
+ protected enum HorizontalAlignment {
+
+ ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_DEFAULT
+ }
+ public static final String DEFAULT_INSETS = "3, 3, 3, 3";
+ public static final HorizontalAlignment DEFAULT_HORIZONTAL_ALIGNMENT = HorizontalAlignment.ALIGN_DEFAULT;
+ public static final VerticalAlignment DEFAULT_VERTICAL_ALIGNMENT = VerticalAlignment.ALIGN_TOP;
+ public static final String DEFAULT_FILL = "java.awt.GridBagConstraints.BOTH";
+ public static final Integer DEFAULT_IPADX = 1;
+ public static final Integer DEFAULT_IPADY = 1;
+ public static final Double DEFAULT_WEIGHTX = 0.0;
+ public static final Double DEFAULT_WEIGHTY = 0.0;
+ protected Double weightx = null;
+ protected Double weighty = null;
+ protected Integer ipadx = null;
+ protected Integer ipady = null;
+ protected HorizontalAlignment horizontalAlignment = null;
+ protected VerticalAlignment verticalAlignment = null;
+ protected String fill = null;
+ protected String insets = null;
+
/**
* Constructor
*/
@@ -46,9 +72,137 @@
* @param table the GuixModelObject which represents the table
*/
public TableHandler(GuixModelObject table) {
- super(table);
+ for (AttributeDescriptor attr : table.getAttributeDescriptors()) {
+ if (attr.getName().equals("weightx")) {
+ weightx = Double.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("weighty")) {
+ weighty = Double.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("ipadx")) {
+ ipadx = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("ipady")) {
+ ipady = Integer.valueOf(attr.getValue());
+ }
+ else if (attr.getName().equals("halign")) {
+ horizontalAlignment = getHalign(attr.getValue());
+ if (horizontalAlignment == null) {
+ if (log.isErrorEnabled()) {
+ log.error(table.getId() + "'s halign attribute has a wrong value : " + attr.getValue());
+ }
+ horizontalAlignment = HorizontalAlignment.ALIGN_DEFAULT;
+ }
+ }
+ else if (attr.getName().equals("valign")) {
+ verticalAlignment = getValign(attr.getValue());
+ if (verticalAlignment == null) {
+ if (log.isErrorEnabled()) {
+ log.error(table.getId() + "'s halign attribute has a wrong value : " + attr.getValue());
+ }
+ verticalAlignment = VerticalAlignment.ALIGN_TOP;
+ }
+ }
+ else if (attr.getName().equals("fill")) {
+ fill = attr.getValue();
+ }
+ else if (attr.getName().equals("insets")) {
+ insets = attr.getValue();
+ }
+ }
}
-
+
+
+ public HorizontalAlignment getHorizontalAlignment() {
+ return horizontalAlignment;
+ }
+
+ public void setHorizontalAlignment(HorizontalAlignment horizontalAlignment) {
+ this.horizontalAlignment = horizontalAlignment;
+ }
+
+ public VerticalAlignment getVerticalAlignment() {
+ return verticalAlignment;
+ }
+
+ public void setVerticalAlignment(VerticalAlignment verticalAlignment) {
+ this.verticalAlignment = verticalAlignment;
+ }
+
+ public String getFill() {
+ return fill;
+ }
+
+ public void setFill(String fill) {
+ this.fill = fill;
+ }
+
+ public String getInsets() {
+ return insets;
+ }
+
+ public void setInsets(String insets) {
+ this.insets = insets;
+ }
+
+ public Integer getIpadx() {
+ return ipadx;
+ }
+
+ public void setIpadx(Integer ipadx) {
+ this.ipadx = ipadx;
+ }
+
+ public Integer getIpady() {
+ return ipady;
+ }
+
+ public void setIpady(Integer ipady) {
+ this.ipady = ipady;
+ }
+
+ public Double getWeightx() {
+ return weightx;
+ }
+
+ public void setWeightx(Double weightx) {
+ this.weightx = weightx;
+ }
+
+ public Double getWeighty() {
+ return weighty;
+ }
+
+ public void setWeighty(Double weighty) {
+ this.weighty = weighty;
+ }
+
+ public HorizontalAlignment getHalign(String halign) {
+ if (halign.equalsIgnoreCase("left")) {
+ return HorizontalAlignment.ALIGN_LEFT;
+ }
+ if (halign.equalsIgnoreCase("right")) {
+ return HorizontalAlignment.ALIGN_RIGHT;
+ }
+ if (halign.equalsIgnoreCase("center")) {
+ return HorizontalAlignment.ALIGN_CENTER;
+ }
+ return null;
+ }
+
+ public VerticalAlignment getValign(String valign) {
+ if (valign.equalsIgnoreCase("top")) {
+ return VerticalAlignment.ALIGN_TOP;
+ }
+ if (valign.equalsIgnoreCase("bottom")) {
+ return VerticalAlignment.ALIGN_BOTTOM;
+ }
+ if (valign.equalsIgnoreCase("middle")) {
+ return VerticalAlignment.ALIGN_MIDDLE;
+ }
+ return null;
+ }
+
/**
* Creates a cell with the right column and generates the code to add it to the table
*
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TextFieldHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TextFieldHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TextFieldHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -4,12 +4,13 @@
*/
package org.nuiton.guix.tags.gwt;
+import com.google.gwt.user.client.ui.KeyboardListener;
/**
*
* @author kevin
*/
-public class TextFieldHandler extends org.nuiton.guix.tags.TextFieldHandler {
+public class TextFieldHandler extends UIObjectHandler {
/**
* Constructor
@@ -23,4 +24,9 @@
return com.google.gwt.user.client.ui.TextBox.class;
}
+ @Override
+ public void configureProxyEventInfo() {
+ super.configureProxyEventInfo();
+ addProxyEventInfo("getText", KeyboardListener.class);
+ }
}
Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ToggleButtonHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ToggleButtonHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ToggleButtonHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -4,16 +4,27 @@
*/
package org.nuiton.guix.tags.gwt;
+import com.google.gwt.user.client.ui.ClickListener;
/**
*
* @author kevin
*/
-public class ToggleButtonHandler extends org.nuiton.guix.tags.ToggleButtonHandler {
+public class ToggleButtonHandler extends ButtonHandler {
+ public ToggleButtonHandler() {
+ super();
+ attrMap.put("selected", "down");
+ }
+
@Override
public Class getClassToGenerate() {
return com.google.gwt.user.client.ui.ToggleButton.class;
}
+ @Override
+ public void configureProxyEventInfo() {
+ super.configureProxyEventInfo();
+ addProxyEventInfo("isDown", ClickListener.class);
+ }
}
Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/UIObjectHandler.java
===================================================================
--- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/UIObjectHandler.java (rev 0)
+++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/UIObjectHandler.java 2009-07-22 13:07:30 UTC (rev 1502)
@@ -0,0 +1,22 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.nuiton.guix.tags.gwt;
+import com.google.gwt.user.client.EventListener;
+import com.google.gwt.user.client.ui.FocusListener;
+import org.nuiton.guix.tags.DefaultTagHandler;
+
+/**
+ *
+ * @author kevin
+ */
+public abstract class UIObjectHandler extends DefaultTagHandler {
+
+ public UIObjectHandler() {
+ super();
+ configureProxyEventInfo();
+ }
+
+}
1
0
r1501 - trunk/guix-compiler/src/main/java/org/nuiton/guix/tags
by kmorin@users.labs.libre-entreprise.org 22 Jul '09
by kmorin@users.labs.libre-entreprise.org 22 Jul '09
22 Jul '09
Author: kmorin
Date: 2009-07-22 15:06:43 +0200 (Wed, 22 Jul 2009)
New Revision: 1501
Added:
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ApplicationHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/PanelHandler.java
Log:
Removed the general taghandlers (I kept the one useful for the tests)
Generation of the binding after the generation of the non-dynamic code : I made a copy of GuixLauncher working with DataBinding and DataSource classes, but it seems to be working without
Added: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ApplicationHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ApplicationHandler.java (rev 0)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ApplicationHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
@@ -0,0 +1,20 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.nuiton.guix.tags;
+
+/**
+ *
+ * @author kevin
+ */
+public abstract class ApplicationHandler extends DefaultTagHandler {
+
+ /**
+ * Constructor
+ */
+ public ApplicationHandler() {
+
+ }
+}
Added: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/PanelHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/PanelHandler.java (rev 0)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/PanelHandler.java 2009-07-22 13:06:43 UTC (rev 1501)
@@ -0,0 +1,20 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.nuiton.guix.tags;
+
+/**
+ *
+ * @author kevin
+ */
+public abstract class PanelHandler extends DefaultTagHandler {
+
+ /**
+ * Constructor
+ */
+ public PanelHandler() {
+
+ }
+}
1
0
r1500 - in trunk/guix-compiler/src/main/java/org/nuiton/guix: . databinding generator model parser tags
by kmorin@users.labs.libre-entreprise.org 22 Jul '09
by kmorin@users.labs.libre-entreprise.org 22 Jul '09
22 Jul '09
Author: kmorin
Date: 2009-07-22 15:06:26 +0200 (Wed, 22 Jul 2009)
New Revision: 1500
Added:
trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher1.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataBinding.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataSource.java
Removed:
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ApplicationHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ButtonHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/CellHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/LabelHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuBarHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuItemHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/PanelHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/RowHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TabPanelHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TableHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TextFieldHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ToggleButtonHandler.java
Modified:
trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/BindingUtils.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/Generator.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaField.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFile.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileGenerator.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaMethod.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/SimpleNode.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/DefaultTagHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java
trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagHandler.java
Log:
Removed the general taghandlers (I kept the one useful for the tests)
Generation of the binding after the generation of the non-dynamic code : I made a copy of GuixLauncher working with DataBinding and DataSource classes, but it seems to be working without
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -22,19 +22,8 @@
//~--- non-JDK imports --------------------------------------------------------
import org.nuiton.guix.tags.ApplicationHandler;
-import org.nuiton.guix.tags.ButtonHandler;
-import org.nuiton.guix.tags.CellHandler;
-import org.nuiton.guix.tags.LabelHandler;
-import org.nuiton.guix.tags.MenuBarHandler;
-import org.nuiton.guix.tags.MenuHandler;
-import org.nuiton.guix.tags.MenuItemHandler;
-import org.nuiton.guix.tags.RowHandler;
-import org.nuiton.guix.tags.TableHandler;
import org.nuiton.guix.tags.PanelHandler;
-import org.nuiton.guix.tags.TabPanelHandler;
import org.nuiton.guix.tags.TagManager;
-import org.nuiton.guix.tags.TextFieldHandler;
-import org.nuiton.guix.tags.ToggleButtonHandler;
/**
* Initialize the application
@@ -44,18 +33,7 @@
public class GuixInitializer {
public static void initialize() {
TagManager.registerGuixClassHandler("Application", ApplicationHandler.class);
- TagManager.registerGuixClassHandler("Table", TableHandler.class);
- TagManager.registerGuixClassHandler("Row", RowHandler.class);
- TagManager.registerGuixClassHandler("Cell", CellHandler.class);
TagManager.registerGuixClassHandler("Panel", PanelHandler.class);
- TagManager.registerGuixClassHandler("Button", ButtonHandler.class);
- TagManager.registerGuixClassHandler("TextField", TextFieldHandler.class);
- TagManager.registerGuixClassHandler("Label", LabelHandler.class);
- TagManager.registerGuixClassHandler("ToggleButton", ToggleButtonHandler.class);
- TagManager.registerGuixClassHandler("TabPanel", TabPanelHandler.class);
- TagManager.registerGuixClassHandler("MenuBar", MenuBarHandler.class);
- TagManager.registerGuixClassHandler("Menu", MenuHandler.class);
- TagManager.registerGuixClassHandler("MenuItem", MenuItemHandler.class);
}
}
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -21,6 +21,9 @@
import org.nuiton.guix.compiler.GuixCompiler;
import java.io.File;
import java.io.PrintWriter;
+import java.io.StringReader;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -28,10 +31,16 @@
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.guix.generator.Generator;
import org.nuiton.guix.generator.GuixGenerator;
+import org.nuiton.guix.generator.JavaArgument;
+import org.nuiton.guix.generator.JavaField;
+import org.nuiton.guix.generator.JavaFile;
+import org.nuiton.guix.generator.JavaMethod;
import org.nuiton.guix.model.ClassDescriptor;
import org.nuiton.guix.model.GuixModelObject;
+import org.nuiton.guix.parser.JavaParser;
+import org.nuiton.guix.parser.JavaParserTreeConstants;
+import org.nuiton.guix.parser.SimpleNode;
import org.nuiton.guix.tags.TagManager;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
@@ -61,6 +70,7 @@
protected List<ClassDescriptor> classDescriptors =
new ArrayList<ClassDescriptor>();
private List<File> compiledFiles = new ArrayList<File>();
+ private Map<GuixGenerator,JavaFile> generatedFiles = new HashMap<GuixGenerator,JavaFile>();
protected int compilerCount;
private File targetDirectory;
private String rootPackage;
@@ -204,7 +214,7 @@
for (GuixModelObject mo : rootModelObjects.keySet()) {
try {
- Generator gen = (GuixGenerator) generatorClass.newInstance();
+ GuixGenerator gen = (GuixGenerator) generatorClass.newInstance();
gen.setDestDir(destDir);
gen.setGmo(mo);
gen.setLastModification(rootModelObjects.get(mo));
@@ -212,7 +222,7 @@
gen.setSerializer(serializer);
gen.setClasses(Arrays.asList(classNames));
gen.setLauncherName(launcherName);
- gen.generate();
+ generatedFiles.put(gen,gen.generate());
}
catch (InstantiationException eee) {
if(log.isErrorEnabled())
@@ -222,11 +232,124 @@
if(log.isErrorEnabled())
log.error(eee);
}
- catch (NullPointerException eee) {
- if(log.isErrorEnabled())
- log.error(eee);
- eee.printStackTrace();
+ }
+ for(GuixGenerator gen : generatedFiles.keySet()) {
+ int dataSourceNumber = 0;
+ StringBuffer dbCreation = new StringBuffer();
+ StringBuffer dbDeletion = new StringBuffer();
+ StringBuffer dbProcess = new StringBuffer();
+ JavaFile jf = generatedFiles.get(gen);
+ for(String field : gen.getBindingsToGenerate().keySet()) {
+ for(String attr : gen.getBindingsToGenerate().get(field).keySet()) {
+ dbCreation.append(dbCreation.length() != 0 ? "else if(\"" : "if(\"").append(field)
+ .append(".").append(attr)
+ .append("\".equals(_binding)) {\n");
+ dbDeletion.append(dbDeletion.length() != 0 ? "else if(\"" : "if(\"").append(field)
+ .append(".").append(attr)
+ .append("\".equals(_binding)) {\n");
+ dbProcess.append(dbProcess.length() != 0 ? "else if(\"" : "if(\"").append(field)
+ .append(".").append(attr)
+ .append("\".equals(_binding)) {\n")
+ .append(field).append(".set")
+ .append(Character.toUpperCase(attr.charAt(0)))
+ .append(attr.substring(1))
+ .append("(");
+ List<String[]> bindings = new ArrayList<String[]>();
+ JavaParser p = new JavaParser(new StringReader(gen.getBindingsToGenerate().get(field).get(attr)));
+ //start parsing
+ while (!p.Line()) {
+ SimpleNode node = p.popNode();
+ if (node != null) {
+ for(String s : browseNode(node)) {
+ List<String> l = new ArrayList<String>();
+ int parOuvertes = 0;
+ StringBuffer read = new StringBuffer();
+ for(char c : s.toCharArray()) {
+ if(c == '(') {
+ parOuvertes++;
+ read.append(c);
+ }
+ else if(c == ')') {
+ parOuvertes--;
+ read.append(c);
+ }
+ else if(c == '.') {
+ if(parOuvertes == 0) {
+ l.add(read.toString());
+ read = new StringBuffer();
+ }
+ else {
+ read.append(c);
+ }
+ }
+ else {
+ read.append(c);
+ }
+ }
+ l.add(read.toString());
+ bindings.add(l.toArray(new String[l.size()]));
+ }
+ }
+ }
+ List<Class> listeners = new ArrayList<Class>();
+ for(String[] binding : bindings) {
+ StringBuffer methodToInvoke = new StringBuffer();
+ StringBuffer oldBinding = new StringBuffer();
+ for(String s : binding) {
+ log.info("old : " + s);
+ methodToInvoke.append(s.replaceAll("\\W", ""));
+ oldBinding.append(s).append(".");
+ }
+ oldBinding.setLength(oldBinding.length() - 1);
+ listeners.addAll(gen.generateBindings(dbCreation, dbDeletion, null, jf, null, binding, 0, null, methodToInvoke.toString(), generatedFiles));
+ //JavaArgument[] args = new JavaArgument[]{new JavaArgument(parameterType.getName(), "event")};
+ StringBuffer newBinding = new StringBuffer();
+ for(String s : binding) {
+ log.info("new : " + s);
+ newBinding.append(s).append(".");
+ }
+ newBinding.setLength(newBinding.length() - 1);
+ log.info(gen.getBindingsToGenerate().get(field).get(attr) + " : " + oldBinding + " - " + newBinding.toString());
+ gen.getBindingsToGenerate().get(field)
+ .put(attr, gen.getBindingsToGenerate().get(field).get(attr).replace(oldBinding.toString(), newBinding.toString()));
+
+ if (jf.getMethod("onChangeFrom" + methodToInvoke, /*args*/null) == null) {
+ jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "onChangeFrom" + methodToInvoke.toString(), /*args*/null, null, /*"_DataSource" + dataSourceNumber + ".propertyChange(null);"*/"processDataBinding(\"" + field + "." + attr + "\");", null));
+ }
+ else {
+ jf.getMethod("onChangeFrom" + methodToInvoke.toString(), /*args*/null).appendBodyCode(/*"_DataSource" + dataSourceNumber + ".propertyChange(null);"*/"processDataBinding(\"" + field + "." + attr + "\");", "\n");
+ }
+ }
+ dbCreation.append("}\n");
+ dbDeletion.append("}\n");
+ dbProcess.append(gen.getBindingsToGenerate().get(field).get(attr))
+ .append(");\n}\n");
+ if(listeners != null) {
+ //jf.addField(new JavaField(Modifier.PRIVATE, "java.beans.PropertyChangeListener", "_DataSource" + dataSourceNumber, "new org.nuiton.guix.runtime.DataBindingListener(this,\"" + field + "." + attr + "\")", null, null));
+ jf.getMethod("initDataBinding", null).appendBodyCode("applyDataBinding(\"" + field + "." + attr + "\");", "\n");
+ for(Class listener : listeners) {
+ final List<Method> listenerMethods = Arrays.asList(listener.getMethods());
+ Class parameterType = listenerMethods.get(0).getParameterTypes()[0];
+ }
+ }
+ dataSourceNumber++;
+ }
}
+ if(generatedFiles.get(jf.getSuperClass()) != null) {
+ dbCreation.append("else {\nsuper.applyDataBinding(_binding);\n" +
+ "return;\n}");
+ dbDeletion.append("\nelse {\nsuper.removeDataBinding(_binding);\n}\n");
+ }
+ dbCreation.append("\nprocessDataBinding(_binding);");
+ dbProcess.insert(0, "if (activeBindings.contains(_binding)) {\n" +
+ "return;\n}\n" +
+ "activeBindings.add(_binding);\ntry{\n");
+ dbProcess.append("\n} finally {\nactiveBindings.remove(_binding);\n}\n");
+ jf.addField(new JavaField(Modifier.PRIVATE, "java.util.List<String>", "activeBindings", "new java.util.ArrayList<String>()", "List of the active bindings", null), false);
+ jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "applyDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbCreation.toString(), null));
+ jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "removeDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbDeletion.toString(), null));
+ jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "processDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbProcess.toString(), null));
+ gen.saveFiles();
}
serializer.endTag("", "beans");
serializer.endDocument();
@@ -251,6 +374,7 @@
}
}
+
/**
* Registers a ClassDescriptor
*
@@ -305,4 +429,17 @@
}
return classDescriptors.get(i);
}
+
+ private List<String> browseNode(SimpleNode node) {
+ List<String> result = new ArrayList<String>();
+ for(int i = 0 ; i < node.jjtGetNumChildren() ; i++) {
+ if(node.getChild(i).getId() == JavaParserTreeConstants.JJTPRIMARYEXPRESSION
+ && !node.getChild(i).getText().trim().startsWith("(")
+ && !node.getChild(i).getText().trim().startsWith("\"")) {
+ result.add(node.getChild(i).getText().trim());
+ }
+ result.addAll(browseNode(node.getChild(i)));
+ }
+ return result;
+ }
}
Added: trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher1.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher1.java (rev 0)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher1.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -0,0 +1,372 @@
+/**
+ * *##% guix-compiler
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.guix;
+
+import java.beans.BeanInfo;
+import java.beans.PropertyChangeListener;
+import org.nuiton.guix.compiler.GuixCompiler;
+import java.io.File;
+import java.io.PrintWriter;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EventListener;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.guix.generator.Generator;
+import org.nuiton.guix.generator.GuixGenerator;
+import org.nuiton.guix.generator.JavaArgument;
+import org.nuiton.guix.generator.JavaField;
+import org.nuiton.guix.generator.JavaFile;
+import org.nuiton.guix.generator.JavaMethod;
+import org.nuiton.guix.model.ClassDescriptor;
+import org.nuiton.guix.model.GuixModelObject;
+import org.nuiton.guix.tags.TagHandler;
+import org.nuiton.guix.tags.TagManager;
+import org.xmlpull.v1.XmlPullParserFactory;
+import org.xmlpull.v1.XmlSerializer;
+
+/**
+ * Launch Guix files compilation
+ *
+ * @author morin
+ */
+public class GuixLauncher1 {
+
+ /** log */
+ protected static final Log log = LogFactory.getLog(GuixLauncher1.class);
+ /** original list of files to compile */
+ protected final File[] files;
+ /** original list of classes to compile */
+ protected final String[] classNames;
+ /** Files to be treated while compilation. */
+ protected List<File> guixFiles = new ArrayList<File>();
+ /** Class names corresponding to the files in the guixFiles list. */
+ protected List<String> guixFileClassNames = new ArrayList<String>();
+ /** Maps the root GuixModelObjects being compiled to the compiler instance
+ * handling the compilation. */
+ protected Map<GuixModelObject, Long> rootModelObjects =
+ new HashMap<GuixModelObject, Long>();
+ /** CLassDescriptor met during the compilation */
+ protected List<ClassDescriptor> classDescriptors =
+ new ArrayList<ClassDescriptor>();
+ private List<File> compiledFiles = new ArrayList<File>();
+ private Map<GuixGenerator,JavaFile> generatedFiles = new HashMap<GuixGenerator,JavaFile>();
+ protected int compilerCount;
+ private File targetDirectory;
+ private String rootPackage;
+ private String mainClass;
+ private Class generatorClass;
+ private String launcherName;
+
+ /**
+ * Constructor
+ *
+ * @param files the files to compile
+ */
+ public GuixLauncher1(File[] files, File targetDirectory, String rootPackage,
+ File baseDir, String mainClass, Class generatorClass, String launcherName) {
+ // Set up a simple configuration that logs on the console.
+ this.files = files;
+ this.targetDirectory = targetDirectory;
+ this.rootPackage = rootPackage != null ? rootPackage : "";
+ if (files != null) {
+ classNames = new String[files.length];
+ for (int i = 0; i < files.length; i++) {
+ String path = files[i].getAbsolutePath();
+ if (baseDir != null) {
+ classNames[i] = rootPackage + "." + path.substring(baseDir.getAbsolutePath().length() + 1,
+ path.lastIndexOf('.')).replace(File.separatorChar, '.');
+ }
+ else {
+ classNames[i] = path.substring(0, path.lastIndexOf('.'));
+ }
+ }
+ }
+ else {
+ classNames = null;
+ }
+ this.mainClass = mainClass != null ? mainClass : "";
+ this.launcherName = launcherName != null ? launcherName : "Main";
+ this.generatorClass = generatorClass;
+ }
+
+ /**
+ * Compiled a set of files.
+ *
+ * @return <code>true</code> if compilation succeeds,
+ * <code>false</code> otherwise
+ */
+ public synchronized boolean compile() {
+ compilerCount = 0;
+ File destDir = targetDirectory;
+ if (files != null) {
+ if (log.isInfoEnabled()) {
+ log.info("Start compiling");
+ }
+ guixFiles.addAll(Arrays.asList(files));
+ guixFileClassNames.addAll(Arrays.asList(classNames));
+ boolean success = true;
+
+ try {
+ assert guixFiles.size() == guixFileClassNames.size();
+
+ for (int i = 0; i < guixFiles.size(); i++) {
+ File file = guixFiles.get(i);
+ String className = guixFileClassNames.get(i);
+
+ //if we have not compiled the file yet
+ if (!compiledFiles.contains(file)) {
+ if (log.isInfoEnabled()) {
+ log.info("Compiling class " + className);
+ }
+ compiledFiles.add(file);
+
+ String classPackage;
+ if (targetDirectory != null) {
+ int dotPos = className.lastIndexOf(".");
+ if (dotPos != -1) {
+ destDir = new File(targetDirectory, className.substring(0, dotPos).replace('.', File.separatorChar));
+ classPackage = className.substring(0, dotPos);
+ }
+ else {
+ destDir = new File(targetDirectory, className);
+ classPackage = className;
+ }
+ if (!destDir.exists() && !destDir.mkdirs()) {
+ if (log.isWarnEnabled()) {
+ log.warn("couldn't create directory " + destDir);
+ }
+ continue;
+ }
+ }
+ else {
+ destDir = file.getParentFile();
+ classPackage = destDir.getAbsolutePath().replace(File.separatorChar, '.');
+ }
+ //compile the file
+ // GuixCompiler compiler = new GuixCompiler(file, this, classPackage);
+ GuixCompiler compiler = null;
+
+ GuixModelObject rootModelObject = compiler.compile();
+ rootModelObjects.put(rootModelObject, compiler.getLastModification());
+
+ if (compiler.isFailed()) {
+ success = false;
+ }
+ }
+ else {
+ if (log.isWarnEnabled()) {
+ log.warn(file.getName() + " has already been compiled.");
+ }
+ }
+ }
+
+ if (success) {
+ int i = 0;
+ while (success && i < classDescriptors.size()) {
+ success = (classDescriptors.get(i).getPackageName() != null || TagManager.getGuixClassHandler(classDescriptors.get(i).getName()) != null);
+ i++;
+ }
+ if (!success) {
+ if (log.isErrorEnabled()) {
+ log.error("The class '" + classDescriptors.get(--i).getName() + "' has no package.");
+ }
+ }
+ }
+
+ if (generatorClass != null) {
+ //creates the XML serializer for the spring conf
+ XmlPullParserFactory factory =
+ XmlPullParserFactory.newInstance(
+ System.getProperty(XmlPullParserFactory.PROPERTY_NAME),
+ null);
+ XmlSerializer serializer = factory.newSerializer();
+
+ File config = new File(targetDirectory,"config.xml");
+
+ serializer.setOutput(new PrintWriter(config));
+ serializer.startDocument("UTF-8", null);
+ serializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n");
+ serializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "\t");
+ serializer.text("\n");
+ serializer.docdecl(" beans SYSTEM \"http://www.springframework.org/dtd/spring-beans.dtd\"");
+ serializer.text("\n");
+ serializer.startTag("", "beans");
+
+ for (GuixModelObject mo : rootModelObjects.keySet()) {
+ try {
+ GuixGenerator gen = (GuixGenerator) generatorClass.newInstance();
+ gen.setDestDir(destDir);
+ gen.setGmo(mo);
+ gen.setLastModification(rootModelObjects.get(mo));
+ gen.setMainClass((mo.getClassDescriptor().getPackageName() + "." + mo.getClassDescriptor().getName()).equals(mainClass));
+ gen.setSerializer(serializer);
+ gen.setClasses(Arrays.asList(classNames));
+ gen.setLauncherName(launcherName);
+ generatedFiles.put(gen,gen.generate());
+ }
+ catch (InstantiationException eee) {
+ if(log.isErrorEnabled())
+ log.error(eee);
+ }
+ catch (IllegalAccessException eee) {
+ if(log.isErrorEnabled())
+ log.error(eee);
+ }
+ }
+ for(GuixGenerator gen : generatedFiles.keySet()) {
+ int dataSourceNumber = 0;
+ StringBuffer dbCreation = new StringBuffer();
+ StringBuffer dbDeletion = new StringBuffer();
+ StringBuffer dbProcess = new StringBuffer();
+ JavaFile jf = generatedFiles.get(gen);
+ for(String field : gen.getBindingsToGenerate().keySet()) {
+ for(String attr : gen.getBindingsToGenerate().get(field).keySet()) {
+ dbCreation.append(dbCreation.length() != 0 ? "else if(\"" : "if(\"").append(field)
+ .append(".").append(attr)
+ .append("\".equals(_binding)) {\n");
+ dbDeletion.append(dbDeletion.length() != 0 ? "else if(\"" : "if(\"").append(field)
+ .append(".").append(attr)
+ .append("\".equals(_binding)) {\n");
+ dbProcess.append(dbProcess.length() != 0 ? "else if(\"" : "if(\"").append(field)
+ .append(".").append(attr)
+ .append("\".equals(_binding)) {\n")
+ .append(field).append(".set")
+ .append(Character.toUpperCase(attr.charAt(0)))
+ .append(attr.substring(1))
+ .append("(");
+ String[] binding = gen.getBindingsToGenerate().get(field).get(attr).split("\\s*\\.\\s*");
+ String methodToInvoke = gen.getBindingsToGenerate().get(field).get(attr).replaceAll("\\W", "");
+ List<Class> listeners = gen.generateBindings(dbCreation, dbDeletion, null, jf, null,null, 0, null, methodToInvoke, generatedFiles);
+ dbCreation.append("}\n");
+ dbDeletion.append("}\n");
+ dbProcess.append(");\n}\n");
+ if(listeners != null) {
+ jf.addField(new JavaField(Modifier.PRIVATE, "java.beans.PropertyChangeListener", "_DataSource" + dataSourceNumber, "new org.nuiton.guix.runtime.DataBindingListener(this,\"" + field + "." + attr + "\")", null, null));
+ jf.getMethod("initDataBinding", null).appendBodyCode("applyDataBinding(\"" + field + "." + attr + "\");", "\n");
+ for(Class listener : listeners) {
+ final List<Method> listenerMethods = Arrays.asList(listener.getMethods());
+ Class parameterType = listenerMethods.get(0).getParameterTypes()[0];
+ JavaArgument[] args = new JavaArgument[]{new JavaArgument(parameterType.getName(), "event")};
+ if (jf.getMethod("onChangeFrom" + methodToInvoke, args) == null) {
+ jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "onChangeFrom" + methodToInvoke, args, null, "_DataSource" + dataSourceNumber + ".propertyChange(null);", null));
+ }
+ else {
+ jf.getMethod("onChangeFrom" + methodToInvoke, args).appendBodyCode("_DataSource" + dataSourceNumber + ".propertyChange(null);", "\n");
+ }
+ }
+ }
+ dataSourceNumber++;
+ }
+ }
+ if(generatedFiles.get(jf.getSuperClass()) != null) {
+ dbCreation.append("else {\nsuper.applyDataBinding(_binding);\n" +
+ "return;\n}");
+ dbDeletion.append("\nelse {\nsuper.removeDataBinding(_binding);\n}\n");
+ }
+ dbCreation.append("\nprocessDataBinding(_binding);");
+ jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "applyDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbCreation.toString(), null));
+ jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "removeDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbDeletion.toString(), null));
+ jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "processDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbProcess.toString(), null));
+ gen.saveFiles();
+ }
+ serializer.endTag("", "beans");
+ serializer.endDocument();
+ }
+ else {
+ if(log.isWarnEnabled()) {
+ log.warn("No generation language given");
+ }
+ }
+ }
+ catch (Throwable e) {
+ e.printStackTrace();
+ return false;
+ }
+ return success;
+ }
+ else {
+ if (log.isWarnEnabled()) {
+ log.warn("No file to compile");
+ }
+ return true;
+ }
+ }
+
+
+ /**
+ * Registers a ClassDescriptor
+ *
+ * @param classDescriptor the ClassDescripor to register
+ * @return false if another ClassDescriptor with the same classname
+ * and package has a different script or superclass
+ */
+ public ClassDescriptor registerClassDescriptor(ClassDescriptor classDescriptor) {
+ if (classDescriptor == null || classDescriptor.getName() == null) {
+ return null;
+ }
+ int i = 0;
+ while (i < classDescriptors.size() && (!classDescriptors.get(i).getName().equals(classDescriptor.getName()) || (classDescriptors.get(i).getPackageName() != null && classDescriptor.getPackageName() != null && !classDescriptors.get(i).getPackageName().equals(classDescriptor.getPackageName())))) {
+ i++;
+ }
+ //if the ClassDescriptor does not exist
+ if (i >= classDescriptors.size()) {
+ classDescriptors.add(classDescriptor);
+ if (log.isDebugEnabled()) {
+ log.debug("new ClassDescriptor " + classDescriptor + " inserted");
+ }
+ return classDescriptor;
+ }
+ classDescriptors.get(i).setPackageName(classDescriptor.getPackageName());
+ if (classDescriptor.getScript() != null) {
+ if (classDescriptors.get(i).getScript() == null) {
+ classDescriptors.get(i).setScript(classDescriptor.getScript());
+ if (log.isDebugEnabled()) {
+ log.debug("add script to ClassDescriptor " + classDescriptor);
+ }
+ }
+ else if (!classDescriptors.get(i).getScript().equals(classDescriptor.getScript())) {
+ if (log.isDebugEnabled()) {
+ log.error("ClassDescriptor " + classDescriptor + " script already defined and different !");
+ }
+ return null;
+ }
+ }
+ if (classDescriptor.getSuperClass() != null) {
+ if (classDescriptors.get(i).getSuperClass() == null) {
+ classDescriptors.get(i).setSuperClass(classDescriptor.getSuperClass());
+ if (log.isDebugEnabled()) {
+ log.debug("add superclass to ClassDescriptor " + classDescriptor);
+ }
+ }
+ else if (!classDescriptors.get(i).getSuperClass().equals(classDescriptor.getSuperClass())) {
+ if (log.isErrorEnabled()) {
+ log.error("ClassDescriptor " + classDescriptor + " superclass already defined and different !");
+ }
+ return null;
+ }
+ }
+ return classDescriptors.get(i);
+ }
+}
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/BindingUtils.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/BindingUtils.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/BindingUtils.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -88,24 +88,25 @@
expression.append(escapeJavaString(stringValue.substring(lastPos)));
expression.append('"');
}
-
- StringBuffer el = new StringBuffer();
- Pattern p = Pattern .compile("\\.(get|is)([A-Z])([a-zA-Z0-9]*)\\(\\)");
- Matcher m = p.matcher(expression.toString());
- int mEnd = 0;
- if(m.find()) {
- do {
- el.append(expression.toString().substring(mEnd, m.start()))
- .append(".");
- mEnd = m.end();
- el.append(m.group(2).toLowerCase())
- .append(m.group(3));
- } while (m.find());
- }
- else {
- el.append(expression.toString());
- }
- return el.toString().length() > 0 ? el.toString().substring(0, el.toString().length()) : el.toString();
+//
+// StringBuffer el = new StringBuffer();
+// Pattern p = Pattern .compile("\\.(get|is)([A-Z])([a-zA-Z0-9]*)\\(\\)");
+// Matcher m = p.matcher(expression.toString());
+// int mEnd = 0;
+// if(m.find()) {
+// do {
+// el.append(expression.toString().substring(mEnd, m.start()))
+// .append(".");
+// mEnd = m.end();
+// el.append(m.group(2).toLowerCase())
+// .append(m.group(3));
+// } while (m.find());
+// }
+// else {
+// el.append(expression.toString());
+// }
+// return el.toString().length() > 0 ? el.toString().substring(0, el.toString().length()) : el.toString();
+ return expression.toString();
}
return null;
}
Added: trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataBinding.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataBinding.java (rev 0)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataBinding.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2006 Ethan Nicholas. All rights reserved.
+ * Use is subject to license terms.
+ */
+package org.nuiton.guix.databinding;
+
+import org.nuiton.guix.CompilerException;
+import org.nuiton.guix.compiler.GuixCompiler;
+
+/**
+ * Represents a data binding in a JAXX file. <code>DataBinding</code> uses {@link DataSource} to
+ * track changes to a source expression and update the destination.
+ */
+public class DataBinding {
+ private String id;
+
+ /** The DatSource which tracks source expression changes. */
+ private DataSource dataSource;
+
+ /** The data binding destination in the form <code><id>.<propertyName></code>. */
+ private String dest;
+
+ /**
+ * A Java snippet which will cause the destination property to be updated with the current value of
+ * the binding.
+ */
+ private String assignment;
+
+ /** The current <code>GuixCompiler</code>. */
+ private GuixCompiler compiler;
+
+
+ /**
+ * Creates a new data binding.
+ *
+ * @param source the Java source code for the data binding expression
+ * @param dest the data binding destination in the form <code><id>.<propertyName></code>
+ * @param assignment Java snippet which will cause the destination property to be updated with the current value of the binding
+ * @param compiler the current <code>JAXXCompiler</code>
+ */
+ public DataBinding(String source, String dest, String assignment, GuixCompiler compiler) {
+ this.id = dest;
+ this.dataSource = new DataSource(id, source);
+ this.dest = dest;
+ this.assignment = assignment;
+ this.compiler = compiler;
+ }
+
+
+ public String getId() {
+ return id;
+ }
+
+
+ /**
+ * Compiles the data binding expression. This method calls methods in <code>JAXXCompiler</code>
+ * to add the Java code that performs the data binding setup.
+ *
+ * @param quickNoDependencies true to optimize bindings with no dependencies by simply running them at startup time
+ * @return <code>true</code> if the expression has dependencies, <code>false</code> otherwise
+ * @throws CompilerException if a compilation error occurs
+ */
+// public boolean compile(boolean quickNoDependencies) throws CompilerException {
+// // DataSource.compile handles all of the listener additions
+// boolean result = dataSource.compile("new jaxx.runtime.DataBindingListener(" + compiler.getRootObject().getJavaCode() + ", " + TypeManager.getJavaCode(id) + ")");
+//
+// if (!result && quickNoDependencies) {
+// if (!dest.endsWith(".layout")) // layout is specially handled early in the chain
+// {
+// compiler.appendInitDataBindings(assignment + JAXXCompiler.getLineSeparator());
+// }
+// return false; // no dependencies, just a static expression
+// }
+// if (compiler.haveProcessDataBinding()) {
+// compiler.appendProcessDataBinding(" else ");
+// } else {
+// compiler.appendProcessDataBinding(" ");
+// }
+// compiler.appendProcessDataBinding("if (" + TypeManager.getJavaCode(id) + ".equals($dest)) {" + JAXXCompiler.getLineSeparator());
+// String objectCode = dataSource.getObjectCode();
+// if (objectCode != null) {
+// compiler.appendProcessDataBinding(" if (" + objectCode + " != null) {" + JAXXCompiler.getLineSeparator());
+// compiler.appendProcessDataBinding(" ");
+// }
+// compiler.appendProcessDataBinding(" " + assignment.trim());
+// if (objectCode != null) {
+// compiler.appendProcessDataBinding(JAXXCompiler.getLineSeparator() + " }");
+// }
+// compiler.appendProcessDataBinding(JAXXCompiler.getLineSeparator() + " }");
+// return true;
+// }
+}
\ No newline at end of file
Added: trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataSource.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataSource.java (rev 0)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataSource.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -0,0 +1,460 @@
+/*
+ * Copyright 2006 Ethan Nicholas. All rights reserved.
+ * Use is subject to license terms.
+ */
+package org.nuiton.guix.databinding;
+
+import java.beans.Introspector;
+import java.beans.PropertyChangeListener;
+import java.io.StringReader;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.guix.CompilerException;
+import org.nuiton.guix.UnsupportedAttributeException;
+import org.nuiton.guix.generator.JavaField;
+import org.nuiton.guix.parser.JavaParser;
+import org.nuiton.guix.parser.JavaParserConstants;
+import org.nuiton.guix.parser.JavaParserTreeConstants;
+import org.nuiton.guix.parser.SimpleNode;
+import org.nuiton.guix.tags.DefaultTagHandler;
+import org.nuiton.guix.tags.TagHandler;
+import org.nuiton.guix.tags.TagManager;
+
+/**
+ * Represents a Java expression which fires a <code>PropertyChangeEvent</code> when it can be
+ * determined that its value may have changed. Events are fired on a "best effort" basis, and events
+ * may either be fired too often (the value has not actually changed) or not often enough (the value
+ * changed but no event was fired).
+ */
+public class DataSource {
+ private class NULL {
+ } // type attached to "null" constants in parsed expressions
+
+ private Log log = LogFactory.getLog(DataSource.class);
+
+ private String id;
+
+ /** The Java source code for the expression. */
+ private String source;
+
+ /** The current <code>JAXXCompiler</code>. */
+ //private JAXXCompiler compiler;
+
+ /** List of symbols which this data source expression depends on. */
+ private List<String> dependencySymbols = new ArrayList<String>();
+
+ private StringBuffer addListenerCode = new StringBuffer();
+ private StringBuffer removeListenerCode = new StringBuffer();
+ private boolean compiled;
+
+ /** the delegate of property to be required */
+ private String objectCode;
+
+ /**
+ * Creates a new data source. After creating a <code>DataSource</code>, use {@link #compile}
+ * to cause it to function at runtime.
+ *
+ * @param id the DataSource's id
+ * @param source the Java source code for the data source expression
+ * @param compiler the current <code>JAXXCompiler</code>
+ */
+ public DataSource(String id, String source) {
+ this.id = id;
+ this.source = source;
+ }
+
+
+ public String getId() {
+ return id;
+ }
+
+ public String getSource() {
+ return source;
+ }
+
+ public String getObjectCode() {
+ return objectCode;
+ }
+
+ /**
+ * Compiles the data source expression and listener. This method calls methods in <code>JAXXCompiler</code>
+ * to add the Java code that performs the data source setup. Adding listeners to <code>DataSource</code> is
+ * slightly more complicated than with ordinary classes, because <code>DataSource</code> only exists at compile
+ * time. You must pass in a Java expression which evaluates to a <code>PropertyChangeListener</code>; this
+ * expression will be compiled and evaluated at runtime to yield the <code>DataSource's</code> listener.
+ *
+ * @param propertyChangeListenerCode Java code snippet which evaluates to a <code>PropertyChangeListener</code>
+ * @return <code>true</code> if the expression has dependencies, <code>false</code> otherwise
+ * @throws CompilerException if a compilation error occurs
+ */
+// public boolean compile(String propertyChangeListenerCode) throws CompilerException {
+// if (compiled) {
+// throw new IllegalStateException(this + " has already been compiled");
+// }
+// String id = "";
+// JavaParser p = new JavaParser(new StringReader(source + ";"));
+// while (!p.Line()) {
+// SimpleNode node = p.popNode();
+// scanNode(node, id);
+// }
+//
+// if (dependencySymbols.size() > 0) {
+// //TC 20081108 prefer add a real JavaField instead of raw code
+// //compiler.appendBodyCode("private PropertyChangeListener " + id + " = " + propertyChangeListenerCode + ";\n");
+// compiler.addSimpleField(new JavaField(Modifier.PRIVATE, PropertyChangeListener.class.getName(), id, propertyChangeListenerCode));
+// }
+//
+// compileListeners();
+// compiled = true;
+//
+// return dependencySymbols.size() > 0;
+// }
+//
+// /** @return a list of symbols on which this data source depends. */
+// public Collection<String> getDependencies() {
+// return Collections.unmodifiableList(dependencySymbols);
+// }
+//
+// /**
+// * Examines a node to identify any dependencies it contains.
+// *
+// * @param node node to scan
+// * @param listenerId id of listener
+// * @throws jaxx.CompilerException ?
+// */
+// private void scanNode(SimpleNode node, String listenerId) throws CompilerException {
+// switch (node.getId()) {
+// case JavaParserTreeConstants.JJTMETHODDECLARATION:
+// break;
+// case JavaParserTreeConstants.JJTFIELDDECLARATION:
+// break;
+//
+// default:
+// int count = node.jjtGetNumChildren();
+// for (int i = 0; i < count; i++) {
+// scanNode(node.getChild(i), listenerId);
+// }
+// determineNodeType(node, listenerId);
+// }
+// }
+//
+// private Class determineLiteralType(SimpleNode node) {
+// assert node.getId() == JavaParserTreeConstants.JJTLITERAL;
+// if (node.jjtGetNumChildren() == 1) {
+// int id = node.getChild(0).getId();
+// if (id == JavaParserTreeConstants.JJTBOOLEANLITERAL) {
+// return boolean.class;
+// }
+// if (id == JavaParserTreeConstants.JJTNULLLITERAL) {
+// return null;
+// }
+// throw new RuntimeException("Expected BooleanLiteral or NullLiteral, found " + JavaParserTreeConstants.jjtNodeName[id]);
+// }
+// int id = node.firstToken.kind;
+// switch (id) {
+// case JavaParserConstants.INTEGER_LITERAL:
+// if (node.firstToken.image.toLowerCase().endsWith("l")) {
+// return long.class;
+// }
+// return int.class;
+// case JavaParserConstants.CHARACTER_LITERAL:
+// return char.class;
+// case JavaParserConstants.FLOATING_POINT_LITERAL:
+// if (node.firstToken.image.toLowerCase().endsWith("f")) {
+// return float.class;
+// }
+// return double.class;
+// case JavaParserConstants.STRING_LITERAL:
+// return String.class;
+// default:
+// throw new RuntimeException("Expected literal token, found " + JavaParserConstants.tokenImage[id]);
+// }
+// }
+//
+// /**
+// * Scans through a compound symbol (foo.bar.baz) to identify and track all trackable pieces of it.
+// *
+// * @param symbol symbol to scan
+// * @param contextClass current class context
+// * @param isMethod flag to search a method
+// * @param listenerId id of the listener
+// * @return the type of the symbol (or null if it could not be determined).
+// */
+// private Class scanCompoundSymbol(String symbol, Class contextClass, boolean isMethod, String listenerId) {
+// String[] tokens = symbol.split("\\s*\\.\\s*");
+// StringBuffer currentSymbol = new StringBuffer();
+// StringBuffer tokensSeenSoFar = new StringBuffer();
+// boolean accepted; // if this ends up false, it means we weren't able to figure out
+// // which object the method is being invoked on
+// boolean recognizeClassNames = true;
+// for (int j = 0; j < tokens.length - (isMethod ? 1 : 0); j++) {
+// accepted = false;
+//
+// if (tokensSeenSoFar.length() > 0) {
+// tokensSeenSoFar.append('.');
+// }
+// tokensSeenSoFar.append(tokens[j]);
+// if (currentSymbol.length() > 0) {
+// currentSymbol.append('.');
+// }
+// currentSymbol.append(tokens[j]);
+//
+// if (currentSymbol.indexOf(".") == -1) {
+// String memberName = currentSymbol.toString();
+// CompiledObject object = compiler.getCompiledObject(memberName);
+// if (object != null) {
+// contextClass = object.getObjectClass();
+// currentSymbol.setLength(0);
+// accepted = true;
+// recognizeClassNames = false;
+// } else {
+// try {
+// FieldDescriptor field = contextClass.getFieldDescriptor(memberName);
+// trackMemberIfPossible(tokensSeenSoFar.toString(), contextClass, field.getName(), false, listenerId);
+// contextClass = field.getType();
+// currentSymbol.setLength(0);
+// accepted = true;
+// recognizeClassNames = false;
+// }
+// catch (NoSuchFieldException e) {
+// if (j == 0 || j == 1 && tokens[0].equals(compiler.getRootObject().getId())) { // still in root context
+// FieldDescriptor[] newFields = compiler.getScriptFields();
+// for (FieldDescriptor newField : newFields) {
+// if (newField.getName().equals(memberName)) {
+// addListener(tokensSeenSoFar.toString(),
+// null,
+// "addPropertyChangeListener(\"" + memberName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator(),
+// "removePropertyChangeListener(\"" + memberName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator());
+// contextClass = newField.getType();
+// assert contextClass != null : "script field '" + memberName + "' is defined, but has type null";
+// currentSymbol.setLength(0);
+// accepted = true;
+// recognizeClassNames = false;
+// break;
+// }
+// }
+// }
+// }
+// }
+// }
+// if (currentSymbol.length() > 0 && recognizeClassNames) {
+// contextClass = TagManager.resolveClass(currentSymbol.toString(), compiler);
+// if (contextClass != null) {
+// currentSymbol.setLength(0);
+// //accepted = true;
+// //recognizeClassNames = false;
+// // TODO: for now we don't handle statics
+// return null;
+// }
+// }
+// if (!accepted) {
+// return null;
+// }
+// }
+//
+// return contextClass;
+// }
+//
+// /**
+// * Adds type information to nodes where possible, and as a side effect adds event listeners to nodes which
+// * can be tracked.
+// *
+// * @param expression the node to scan
+// * @param listenerId id of the listener
+// * @return the class descriptor of the return type or null
+// */
+// private Class determineExpressionType(SimpleNode expression, String listenerId) {
+// assert expression.getId() == JavaParserTreeConstants.JJTPRIMARYEXPRESSION;
+// SimpleNode prefix = expression.getChild(0);
+// if (prefix.jjtGetNumChildren() == 1) {
+// int type = prefix.getChild(0).getId();
+// if (type == JavaParserTreeConstants.JJTLITERAL || type == JavaParserTreeConstants.JJTEXPRESSION) {
+// prefix.setJavaType(prefix.getChild(0).getJavaType());
+// } else if (type == JavaParserTreeConstants.JJTNAME && expression.jjtGetNumChildren() == 1) // name with no arguments after it
+// {
+// prefix.setJavaType(scanCompoundSymbol(prefix.getText().trim(), compiler.getRootObject().getObjectClass(), false, listenerId));
+// }
+// }
+//
+// if (expression.jjtGetNumChildren() == 1) {
+// return prefix.getJavaType();
+// }
+//
+// Class contextClass = prefix.getJavaType();
+// if (contextClass == null) {
+// contextClass = compiler.getRootObject().getObjectClass();
+// }
+// String lastNode = prefix.getText().trim();
+//
+// for (int i = 1; i < expression.jjtGetNumChildren(); i++) {
+// SimpleNode suffix = expression.getChild(i);
+// if (suffix.jjtGetNumChildren() == 1 && suffix.getChild(0).getId() == JavaParserTreeConstants.JJTARGUMENTS) {
+// if (suffix.getChild(0).jjtGetNumChildren() == 0) { // at the moment only no-argument methods are trackable
+// contextClass = scanCompoundSymbol(lastNode, contextClass, true, listenerId);
+// if (contextClass == null) {
+// return null;
+// }
+// int dotPos = lastNode.lastIndexOf(".");
+// String objectCode = dotPos == -1 ? "" : lastNode.substring(0, dotPos);
+// for (int j = i - 2; j >= 0; j--) {
+// objectCode = expression.getChild(j).getText() + objectCode;
+// }
+// if (objectCode.length() == 0) {
+// objectCode = compiler.getRootObject().getJavaCode();
+// }
+// String methodName = lastNode.substring(dotPos + 1).trim();
+// try {
+// MethodDescriptor method = contextClass.getMethodDescriptor(methodName);
+// trackMemberIfPossible(objectCode, contextClass, method.getName(), true, listenerId);
+// return method.getReturnType();
+// }
+// catch (NoSuchMethodException e) {
+// // happens for methods defined in the current JAXX file via scripts
+// String propertyName = null;
+// if (methodName.startsWith("is")) {
+// propertyName = Introspector.decapitalize(methodName.substring("is".length()));
+// } else if (methodName.startsWith("get")) {
+// propertyName = Introspector.decapitalize(methodName.substring("get".length()));
+// }
+// if (propertyName != null) {
+// MethodDescriptor[] newMethods = compiler.getScriptMethods();
+// for (MethodDescriptor newMethod : newMethods) {
+// if (newMethod.getName().equals(methodName)) {
+// addListener(compiler.getRootObject().getId(),
+// null,
+// "addPropertyChangeListener(\"" + propertyName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator(),
+// "removePropertyChangeListener(\"" + propertyName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator());
+// contextClass = newMethod.getReturnType();
+// break;
+// }
+// }
+// }
+// }
+// }
+// }
+// lastNode = suffix.getText().trim();
+// if (lastNode.startsWith(".")) {
+// lastNode = lastNode.substring(1);
+// }
+// }
+//
+// return null;
+// }
+//
+//// private void trackMemberIfPossible(String objectCode, Class objectClass, String memberName, boolean method, String listenerId) {
+//// if (objectClass.isInterface()) // might be technically possible to track in some cases, but for now
+//// {
+//// return; // we can't create a DefaultObjectHandler for interfaces
+//// }
+////
+//// TagHandler handler = (TagHandler)TagManager.getGuixClassHandler(objectClass.getName()).newInstance();
+//// try {
+//// if (handler.isMemberBound(memberName)) {
+//// addListener(objectCode + "." + memberName + (method ? "()" : ""),
+//// objectCode,
+//// handler.getAddMemberListenerCode(objectCode, id, memberName, listenerId, compiler),
+//// handler.getRemoveMemberListenerCode(objectCode, id, memberName, listenerId, compiler));
+//// }
+//// }
+//// catch (UnsupportedAttributeException e) {
+//// // ignore -- this is thrown for methods like toString(), for which there is no tracking and
+//// // no setting support
+//// }
+//// }
+//
+// /**
+// * Adds type information to nodes where possible, and as a side effect adds event listeners to nodes which
+// * can be tracked.
+// *
+// * @param node node to scan
+// * @param listenerId the listener id
+// */
+// private void determineNodeType(SimpleNode node, String listenerId) {
+// Class type = null;
+// if (node.jjtGetNumChildren() == 1) {
+// type = node.getChild(0).getJavaType();
+// }
+// switch (node.getId()) {
+// case JavaParserTreeConstants.JJTCLASSORINTERFACETYPE:
+// type = Class.class;
+// break;
+// case JavaParserTreeConstants.JJTPRIMARYEXPRESSION:
+// type = determineExpressionType(node, listenerId);
+// break;
+// case JavaParserTreeConstants.JJTLITERAL:
+// type = determineLiteralType(node);
+// break;
+// case JavaParserTreeConstants.JJTCASTEXPRESSION:
+// try {
+// type = Class.forName(node.getChild(0).getText());
+// }
+// catch (ClassNotFoundException eee) {
+// if(log.isErrorEnabled()) {
+// log.error(eee);
+// }
+// }
+// break;
+// }
+// node.setJavaType(type);
+// }
+//
+// private void addListener(String dependencySymbol, String objectCode, String addCode, String removeCode) {
+// this.objectCode = objectCode;
+// if (!dependencySymbols.contains(dependencySymbol)) {
+// dependencySymbols.add(dependencySymbol);
+// if (objectCode != null) {
+// addListenerCode.append("if (").append(objectCode).append(" != null) {").append(JAXXCompiler.getLineSeparator());
+// addListenerCode.append(" ");
+// }
+// addListenerCode.append(" ").append(addCode);
+// if (objectCode != null) {
+// addListenerCode.append(" ").append("}");
+// }
+//
+// if (objectCode != null) {
+// removeListenerCode.append("if (").append(objectCode).append(" != null) {").append(JAXXCompiler.getLineSeparator());
+// removeListenerCode.append(" ");
+// }
+// removeListenerCode.append(" ").append(removeCode);
+// if (objectCode != null) {
+// removeListenerCode.append(" }");
+// }
+// }
+// }
+//
+// private void compileListeners() {
+// String javaCodeId = TypeManager.getJavaCode(id);
+// if (addListenerCode.length() > 0) {
+// if (compiler.haveApplyDataBinding()) {
+// compiler.appendApplyDataBinding(" else ");
+// }
+// compiler.appendApplyDataBinding("if (" + javaCodeId + ".equals($binding)) {" + JAXXCompiler.getLineSeparator());
+// compiler.appendApplyDataBinding(" " + addListenerCode + JAXXCompiler.getLineSeparator());
+// compiler.appendApplyDataBinding("}");
+// //if (compiler.applyDataBinding.length() > 0)
+// // compiler.applyDataBinding.append("else ");
+// //compiler.applyDataBinding.append("if ($binding.equals(").append(TypeManager.getJavaCode(id)).append(")) {").append(JAXXCompiler.getLineSeparator());
+// //compiler.applyDataBinding.append(" ").append(addListenerCode).append(JAXXCompiler.getLineSeparator());
+// //compiler.applyDataBinding.append("}").append(JAXXCompiler.getLineSeparator());
+// }
+//
+// if (removeListenerCode.length() > 0) {
+// if (compiler.haveRemoveDataBinding()) {
+// compiler.appendRemoveDataBinding(" else ");
+// }
+// compiler.appendRemoveDataBinding("if (" + javaCodeId + ".equals($binding)) {" + JAXXCompiler.getLineSeparator());
+// compiler.appendRemoveDataBinding(" " + removeListenerCode + JAXXCompiler.getLineSeparator());
+// compiler.appendRemoveDataBinding("}");
+// //if (compiler.removeDataBinding.length() > 0)
+// // compiler.removeDataBinding.append("else ");
+// //compiler.removeDataBinding.append("if ($binding.equals(").append(TypeManager.getJavaCode(id)).append(")) {").append(JAXXCompiler.getLineSeparator());
+// //compiler.removeDataBinding.append(" ").append(removeListenerCode).append(JAXXCompiler.getLineSeparator());
+// //compiler.removeDataBinding.append("}").append(JAXXCompiler.getLineSeparator());
+// }
+// }
+}
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/Generator.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/Generator.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/Generator.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -31,7 +31,7 @@
*/
public interface Generator {
- public void generate();
+ public JavaFile generate();
public File getDestDir();
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -20,8 +20,11 @@
package org.nuiton.guix.generator;
import java.io.File;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.nuiton.guix.model.GuixModelObject;
+import org.nuiton.guix.tags.TagHandler;
import org.xmlpull.v1.XmlSerializer;
/**
@@ -45,8 +48,10 @@
protected List<String> classes = null;
/** Name to give to the generated launcher*/
protected String launcherName = null;
+ /** */
+ protected Map<String,Map<String, String>> bindings2Generate = new HashMap<String,Map<String, String>>();
- public abstract void generate();
+ public abstract JavaFile generate();
public File getDestDir() {
return destDir;
@@ -104,4 +109,16 @@
this.launcherName = launcherName;
}
+ public Map<String,Map<String, String>> getBindingsToGenerate() {
+ return bindings2Generate;
+ }
+
+ public void setBindingsToGenerate(Map<String,Map<String, String>> bindings2Generate) {
+ this.bindings2Generate = bindings2Generate;
+ }
+
+ public abstract void saveFiles();
+
+ public abstract List<Class> generateBindings(StringBuffer dbCreation, StringBuffer dbDeletion, TagHandler prevTh, JavaFile jf,
+ Class clazz, String[] binding, int i, List<String> alreadyChecked, String methodToInvoke, Map<GuixGenerator,JavaFile> generatedFiles);
}
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaField.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaField.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaField.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -20,6 +20,7 @@
import java.lang.reflect.Modifier;
import java.util.Comparator;
+import org.nuiton.guix.tags.TagHandler;
/**
* Represents a field in a Java source file being generated for output. <code>JavaFields</code> are created
@@ -32,6 +33,7 @@
private String name;
private String initializer;
private String javaDoc;
+ private TagHandler tagHandler;
/**
@@ -44,10 +46,23 @@
* @param name the field's name
*/
public JavaField(int modifiers, String type, String name, String javaDoc) {
- this(modifiers, type, name, null, javaDoc);
+ this(modifiers, type, name, null, javaDoc, null);
}
+ /**
+ * Constructs a new <code>JavaField</code>. The <code>modifiers</code> parameter is a bit mask of the
+ * constants from {@link java.lang.reflect.Modifier}, and the <code>type</code> of the field should be
+ * represented as it would appear in Java source code.
+ *
+ * @param modifiers the modifier keywords that should appear as part of the field's declaration
+ * @param type the type of the field as it would appear in Java source code
+ * @param name the field's name
+ */
+ public JavaField(int modifiers, String type, String name, String javaDoc, TagHandler tagHanlder) {
+ this(modifiers, type, name, null, javaDoc, tagHanlder);
+ }
+
/**
* Constructs a new <code>JavaField</code>. The <code>modifiers</code> parameter is a bit mask of the
* constants from <code>java.lang.reflect.Modifier</code>, and the <code>type</code> of the field should be
@@ -60,12 +75,13 @@
* @param name the field's name
* @param initializer the initial value of the field, as it would appear in Java source code
*/
- public JavaField(int modifiers, String type, String name, String initializer, String javaDoc) {
+ public JavaField(int modifiers, String type, String name, String initializer, String javaDoc, TagHandler tagHandler) {
this.modifiers = modifiers;
this.type = type;
this.name = name;
this.initializer = initializer;
this.javaDoc = javaDoc;
+ this.tagHandler = tagHandler;
}
@@ -100,7 +116,11 @@
return type;
}
+ public TagHandler getTagHandler() {
+ return tagHandler;
+ }
+
/**
* Returns the Java source code for this field.
*
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFile.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFile.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFile.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -27,6 +27,8 @@
import java.util.EnumMap;
import java.util.List;
import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* A Java source file being generated for output. Once the class is completely initialized, use the
@@ -156,6 +158,30 @@
return methods.toArray(new JavaMethod[methods.size()]);
}
+ public JavaMethod getMethod(String methodName, JavaArgument[] args) {
+ for(JavaMethod method : methods) {
+ if(method.getName().equals(methodName)) {
+ if(method.getArguments() == null && args == null) {
+ return method;
+ }
+ else if (method.getArguments().length == args.length) {
+ boolean samesame = true;
+ for(int i = 0 ; i < args.length ; i++) {
+ if(!args[i].getName().equals(method.getArguments()[i].getName())
+ || !args[i].getType().equals(method.getArguments()[i].getType())) {
+ samesame = false;
+ break;
+ }
+ }
+ if(samesame) {
+ return method;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
public void addField(JavaField field) {
addField(field, false);
}
@@ -190,31 +216,48 @@
return fields.toArray(new JavaField[fields.size()]);
}
+ public JavaField getField(String fieldName) {
+ for(JavaField field : fields) {
+ if(field.getName().equals(fieldName)) {
+ return field;
+ }
+ }
+ return null;
+ }
- public static String addIndentation(String source, int indentation, String lineSeparator) {
- return indent(source, indentation, false, lineSeparator);
+
+ public static String addIndentation(String source, String lineSeparator) {
+ return indent(source, false, lineSeparator);
}
- public static String setIndentation(String source, int indentation, String lineSeparator) {
- return indent(source, indentation, true, lineSeparator);
+ public static String setIndentation(String source, String lineSeparator) {
+ return indent(source, true, lineSeparator);
}
- public static String indent(String source, int indentation, boolean trim, String lineSeparator) {
+ public static String indent(String source, boolean trim, String lineSeparator) {
if (trim) {
source = source.trim();
}
- char[] spaces = new char[indentation];
- Arrays.fill(spaces, ' ');
+ char[] spaces = new char[1];
+ Arrays.fill(spaces, '\t');
StringBuffer result = new StringBuffer();
String[] lines = source.split(System.getProperty("line.separator") + "|\n");
for (int i = 0; i < lines.length; i++) {
if (i > 0) {
result.append(lineSeparator);
}
+ if(lines[i].equals(lines[i].trim()) && (lines[i].trim().startsWith("}") || lines[i].trim().endsWith("}"))) {
+ spaces = new char[spaces.length - 1];
+ Arrays.fill(spaces, '\t');
+ }
result.append(spaces);
result.append(trim ? lines[i].trim() : lines[i]);
+ if(lines[i].equals(lines[i].trim()) && lines[i].trim().endsWith("{")) {
+ spaces = new char[spaces.length + 1];
+ Arrays.fill(spaces, '\t');
+ }
}
return result.toString();
}
@@ -226,32 +269,31 @@
public String getClassBody(String lineSeparator) {
- StringBuffer result = new StringBuffer();
+ StringBuffer result = new StringBuffer("\t");
if (classType != INTERFACE && fields.size() > 0) {
java.util.Collections.sort(fields); // sort fields
for (JavaField field : fields) {
- result.append(addIndentation(field.toString(lineSeparator), 4, lineSeparator));
- result.append(lineSeparator);
+ result.append(field.toString(lineSeparator));
}
result.append(lineSeparator);
}
if (rawBodyCode.length() > 0) {
- result.append(addIndentation("/* begin raw body code */\n", 4, lineSeparator));
+ result.append("/* begin raw body code */\n");
String s = rawBodyCode.toString();
if (!s.startsWith(lineSeparator)) {
result.append(lineSeparator);
}
- result.append(addIndentation(s, 4, lineSeparator));
+ result.append(s);
result.append(lineSeparator);
- result.append(addIndentation("/* end raw body code */", 4, lineSeparator));
- result.append(lineSeparator);
+ result.append("/* end raw body code */");
+ result.append(lineSeparator).append(lineSeparator);
}
for (JavaFile innerClass : innerClasses) {
- result.append(addIndentation(innerClass.toString(), 4, lineSeparator));
+ result.append(innerClass.toString());
result.append(lineSeparator).append(lineSeparator);
}
@@ -263,7 +305,11 @@
}
map.clear();
- return result.toString();
+ Pattern p = Pattern.compile("\\n");
+ //System.out.println(result.toString());
+ Matcher m = p.matcher(result.toString());
+ return m.replaceAll("\n\t");
+
}
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileGenerator.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileGenerator.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileGenerator.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -98,7 +98,7 @@
* Fills and saves the generated file
* @param out the file to record
*/
- protected void saveFile(File out) {
+ public void saveFile(File out) {
FileWriter fw = null;
try {
fw = new FileWriter(out);
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaMethod.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaMethod.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaMethod.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -27,6 +27,8 @@
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* Represents a method in a Java source file being generated for output. <code>JavaMethods</code> are created
@@ -240,7 +242,7 @@
if (bodyCode != null) {
result.append(" {");
result.append(lineSeparator);
- String formattedBodyCode = JavaFile.addIndentation(bodyCode.toString().trim(), 4, lineSeparator);
+ String formattedBodyCode = JavaFile.addIndentation(bodyCode.toString().trim(), lineSeparator);
if (formattedBodyCode.length() > 0) {
result.append(formattedBodyCode);
result.append(lineSeparator);
@@ -408,10 +410,10 @@
if (methods.isEmpty()) {
return;
}
- buffer.append(JavaFile.addIndentation(header, 4, lineSeparator));
+ buffer.append(header);
buffer.append(lineSeparator).append(lineSeparator);
for (JavaMethod method : methods) {
- buffer.append(JavaFile.addIndentation(method.toString(lineSeparator), 4, lineSeparator));
+ buffer.append(method.toString(lineSeparator));
buffer.append(lineSeparator).append(lineSeparator);
}
}
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -18,6 +18,7 @@
*/
package org.nuiton.guix.model;
+import org.nuiton.guix.tags.TagHandler;
/**
* Descriptor of a class found in the guix files.
@@ -94,5 +95,3 @@
}
}
-
-//~ Formatted by Jindent --- http://www.jindent.com
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/SimpleNode.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/SimpleNode.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/SimpleNode.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -10,7 +10,7 @@
protected Node[] children;
public Token firstToken;
protected int id;
- private ClassDescriptor javaType;
+ private Class javaType;
public Token lastToken;
protected Node parent;
protected JavaParser parser;
@@ -44,11 +44,11 @@
return (SimpleNode) parent;
}
- public ClassDescriptor getJavaType() {
+ public Class getJavaType() {
return javaType;
}
- public void setJavaType(ClassDescriptor javaType) {
+ public void setJavaType(Class javaType) {
this.javaType = javaType;
}
Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ApplicationHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ApplicationHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ApplicationHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -1,20 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.nuiton.guix.tags;
-
-/**
- *
- * @author kevin
- */
-public abstract class ApplicationHandler extends DefaultTagHandler {
-
- /**
- * Constructor
- */
- public ApplicationHandler() {
-
- }
-}
Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ButtonHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ButtonHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ButtonHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -1,20 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.nuiton.guix.tags;
-
-/**
- *
- * @author kevin
- */
-public abstract class ButtonHandler extends DefaultTagHandler {
-
- /**
- * Constructor
- */
- public ButtonHandler() {
-
- }
-}
Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/CellHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/CellHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/CellHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -1,173 +0,0 @@
-/**
- * *##% guix-compiler-swing
- * Copyright (C) 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
- */
-package org.nuiton.guix.tags;
-
-import org.nuiton.guix.model.AttributeDescriptor;
-import org.nuiton.guix.model.GuixModelObject;
-
-/**
- * Represents a cell of a table
- *
- * @author kevin
- */
-public abstract class CellHandler extends TableHandler {
-
- /** id of the object contained by the cell */
- private String id = null;
- /** number of columns of the cell */
- private int columns = 1;
- /** number of rows of the cell */
- private int rows = 1;
- /** index of the row */
- private int row = -1;
- /** index of the column */
- private int column = -1;
-
- /**
- * Constructor
- */
- public CellHandler() {
-
- }
-
- /**
- * Constructor
- *
- * @param cell the GuixModelObject which represents the cell
- */
- public CellHandler(GuixModelObject cell) {
- assert cell.getChildren().size() == 1;
- id = cell.getChildren().get(0).getId();
- for (AttributeDescriptor attr : cell.getAttributeDescriptors()) {
- if (attr.getName().equals("columns")) {
- columns = Integer.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("column")) {
- column = Integer.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("rows")) {
- rows = Integer.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("weightx")) {
- weightx = Double.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("weighty")) {
- weighty = Double.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("ipadx")) {
- ipadx = Integer.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("ipady")) {
- ipady = Integer.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("halign")) {
- horizontalAlignment = getHalign(attr.getValue());
- }
- else if (attr.getName().equals("valign")) {
- verticalAlignment = getValign(attr.getValue());
- }
- else if (attr.getName().equals("fill")) {
- fill = attr.getValue();
- }
- else if (attr.getName().equals("insets")) {
- insets = attr.getValue();
- }
- }
- }
-
- /**
- * Constructor
- *
- * @param cell the GuixModelObject which represents the cell
- * @param row the row which contains the cell
- */
- public CellHandler(GuixModelObject cell, RowHandler row) {
- this(cell);
- //if the attributes that the row contains too have not been defined by the user within the cell,
- //but have been defined in the row (or the table), set them
- if (horizontalAlignment == null) {
- horizontalAlignment = row.getHorizontalAlignment() == null ? TableHandler.DEFAULT_HORIZONTAL_ALIGNMENT : row.getHorizontalAlignment();
- }
- if (verticalAlignment == null) {
- verticalAlignment = row.getVerticalAlignment() == null ? TableHandler.DEFAULT_VERTICAL_ALIGNMENT : row.getVerticalAlignment();
- }
- if (fill == null) {
- fill = row.getFill() == null ? TableHandler.DEFAULT_FILL : row.getFill();
- }
- if (insets == null) {
- insets = row.getInsets() == null ? TableHandler.DEFAULT_INSETS : row.getInsets();
- }
- if (ipadx == null) {
- ipadx = row.getIpadx() == null ? TableHandler.DEFAULT_IPADX : row.getIpadx();
- }
- if (ipady == null) {
- ipady = row.getIpady() == null ? TableHandler.DEFAULT_IPADY : row.getIpady();
- }
- if (weightx == null) {
- weightx = row.getWeightx() == null ? TableHandler.DEFAULT_WEIGHTX : row.getWeightx();
- }
- if (weighty == null) {
- weighty = row.getWeighty() == null ? TableHandler.DEFAULT_WEIGHTY : row.getWeighty();
- }
- if(this.row == -1) {
- this.row = row.getRow() < 0 ? -1 : row.getRow();
- }
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public int getColumn() {
- return column;
- }
-
- public void setColumn(int column) {
- this.column = column;
- }
-
- public int getColumns() {
- return columns;
- }
-
- public void setColumns(int columns) {
- this.columns = columns;
- }
-
- public int getRow() {
- return row;
- }
-
- public void setRow(int row) {
- this.row = row;
- }
-
- public int getRows() {
- return rows;
- }
-
- public void setRows(int rows) {
- this.rows = rows;
- }
-
-}
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/DefaultTagHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/DefaultTagHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/DefaultTagHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -4,6 +4,18 @@
*/
package org.nuiton.guix.tags;
+import java.beans.BeanInfo;
+import java.beans.EventSetDescriptor;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.MethodDescriptor;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+import org.nuiton.guix.UnsupportedAttributeException;
/**
*
@@ -11,4 +23,248 @@
*/
public abstract class DefaultTagHandler implements TagHandler {
+ protected Map<String,String> attrMap = new HashMap<String,String>();
+
+ /** Maps property names to their respective ProxyEventInfos. */
+ private Map<String, ProxyEventInfo> eventInfos;
+
+ /** The JAXXBeanInfo for the beanClass. */
+ protected BeanInfo beanInfo;
+
+ /** Maps property names to their respective JAXXPropertyDescriptors. */
+ private Map<String, PropertyDescriptor> properties;
+
+ /** Maps event names to their respective JAXXEventSetDescriptors. */
+ private Map<String, EventSetDescriptor> events;
+
+ /**
+ * Encapsulates information about a "proxy event handler", which is an event handler that
+ * fires PropertyChangeEvents when it is triggered. ProxyEventInfos simplify the data binding
+ * system by allowing all dependencies to fire the same kind of event even if they would
+ * normally throw something else, like <code>DocumentEvent</code>.
+ */
+ private class ProxyEventInfo {
+ /** The name of the method or field being proxied, e.g. "getText". */
+ String memberName;
+
+ /** The "actual" event listener for the property in question, e.g. DocumentListener. */
+ Class listenerClass;
+
+ /**
+ * In cases where a different object (such as a model) is more directly responsible for
+ * managing the property, this is the name of the property where that object can be
+ * found, e.g. "document" (which is turned into a call to "getDocument()"). This property
+ * is also treated as a dependency of the data binding expression, and any updates to it
+ * (assuming it is bound) will cause the listener to be removed from the old value and
+ * attached to the new value, and the data binding to be processed.
+ */
+ String modelName;
+
+ /** The name of the method used to add the "native" event listener, e.g. "addDocumentListener". */
+ String addMethod;
+
+ /** The name of the method used to remove the "native" event listener, e.g. "removeDocumentListener". */
+ String removeMethod;
+ }
+
+ /**
+ * Performs introspection on the beanClass and stores the results.
+ *
+ * @throws java.beans.IntrospectionException
+ * TODO
+ */
+ protected void init() throws IntrospectionException {
+ if (beanInfo == null) {
+ // perform introspection & cache the results
+ beanInfo = Introspector.getBeanInfo(getClassToGenerate());
+
+ PropertyDescriptor[] propertiesArray = beanInfo.getPropertyDescriptors();
+ properties = new HashMap<String, PropertyDescriptor>();
+ for (int i = propertiesArray.length - 1; i >= 0; i--) {
+ properties.put(propertiesArray[i].getName(), propertiesArray[i]);
+ }
+
+ EventSetDescriptor[] eventsArray = beanInfo.getEventSetDescriptors();
+ events = new HashMap<String, EventSetDescriptor>();
+ for (int i = eventsArray.length - 1; i >= 0; i--) {
+ Method[] methods = eventsArray[i].getListenerMethods();
+ for (Method method : methods) {
+ events.put(method.getName(), eventsArray[i]);
+ }
+ }
+
+ configureProxyEventInfo();
+ }
+ }
+
+ /**
+ * Configures the event handling for members which do not fire <code>PropertyChangeEvent</code> when
+ * modified. The default implementation does nothing. Subclasses should override this method to call
+ * <code>addProxyEventInfo</code> for each member which requires special handling.
+ */
+ protected void configureProxyEventInfo() {
+
+ }
+
+
+ /**
+ * Configures a proxy event handler which fires <code>PropertyChangeEvents</code> when a non-bound
+ * member is updated. This is necessary for all fields (which cannot be bound) and for methods that are
+ * not bound property <code>get</code> methods. The proxy event handler will attach the specified kind
+ * of listener to the class and fire a <code>PropertyChangeEvent</code> whenever the listener receives
+ * any kind of event.
+ * <p/>
+ * Even though this method can theoretically be applied to fields (in addition to methods), it would be an
+ * unusual situation in which that would actually work -- as fields cannot fire events when modified, it would
+ * be difficult to have a listener that was always notified when a field value changed.
+ *
+ * @param memberName the name of the field or method being proxied
+ * @param listenerClass the type of listener which receives events when the field or method is updated
+ */
+ public void addProxyEventInfo(String memberName, Class listenerClass) {
+ addProxyEventInfo(memberName, listenerClass, null);
+ }
+
+
+ /**
+ * Configures a proxy event handler which fires <code>PropertyChangeEvents</code> when a non-bound
+ * member is updated. This is necessary for all fields (which cannot be bound) and for methods that are
+ * not bound property <code>get</code> methods. This variant attaches a listener to a property of the
+ * object (such as <code>model</code>) and not the object itself, which is useful when there is a model
+ * that is the "real" container of the information. The proxy event handler will attach the specified kind
+ * of listener to the property's value (retrieved using the property's <code>get</code> method) and fire
+ * a <code>PropertyChangeEvent</code> whenever the listener receives any kind of event.
+ * <p/>
+ * If the property is itself bound (typically the case with models), any updates to the property's value will
+ * cause the listener to be removed from the old property value and reattached to the new property value,
+ * as well as cause a <code>PropertyChangeEvent</code> to be fired.
+ * <p/>
+ * Even though this method can theoretically be applied to fields (in addition to methods), it would be an
+ * unusual situation in which that would actually work -- as fields cannot fire events when modified, it would
+ * be difficult to have a listener that was always notified when a field value changed.
+ *
+ * @param memberName the name of the field or method being proxied
+ * @param listenerClass the type of listener which receives events when the field or method is updated
+ * @param modelName the JavaBeans-style name of the model property
+ */
+ public void addProxyEventInfo(String memberName, Class listenerClass, String modelName) {
+ String listenerName = listenerClass.getName();
+ listenerName = listenerName.substring(listenerName.lastIndexOf(".") + 1);
+ addProxyEventInfo(memberName, listenerClass, modelName, "add" + listenerName, "remove" + listenerName);
+ }
+
+ /**
+ * Configures a proxy event handler which fires <code>PropertyChangeEvents</code> when a non-bound
+ * member is updated. This is necessary for all fields (which cannot be bound) and for methods that are
+ * not bound property <code>get</code> methods. This variant attaches a listener to a property of the
+ * object (such as <code>model</code>) and not the object itself, which is useful when there is a model
+ * that is the "real" container of the information. The proxy event handler will attach the specified kind
+ * of listener to the property's value (retrieved using the property's <code>get</code> method) and fire
+ * a <code>PropertyChangeEvent</code> whenever the listener receives any kind of event.
+ * <p/>
+ * If the property is itself bound (typically the case with models), any updates to the property's value will
+ * cause the listener to be removed from the old property value and reattached to the new property value,
+ * as well as cause a <code>PropertyChangeEvent</code> to be fired.
+ * <p/>
+ * This variant of <code>addProxyEventInfo</code> allows the names of the methods that add and remove
+ * the event listener to be specified, in cases where the names are not simply <code>add<listenerClassName></code>
+ * and <code>remove<listenerClassName></code>.
+ * <p/>
+ * Even though this method can theoretically be applied to fields (in addition to methods), it would be an
+ * unusual situation in which that would actually work -- as fields cannot fire events when modified, it would
+ * be difficult to have a listener that was always notified when a field value changed.
+ *
+ * @param memberName the name of the field or method being proxied
+ * @param listenerClass the type of listener which receives events when the field or method is updated
+ * @param modelName the JavaBeans-style name of the model property
+ * @param addMethod add method name
+ * @param removeMethod remove method name
+ */
+ public void addProxyEventInfo(String memberName, Class listenerClass,
+ String modelName, String addMethod, String removeMethod) {
+ ProxyEventInfo info = new ProxyEventInfo();
+ info.memberName = memberName;
+ info.listenerClass = listenerClass;
+ info.modelName = modelName;
+ info.addMethod = addMethod;
+ info.removeMethod = removeMethod;
+ if (eventInfos == null) {
+ eventInfos = new HashMap<String, ProxyEventInfo>();
+ }
+ eventInfos.put(memberName, info);
+ }
+
+ @Override
+ public boolean hasEventInfosAboutMethod(String methodName) {
+ return eventInfos != null && eventInfos.get(methodName) != null;
+ }
+
+ @Override
+ public Class getEventInfosListenerClass(String methodName) {
+ return eventInfos.get(methodName) != null ? eventInfos.get(methodName).listenerClass : null;
+ }
+
+ @Override
+ public String getEventInfosAddListenerMethodName(String methodName) {
+ return eventInfos.get(methodName) != null ? eventInfos.get(methodName).addMethod : null;
+ }
+
+ @Override
+ public String getEventInfosRemoveListenerMethodName(String methodName) {
+ return eventInfos.get(methodName) != null ? eventInfos.get(methodName).removeMethod : null;
+ }
+
+ @Override
+ public String getEventInfosModelName(String methodName) {
+ return eventInfos.get(methodName) != null ? eventInfos.get(methodName).modelName : null;
+ }
+
+ @Override
+ public String getAttrToGenerate(String attr) {
+ return attrMap.get(attr);
+ }
+
+ /**
+ * @param name ?
+ * @return <code>true</code> if the named member is <i>bound</i> (fires <code>PropertyChangeEvent</code>
+ * when modified). Members are either fields (represented by the simple name of the field) or <code>get/is</code>
+ * methods (represented by the simple name of the method, <b>not</b> the simplified JavaBeans-style name).
+ * Methods which are not actually bound in their native class, but for which proxy events have been
+ * configured (such as <code>JTextField.getText</code>, return <code>true</code>.
+ * @throws jaxx.UnsupportedAttributeException
+ * ?
+ */
+ @Override
+ public boolean isMemberBound(String member) throws UnsupportedAttributeException {
+ try {
+ init();
+ } catch (IntrospectionException e) {
+ throw new RuntimeException(e);
+ }
+
+ if (eventInfos != null && eventInfos.containsKey(member)) {
+ return true;
+ }
+
+ if (member.equals("getClass")) {
+ return false;
+ }
+
+ String propertyName = null;
+ if (member.startsWith("get")) {
+ propertyName = Introspector.decapitalize(member.substring("get".length()));
+ } else if (member.startsWith("is")) {
+ propertyName = Introspector.decapitalize(member.substring("is".length()));
+ }
+ PropertyDescriptor property = propertyName != null ? properties.get(propertyName) : null;
+ if (property != null) {
+ return property.isBound();
+ }
+ try {
+ Field field = getClassToGenerate().getField(member);
+ return Modifier.isFinal(field.getModifiers()); // final fields might as well be considered bound -- they can't be modified anyway
+ } catch (NoSuchFieldException e) {
+ throw new UnsupportedAttributeException("cannot find property '" + member + "' of " + getClassToGenerate());
+ }
+ }
}
Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/LabelHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/LabelHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/LabelHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -1,21 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.nuiton.guix.tags;
-
-/**
- *
- * @author kevin
- */
-public abstract class LabelHandler extends DefaultTagHandler {
-
- /**
- * Constructor
- */
- public LabelHandler() {
-
- }
-
-}
Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuBarHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuBarHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuBarHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -1,21 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.nuiton.guix.tags;
-
-/**
- *
- * @author kevin
- */
-public abstract class MenuBarHandler extends DefaultTagHandler {
-
- /**
- * Constructor
- */
- public MenuBarHandler() {
-
- }
-
-}
Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -1,21 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.nuiton.guix.tags;
-
-/**
- *
- * @author kevin
- */
-public abstract class MenuHandler extends DefaultTagHandler {
-
- /**
- * Constructor
- */
- public MenuHandler() {
-
- }
-
-}
Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuItemHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuItemHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuItemHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -1,21 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.nuiton.guix.tags;
-
-/**
- *
- * @author kevin
- */
-public abstract class MenuItemHandler extends DefaultTagHandler {
-
- /**
- * Constructor
- */
- public MenuItemHandler() {
-
- }
-
-}
Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/PanelHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/PanelHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/PanelHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -1,20 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.nuiton.guix.tags;
-
-/**
- *
- * @author kevin
- */
-public abstract class PanelHandler extends DefaultTagHandler {
-
- /**
- * Constructor
- */
- public PanelHandler() {
-
- }
-}
Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/RowHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/RowHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/RowHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -1,122 +0,0 @@
-/**
- * *##% guix-compiler-swing
- * Copyright (C) 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
- */
-package org.nuiton.guix.tags;
-
-import org.nuiton.guix.model.AttributeDescriptor;
-import org.nuiton.guix.model.GuixModelObject;
-
-/**
- * Represents a row of a table
- *
- * @author kevin
- */
-public abstract class RowHandler extends TableHandler {
-
- /** index of the row */
- private int row = -1;
-
- /**
- * Constructor
- */
- public RowHandler() {
-
- }
-
- /**
- * Constructor
- *
- * @param row the GuixModelObject which represents the row
- */
- public RowHandler(GuixModelObject row) {
- for (AttributeDescriptor attr : row.getAttributeDescriptors()) {
- if (attr.getName().equals("row")) {
- this.row = Integer.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("weightx")) {
- weightx = Double.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("weighty")) {
- weighty = Double.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("ipadx")) {
- ipadx = Integer.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("ipady")) {
- ipady = Integer.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("halign")) {
- horizontalAlignment = getHalign(attr.getValue());
- }
- else if (attr.getName().equals("valign")) {
- verticalAlignment = getValign(attr.getValue());
- }
- else if (attr.getName().equals("fill")) {
- fill = attr.getValue();
- }
- else if (attr.getName().equals("insets")) {
- insets = attr.getValue();
- }
- }
- }
-
- /**
- * Constructor
- *
- * @param row the GuixModelObject which represents the row
- * @param table the table which contains the row
- */
- public RowHandler(GuixModelObject row, TableHandler table) {
- this(row);
- //if the attributes that the table contains too have not been defined by the user within the row,
- //but have been defined in the table, set them
- if (horizontalAlignment == null) {
- horizontalAlignment = table.getHorizontalAlignment() == null ? TableHandler.DEFAULT_HORIZONTAL_ALIGNMENT : table.getHorizontalAlignment();
- }
- if (verticalAlignment == null) {
- verticalAlignment = table.getVerticalAlignment() == null ? TableHandler.DEFAULT_VERTICAL_ALIGNMENT : table.getVerticalAlignment();
- }
- if (fill == null) {
- fill = table.getFill() == null ? TableHandler.DEFAULT_FILL : table.getFill();
- }
- if (insets == null) {
- insets = table.getInsets() == null ? TableHandler.DEFAULT_INSETS : table.getInsets();
- }
- if (ipadx == null) {
- ipadx = table.getIpadx() == null ? TableHandler.DEFAULT_IPADX : table.getIpadx();
- }
- if (ipady == null) {
- ipady = table.getIpady() == null ? TableHandler.DEFAULT_IPADY : table.getIpady();
- }
- if (weightx == null) {
- weightx = table.getWeightx() == null ? TableHandler.DEFAULT_WEIGHTX : table.getWeightx();
- }
- if (weighty == null) {
- weighty = table.getWeighty() == null ? TableHandler.DEFAULT_WEIGHTY : table.getWeighty();
- }
- }
-
- public int getRow() {
- return row;
- }
-
- public void setRow(int row) {
- this.row = row;
- }
-
-}
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -90,6 +90,7 @@
* with the same name as the class
*/
public StyleSheet autoDetectStyleFile(File styleFile) throws IOException {
+ selectors = new ArrayList<Selector>();
return processStylesheet(loadStyleFile(styleFile));
}
@@ -109,6 +110,7 @@
public StyleSheet compileStyle(XmlPullParser xpp, File styleFile) throws IOException, XmlPullParserException {
StyleSheet result = null;
StringBuffer style = new StringBuffer();
+ selectors = new ArrayList<Selector>();
if ((styleFile != null) && styleFile.exists()) {
style.append(loadStyleFile(styleFile));
@@ -150,7 +152,6 @@
* which rules will be applied to
*/
protected Selector processSelector(SimpleNode selector) {
-
// chack if it is a selector
if (selector.getId() != CSSParserTreeConstants.JJTSELECTOR) {
throw new IllegalArgumentException("argument node is not a Selector");
Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TabPanelHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TabPanelHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TabPanelHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -1,20 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.nuiton.guix.tags;
-
-/**
- *
- * @author kevin
- */
-public abstract class TabPanelHandler extends DefaultTagHandler {
-
- /**
- * Constructor
- */
- public TabPanelHandler() {
-
- }
-}
Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TableHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TableHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TableHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -1,202 +0,0 @@
-/**
- * *##% guix-compiler-swing
- * Copyright (C) 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
- */
-package org.nuiton.guix.tags;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.guix.model.AttributeDescriptor;
-import org.nuiton.guix.model.GuixModelObject;
-
-/**
- * Represents a table
- *
- * @author kevin
- */
-public abstract class TableHandler extends DefaultTagHandler {
-
- private static Log log = LogFactory.getLog(TableHandler.class);
-
- protected enum VerticalAlignment {
-
- ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM
- }
- protected enum HorizontalAlignment {
-
- ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_DEFAULT
- }
- public static final String DEFAULT_INSETS = "3, 3, 3, 3";
- public static final HorizontalAlignment DEFAULT_HORIZONTAL_ALIGNMENT = HorizontalAlignment.ALIGN_DEFAULT;
- public static final VerticalAlignment DEFAULT_VERTICAL_ALIGNMENT = VerticalAlignment.ALIGN_TOP;
- public static final String DEFAULT_FILL = "java.awt.GridBagConstraints.BOTH";
- public static final Integer DEFAULT_IPADX = 1;
- public static final Integer DEFAULT_IPADY = 1;
- public static final Double DEFAULT_WEIGHTX = 0.0;
- public static final Double DEFAULT_WEIGHTY = 0.0;
- protected Double weightx = null;
- protected Double weighty = null;
- protected Integer ipadx = null;
- protected Integer ipady = null;
- protected HorizontalAlignment horizontalAlignment = null;
- protected VerticalAlignment verticalAlignment = null;
- protected String fill = null;
- protected String insets = null;
-
- /**
- * Constructor
- */
- public TableHandler() {
- }
-
- /**
- * Constructor
- *
- * @param table the GuixModelObject which represents the table
- */
- public TableHandler(GuixModelObject table) {
-
- for (AttributeDescriptor attr : table.getAttributeDescriptors()) {
- if (attr.getName().equals("weightx")) {
- weightx = Double.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("weighty")) {
- weighty = Double.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("ipadx")) {
- ipadx = Integer.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("ipady")) {
- ipady = Integer.valueOf(attr.getValue());
- }
- else if (attr.getName().equals("halign")) {
- horizontalAlignment = getHalign(attr.getValue());
- if (horizontalAlignment == null) {
- if (log.isErrorEnabled()) {
- log.error(table.getId() + "'s halign attribute has a wrong value : " + attr.getValue());
- }
- horizontalAlignment = HorizontalAlignment.ALIGN_DEFAULT;
- }
- }
- else if (attr.getName().equals("valign")) {
- verticalAlignment = getValign(attr.getValue());
- if (verticalAlignment == null) {
- if (log.isErrorEnabled()) {
- log.error(table.getId() + "'s halign attribute has a wrong value : " + attr.getValue());
- }
- verticalAlignment = VerticalAlignment.ALIGN_TOP;
- }
- }
- else if (attr.getName().equals("fill")) {
- fill = attr.getValue();
- }
- else if (attr.getName().equals("insets")) {
- insets = attr.getValue();
- }
- }
- }
-
- public HorizontalAlignment getHorizontalAlignment() {
- return horizontalAlignment;
- }
-
- public void setHorizontalAlignment(HorizontalAlignment horizontalAlignment) {
- this.horizontalAlignment = horizontalAlignment;
- }
-
- public VerticalAlignment getVerticalAlignment() {
- return verticalAlignment;
- }
-
- public void setVerticalAlignment(VerticalAlignment verticalAlignment) {
- this.verticalAlignment = verticalAlignment;
- }
-
- public String getFill() {
- return fill;
- }
-
- public void setFill(String fill) {
- this.fill = fill;
- }
-
- public String getInsets() {
- return insets;
- }
-
- public void setInsets(String insets) {
- this.insets = insets;
- }
-
- public Integer getIpadx() {
- return ipadx;
- }
-
- public void setIpadx(Integer ipadx) {
- this.ipadx = ipadx;
- }
-
- public Integer getIpady() {
- return ipady;
- }
-
- public void setIpady(Integer ipady) {
- this.ipady = ipady;
- }
-
- public Double getWeightx() {
- return weightx;
- }
-
- public void setWeightx(Double weightx) {
- this.weightx = weightx;
- }
-
- public Double getWeighty() {
- return weighty;
- }
-
- public void setWeighty(Double weighty) {
- this.weighty = weighty;
- }
-
- public HorizontalAlignment getHalign(String halign) {
- if (halign.equalsIgnoreCase("left")) {
- return HorizontalAlignment.ALIGN_LEFT;
- }
- if (halign.equalsIgnoreCase("right")) {
- return HorizontalAlignment.ALIGN_RIGHT;
- }
- if (halign.equalsIgnoreCase("center")) {
- return HorizontalAlignment.ALIGN_CENTER;
- }
- return null;
- }
-
- public VerticalAlignment getValign(String valign) {
- if (valign.equalsIgnoreCase("top")) {
- return VerticalAlignment.ALIGN_TOP;
- }
- if (valign.equalsIgnoreCase("bottom")) {
- return VerticalAlignment.ALIGN_BOTTOM;
- }
- if (valign.equalsIgnoreCase("middle")) {
- return VerticalAlignment.ALIGN_MIDDLE;
- }
- return null;
- }
-}
Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -12,4 +12,18 @@
public interface TagHandler {
public Class getClassToGenerate();
+
+ public String getAttrToGenerate(String attr);
+
+ public boolean hasEventInfosAboutMethod(String methodName);
+
+ public Class getEventInfosListenerClass(String methodName);
+
+ public String getEventInfosAddListenerMethodName(String methodName);
+
+ public String getEventInfosRemoveListenerMethodName(String methodName);
+
+ public String getEventInfosModelName(String methodName);
+
+ public boolean isMemberBound(String member);
}
Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TextFieldHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TextFieldHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TextFieldHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -1,21 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.nuiton.guix.tags;
-
-/**
- *
- * @author kevin
- */
-public abstract class TextFieldHandler extends DefaultTagHandler {
-
- /**
- * Constructor
- */
- public TextFieldHandler() {
-
- }
-
-}
Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ToggleButtonHandler.java
===================================================================
--- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ToggleButtonHandler.java 2009-07-22 13:03:32 UTC (rev 1499)
+++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ToggleButtonHandler.java 2009-07-22 13:06:26 UTC (rev 1500)
@@ -1,20 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.nuiton.guix.tags;
-
-/**
- *
- * @author kevin
- */
-public abstract class ToggleButtonHandler extends DefaultTagHandler {
-
- /**
- * Constructor
- */
- public ToggleButtonHandler() {
-
- }
-}
1
0
Author: kmorin
Date: 2009-07-22 15:03:32 +0200 (Wed, 22 Jul 2009)
New Revision: 1499
Modified:
trunk/pom.xml
Log:
Add the runtime modules (probably unuseful but in case)
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-06-26 14:33:53 UTC (rev 1498)
+++ trunk/pom.xml 2009-07-22 13:03:32 UTC (rev 1499)
@@ -18,11 +18,12 @@
<modules>
<module>guix-compiler</module>
<module>guix-compiler-swing</module>
- <module>guix-runtime</module>
+ <module>guix-compiler-gwt</module>
+ <module>guix-runtime-swing</module>
+ <module>guix-runtime-gwt</module>
<module>maven-guix-plugin</module>
<module>guix-test-swing</module>
- <module>guix-test-gwt</module>
- <module>guix-compiler-gwt</module>
+ <module>guix-test-gwt</module>
</modules>
1
0
Author: sletellier
Date: 2009-07-15 15:13:01 +0200 (Wed, 15 Jul 2009)
New Revision: 1508
Added:
tags/jaxx-1.5.1/
Log:
Adding tag jaxx-1.5.1
Property changes on: tags/jaxx-1.5.1
___________________________________________________________________
Added: svn:ignore
+ *.ipr
*.iws
*.iml
target
catalog.xml
*.log
Added: svn:mergeinfo
+
1
0