r1575 - in trunk/guix-compiler-gwt: . src/main/java/org/nuiton/guix src/main/java/org/nuiton/guix/generator src/main/java/org/nuiton/guix/tags/gwt src/test/java/org/nuiton/guix/generator
Author: kmorin Date: 2009-08-25 12:50:11 +0200 (Tue, 25 Aug 2009) New Revision: 1575 Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/CheckBoxHandler.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ComboBoxHandler.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/DialogBoxHandler.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/HorizontalSplitPanelHandler.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ListHandler.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/PasswordFieldHandler.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ProgressBarHandler.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/RadioButtonHandler.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ScrollPanelHandler.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TabHandler.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TextAreaHandler.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TreeHandler.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TreeNodeHandler.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/VerticalSplitPanelHandler.java Removed: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtConfigGenerator.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator1.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtHtmlGenerator.java Modified: trunk/guix-compiler-gwt/pom.xml trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/GwtEventHandler.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/GwtGuixInitializer.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/GwtImplementationGenerator.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtInterfaceGenerator.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtJavaFileGenerator.java trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TextFieldHandler.java trunk/guix-compiler-gwt/src/test/java/org/nuiton/guix/generator/GwtGeneratorTest.java Log: Removed unused classes Imporved the binding Add Handlers Modified: trunk/guix-compiler-gwt/pom.xml =================================================================== --- trunk/guix-compiler-gwt/pom.xml 2009-08-25 10:49:26 UTC (rev 1574) +++ trunk/guix-compiler-gwt/pom.xml 2009-08-25 10:50:11 UTC (rev 1575) @@ -56,6 +56,12 @@ </dependency> <dependency> + <groupId>net.sf.gwt-widget</groupId> + <artifactId>gwt-widgets</artifactId> + <version>0.2.0</version> + </dependency> + + <dependency> <groupId>xpp3</groupId> <artifactId>xpp3</artifactId> </dependency> Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/GwtEventHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/GwtEventHandler.java 2009-08-25 10:49:26 UTC (rev 1574) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/GwtEventHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -119,12 +119,13 @@ .append("(new ") .append(e.getListenerType().getCanonicalName()) //if only one event is handled for this EventSetDescriptor then add a listener, else add an adapter - .append(e.getAddListenerMethod().getParameterTypes()[0].getMethods().length == 1 ? "" : "Adapter") + .append(e.getAddListenerMethod().getParameterTypes()[0].getMethods().length == map.get(e).keySet().size() ? "" : "Adapter") .append("() {\n"); //for every event handled for the EventSetDescriptor for(Method m : map.get(e).keySet()) { - for(Annotation a : m.getDeclaredAnnotations()) + for(Annotation a : m.getDeclaredAnnotations()) { result.append(a.toString()).append("\n"); + } //add the method that handles the event result.append("public ") .append(m.getReturnType().getCanonicalName()) Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/GwtGuixInitializer.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/GwtGuixInitializer.java 2009-08-25 10:49:26 UTC (rev 1574) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/GwtGuixInitializer.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -28,13 +28,27 @@ import org.nuiton.guix.tags.gwt.TableHandler; import org.nuiton.guix.tags.TagManager; import org.nuiton.guix.tags.gwt.ButtonHandler; +import org.nuiton.guix.tags.gwt.CheckBoxHandler; +import org.nuiton.guix.tags.gwt.ComboBoxHandler; +import org.nuiton.guix.tags.gwt.DialogBoxHandler; +import org.nuiton.guix.tags.gwt.HorizontalSplitPanelHandler; import org.nuiton.guix.tags.gwt.LabelHandler; +import org.nuiton.guix.tags.gwt.ListHandler; 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.PasswordFieldHandler; +import org.nuiton.guix.tags.gwt.ProgressBarHandler; +import org.nuiton.guix.tags.gwt.RadioButtonHandler; +import org.nuiton.guix.tags.gwt.ScrollPanelHandler; +import org.nuiton.guix.tags.gwt.TabHandler; import org.nuiton.guix.tags.gwt.TabPanelHandler; +import org.nuiton.guix.tags.gwt.TextAreaHandler; import org.nuiton.guix.tags.gwt.TextFieldHandler; import org.nuiton.guix.tags.gwt.ToggleButtonHandler; +import org.nuiton.guix.tags.gwt.TreeHandler; +import org.nuiton.guix.tags.gwt.TreeNodeHandler; +import org.nuiton.guix.tags.gwt.VerticalSplitPanelHandler; /** * Initialize the application @@ -48,11 +62,25 @@ TagManager.registerGuixClassHandler("Row", RowHandler.class); TagManager.registerGuixClassHandler("Cell", CellHandler.class); TagManager.registerGuixClassHandler("Panel", PanelHandler.class); + TagManager.registerGuixClassHandler("DialogBox", DialogBoxHandler.class); + TagManager.registerGuixClassHandler("ScrollPanel", ScrollPanelHandler.class); + TagManager.registerGuixClassHandler("HorizontalSplitPanel", HorizontalSplitPanelHandler.class); + TagManager.registerGuixClassHandler("VerticalSplitPanel", VerticalSplitPanelHandler.class); TagManager.registerGuixClassHandler("Button", ButtonHandler.class); TagManager.registerGuixClassHandler("TextField", TextFieldHandler.class); + TagManager.registerGuixClassHandler("TextArea", TextAreaHandler.class); TagManager.registerGuixClassHandler("Label", LabelHandler.class); TagManager.registerGuixClassHandler("ToggleButton", ToggleButtonHandler.class); + TagManager.registerGuixClassHandler("CheckBox", CheckBoxHandler.class); + TagManager.registerGuixClassHandler("ComboBox", ComboBoxHandler.class); + TagManager.registerGuixClassHandler("PasswordField", PasswordFieldHandler.class); + TagManager.registerGuixClassHandler("ProgressBar", ProgressBarHandler.class); + TagManager.registerGuixClassHandler("RadioButton", RadioButtonHandler.class); TagManager.registerGuixClassHandler("TabPanel", TabPanelHandler.class); + TagManager.registerGuixClassHandler("Tab", TabHandler.class); + TagManager.registerGuixClassHandler("Tree", TreeHandler.class); + TagManager.registerGuixClassHandler("TreeNode", TreeNodeHandler.class); + TagManager.registerGuixClassHandler("List", ListHandler.class); TagManager.registerGuixClassHandler("MenuBar", MenuBarHandler.class); TagManager.registerGuixClassHandler("Menu", MenuHandler.class); TagManager.registerGuixClassHandler("MenuItem", MenuItemHandler.class); 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-08-25 10:49:26 UTC (rev 1574) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtAbstractClassGenerator.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -34,7 +34,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.nuiton.guix.databinding.BindingUtils; +import org.nuiton.guix.BindingUtils; import org.nuiton.guix.GwtEventHandler; import org.nuiton.guix.model.AttributeDescriptor; import org.nuiton.guix.model.StyleSheet; @@ -56,6 +56,9 @@ */ public class GwtAbstractClassGenerator extends GwtJavaFileGenerator { + private static final String SETTER_PATTERN = "%1$s oldValue = this.%2$s;\n%3$s\nsupport.firePropertyChange(\"%2$s\", oldValue, %4$s);"; + private static final String GWT_DEFAULT_PACKAGE = "com.google.gwt.user.client.ui"; + /** Stylesheets applied to the objects of the class */ List<StyleSheet> styleSheets = new ArrayList<StyleSheet>(); /** map of the different parts of the script associated with gmo */ @@ -80,8 +83,7 @@ gmo.getClassDescriptor().getName() + "Abstract", null, gmo.getJavadoc()); - ScriptHandler sh = new ScriptHandler(); - script = sh.decomposeScript(gmo.getClassDescriptor().getScript()); + script = ScriptHandler.decomposeScript(gmo.getClassDescriptor().getScript()); } public void setGwtGenerator(GwtGenerator gwtGenerator) { @@ -90,19 +92,23 @@ @Override public JavaFile generate() { - super.addImports(gmo); + super.addImports(); //add imports for (String s : (List<String>) script.get(ScriptPart.IMPORTS)) { jf.addImport(s); } + //add fields + for(JavaField field : (List<JavaField>) script.get(ScriptPart.FIELDS)) { + jf.addField(field, true); + } + //add bodycode jf.addBodyCode((String) script.get(ScriptPart.BODYCODE)); - - try { + //get creation, setting and displying methods content Map<Method, String> methodBodies = browseModelObjects(gmo); //add constructor @@ -112,17 +118,18 @@ //add initialization method jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "initialize", null, null, getMethodName(Method.BEFORE_CREATION) + "();\n" + getMethodName(Method.COMPONENTS_CREATION) + "();\n" + - getMethodName(Method.COMPONENTS_SETTINGS) + "();\n" + (script.get(ScriptPart.INITIALIZERS) != null ? script.get(ScriptPart.INITIALIZERS) + "\n" : "") + - getMethodName(Method.BEFORE_INITIALIZATION) + "();\n" + getMethodName(Method.COMPONENTS_TREE) + "();\n" + + getMethodName(Method.BEFORE_SETTINGS) + "();\n" + getMethodName(Method.COMPONENTS_SETTINGS) + "();\n" + + getMethodName(Method.BEFORE_TREE) + "();\n" + getMethodName(Method.COMPONENTS_TREE) + "();\n" + getMethodName(Method.BEFORE_BINDING) + "();\n" + getMethodName(Method.DATABINDING_INIT) + "();\n" + getMethodName(Method.IN_THE_END) + "();", "initialization")); //add overridable methods - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.BEFORE_CREATION), null, null, jf.isSuperclassIsGuixObject() ? "super." + getMethodName(Method.BEFORE_CREATION) + "();\n" : "", "")); - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.BEFORE_INITIALIZATION), null, null, jf.isSuperclassIsGuixObject() ? "super." + getMethodName(Method.BEFORE_INITIALIZATION) + "();\n" : "", "")); - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.BEFORE_BINDING), null, null, jf.isSuperclassIsGuixObject() ? "super." + getMethodName(Method.BEFORE_BINDING) + "();\n" : "", "")); - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.IN_THE_END), null, null, jf.isSuperclassIsGuixObject() ? "super." + getMethodName(Method.IN_THE_END) + "();\n" : "", "")); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.BEFORE_CREATION), null, null, jf.isSuperclassIsGuixObject() ? "super." + getMethodName(Method.BEFORE_CREATION) + "();\n" : "", "Method called before the creation of the components")); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.BEFORE_TREE), null, null, jf.isSuperclassIsGuixObject() ? "super." + getMethodName(Method.BEFORE_TREE) + "();\n" : "", "Method called before the creation of the component tree")); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.BEFORE_SETTINGS), null, null, jf.isSuperclassIsGuixObject() ? "super." + getMethodName(Method.BEFORE_SETTINGS) + "();\n" : "", "Method called before the settings of the components")); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.BEFORE_BINDING), null, null, jf.isSuperclassIsGuixObject() ? "super." + getMethodName(Method.BEFORE_BINDING) + "();\n" : "", "Method called before the binding")); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.IN_THE_END), null, null, jf.isSuperclassIsGuixObject() ? "super." + getMethodName(Method.IN_THE_END) + "();\n" : "", "Method called in the end of the initialization")); //add creation and initialization methods jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.COMPONENTS_CREATION), null, null, @@ -143,7 +150,7 @@ //add script methods for (JavaMethod m : (List<JavaMethod>) script.get(ScriptPart.METHODS)) { //checks if the method override a generated method - if ((m.getName().equals(getMethodName(Method.BEFORE_BINDING)) || m.getName().equals(getMethodName(Method.BEFORE_CREATION)) || m.getName().equals(getMethodName(Method.BEFORE_INITIALIZATION)) || m.getName().equals(getMethodName(Method.IN_THE_END))) && m.getReturnType() != null && m.getReturnType().equals("void") && m.getArguments() == null) { + if ((m.getName().equals(getMethodName(Method.BEFORE_BINDING)) || m.getName().equals(getMethodName(Method.BEFORE_CREATION)) || m.getName().equals(getMethodName(Method.BEFORE_TREE)) || m.getName().equals(getMethodName(Method.BEFORE_SETTINGS)) || m.getName().equals(getMethodName(Method.IN_THE_END))) && m.getReturnType() != null && m.getReturnType().equals("void") && m.getArguments() == null) { int i = 0; boolean methodFound = false; while (i < jf.getMethods().length && !methodFound) { @@ -161,6 +168,27 @@ jf.addMethod(m); } } + //add the method for the PropertChange management + if(!jf.isSuperclassIsGuixObject()) { + jf.addField(new JavaField(Modifier.PROTECTED, "java.beans.PropertyChangeSupport", "support", "new java.beans.PropertyChangeSupport(this)", null, null)); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "addPropertyChangeListener", new JavaArgument[]{new JavaArgument("java.beans.PropertyChangeListener", "listener")}, + null, "support.addPropertyChangeListener(listener);", null)); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "addPropertyChangeListener", new JavaArgument[]{new JavaArgument("String", "property"), new JavaArgument("java.beans.PropertyChangeListener", "listener")}, + null, "support.addPropertyChangeListener(property, listener);", null)); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "removePropertyChangeListener", new JavaArgument[]{new JavaArgument("java.beans.PropertyChangeListener", "listener")}, + null, "support.addPropertyChangeListener(listener);", null)); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "removePropertyChangeListener", new JavaArgument[]{new JavaArgument("String", "property"), new JavaArgument("java.beans.PropertyChangeListener", "listener")}, + null, "support.addPropertyChangeListener(property, listener);", null)); + } + //Modify the setters by adding the firePropertyChange call + for(JavaMethod method : jf.getMethods()) { + if(method.getName().startsWith("set") && method.getName().length() > 3 + && Character.isUpperCase(method.getName().charAt(3)) && method.getArguments() != null) { + method.setBodyCode(String.format(SETTER_PATTERN, method.getArguments()[0].getType(), + Character.toLowerCase(method.getName().charAt(3)) + method.getName().substring(4), + method.getBodyCode(), method.getArguments()[0].getName())); + } + } } catch (ClassNotFoundException eee) { if (log.isErrorEnabled()) { @@ -190,31 +218,24 @@ Class clazz = null; //do we need to overcharge the field boolean createField = true; - //Name of the tab - String tabName = 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(); - 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")) { - tabName = "\"" + gmo.getAttributeDescriptors().get(i).getValue() + "\""; - } - } - } //if gmo represnts a table tag - if (gmo.getClassDescriptor().getPackageName() == null && gmo.getClassDescriptor().getName().equalsIgnoreCase("Table")) { + if ((gmo.getClassDescriptor().getSuperClass() != null + && ((gmo.getClassDescriptor().getSuperClass().getPackageName() == null + && (gmo.getClassDescriptor().getSuperClass().getName().equalsIgnoreCase("Table") || gmo.getClassDescriptor().getSuperClass().getName().equalsIgnoreCase("FlexTable"))) + || gmo.getClassDescriptor().getSuperClass().toString().equals("com.google.gwt.user.client.ui.FlexTable"))) + || ((gmo.getClassDescriptor().getPackageName() == null + && (gmo.getClassDescriptor().getName().equalsIgnoreCase("Table") || gmo.getClassDescriptor().getName().equalsIgnoreCase("FlexTable"))) + || gmo.getClassDescriptor().toString().equals("com.google.gwt.user.client.ui.FlexTable"))) { //matrix of the gridbaglayout : the free zones are represented by null or false List<List<int[]>> layout = new ArrayList<List<int[]>>(); StringBuffer settingsMethod = new StringBuffer(); //Checks in the table tag if any attribute defines constraints for the children - TableHandler table = new TableHandler(gmo); + TableHandler tableHandler = new TableHandler(gmo); //the table is a FlexPanel - clazz = table.getClassToGenerate(); + clazz = tableHandler.getClassToGenerate(); //if the gmo is the parent or if the field is inherited and has the same class, we don't need to overcharge the field if(gmo.getParent() == null || (jf.getInheritedField(gmo.getId()) != null && jf.getInheritedField(gmo.getId()).getType().equals(clazz.getName()))) { @@ -223,18 +244,26 @@ //if the field is inherited but doesn't hav the same class, check if the types are compatible if(createField && jf.getInheritedField(gmo.getId()) != null) { try { - Class inheritedClazz = Class.forName(jf.getInheritedField(gmo.getId()).getType()); + Class inheritedClazz = gwtClassLoader.loadClass(jf.getInheritedField(gmo.getId()).getType()); if(!inheritedClazz.isAssignableFrom(clazz)) { throw new ClassCastException(); } } catch(ClassNotFoundException eee) { - throw new ClassCastException(); + try { + Class inheritedClazz = ClassLoader.getSystemClassLoader().loadClass(jf.getInheritedField(gmo.getId()).getType()); + if(!inheritedClazz.isAssignableFrom(clazz)) { + throw new ClassCastException(); + } + } + catch(ClassNotFoundException eeee) { + throw new ClassCastException(); + } } } if(createField) { jf.addField(new JavaField(Modifier.PROTECTED, - clazz.getName(), gmo.getId(), gmo.getJavadoc(), table), true); + clazz.getName(), gmo.getId(), gmo.getJavadoc(), tableHandler), gmo.isJavaBean()); componentsCreation.append(gmo.getId()).append(" = new ").append(clazz.getName()) .append("(").append(gmo.getConstructor() != null ? gmo.getConstructor() : "").append(");\n"); @@ -250,14 +279,20 @@ } settingsMethod.append(gmo.getId()) .append(".addStyleName(\"Table\");\n"); - processAttributes(clazz, gmo, settingsMethod, geh, table); + processAttributes(clazz, gmo, settingsMethod, geh, tableHandler); //add the component to its parent - componentsTree.append(gmo.getParent().getParent() == null ? "this" : gmo.getParent().getId()).append(".add(").append(gmo.getId()); - if(tabName != null) { - componentsTree.append(",").append(tabName); + if (!ignoreTag(gmo)) { + if(gmo.getParent().getParent() == null && jf.getInheritedField(gmo.getId()) != null) { + componentsTree.append(gmo.getParent().getParent() != null ? gmo.getParent().getId() : "this").append(".set").append(capitalizedId).append("(").append(gmo.getId()).append(");\n"); + } + else if(addItemComponent(gmo)) { + componentsTree.append(gmo.getParent().getParent() != null ? gmo.getParent().getId() : "this").append(".addItem(").append(gmo.getId()).append(");\n"); + } + else { + componentsTree.append(gmo.getParent().getParent() == null ? "this" : gmo.getParent().getId()).append(".add(").append(gmo.getId()).append(");\n"); + } } - componentsTree.append(");\n"); for (int r = 0; r < gmo.getChildren().size(); r++) { GuixModelObject row = gmo.getChildren().get(r); @@ -269,10 +304,10 @@ } else { //Checks in the row tag if any attribute defines constraints for the children - RowHandler ro = new RowHandler(row, table); + RowHandler rowHandler = new RowHandler(row, tableHandler); componentsTree.append(gmo.getId()) .append(".getRowFormatter().addStyleName(") - .append(ro.getRow() > 0 ? ro.getRow() : r).append(",\"Row\");\n"); + .append(rowHandler.getRow() > 0 ? rowHandler.getRow() : r).append(",\"Row\");\n"); int iC = 0; for (int c = 0; c < row.getChildren().size(); c++) { GuixModelObject cell = row.getChildren().get(c); @@ -289,8 +324,8 @@ } } else { - CellHandler cl = new CellHandler(cell, ro); - componentsTree.append(TableHandler.createCell(gmo.getId(), cl, layout, iC, r)); + CellHandler cellHandler = new CellHandler(cell, rowHandler); + componentsTree.append(TableHandler.createCell(gmo.getId(), cellHandler, layout, iC, r)); //browse the children of the child of the cell Map<Method, String> methodBodies = browseModelObjects(cell.getChildren().get(0)); @@ -304,11 +339,50 @@ //create the table componentsSettings.append(gmo.getId()).append("Settings();\n"); } + else if ((gmo.getClassDescriptor().getSuperClass() != null && gmo.getClassDescriptor().getSuperClass().getPackageName() == null && gmo.getClassDescriptor().getSuperClass().getName().equalsIgnoreCase("Tab")) + || (gmo.getClassDescriptor().getPackageName() == null && gmo.getClassDescriptor().getName().equalsIgnoreCase("Tab"))) { + //if the parent has a superclass and this superclass is a TabPanel or if the parent is null or if the parent is a TabPanel + if(((gmo.getParent().getClassDescriptor().getSuperClass() != null + && ((gmo.getParent().getClassDescriptor().getSuperClass().getPackageName() == null + && gmo.getParent().getClassDescriptor().getSuperClass().getName().equals("TabPanel")) + || (gmo.getParent().getClassDescriptor().getSuperClass().toString().equals("com.google.gwt.user.client.ui.TabPanel")))) + ||(gmo.getParent() == null + || (gmo.getParent().getClassDescriptor().getPackageName() == null + && gmo.getParent().getClassDescriptor().getName().equals("TabPanel")) + || (gmo.getParent().getClassDescriptor().toString().equals("com.google.gwt.user.client.ui.TabPanel")))) + && gmo.getChildren().size() == 1) { + String title = null; + for(AttributeDescriptor attribute : gmo.getAttributeDescriptors()) { + if(attribute.getName().equals("title")) { + title = attribute.getValue(); + break; + } + } + + //add the component to its parent + componentsTree.append(gmo.getParent().getParent() != null ? gmo.getParent().getId() : "this").append(".add(") + .append(gmo.getChildren().get(0).getId()).append(",").append(title != null ? title : "\"" + gmo.getId() + "\"").append(");\n"); + + Map<Method, String> methodBodies = browseModelObjects(gmo.getChildren().get(0)); + componentsCreation.append(methodBodies.get(Method.COMPONENTS_CREATION)); + componentsSettings.append(methodBodies.get(Method.COMPONENTS_SETTINGS)); + componentsTree.append(methodBodies.get(Method.COMPONENTS_TREE)); + } + else if(log.isErrorEnabled()) { + log.error("Tab tags can only be children of TabPanel tags, and can have only one child."); + } + } //if gmo represnts a menubar tag - else if (gmo.getClassDescriptor().getPackageName() == null && gmo.getClassDescriptor().getName().equalsIgnoreCase("MenuBar")) { + else if ((gmo.getClassDescriptor().getSuperClass() != null + && ((gmo.getClassDescriptor().getSuperClass().getPackageName() == null + && gmo.getClassDescriptor().getSuperClass().getName().equalsIgnoreCase("MenuBar")) + || gmo.getClassDescriptor().getSuperClass().toString().equals("com.google.gwt.user.client.ui.MenuBar"))) + || ((gmo.getClassDescriptor().getPackageName() == null + && gmo.getClassDescriptor().getName().equalsIgnoreCase("MenuBar")) + || gmo.getClassDescriptor().toString().equals("com.google.gwt.user.client.ui.MenuBar"))) { StringBuffer settingsMethod = new StringBuffer(); - MenuBarHandler menuBar = new MenuBarHandler(); - clazz = menuBar.getClassToGenerate(); + MenuBarHandler menuBarHandler = new MenuBarHandler(); + clazz = menuBarHandler.getClassToGenerate(); //if the gmo is the parent or if the field is inherited and has the same class, we don't need to overcharge the field if(gmo.getParent() == null || (jf.getInheritedField(gmo.getId()) != null && jf.getInheritedField(gmo.getId()).getType().equals(clazz.getName()))) { createField = false; @@ -316,20 +390,28 @@ //if the field is inherited but doesn't hav the same class, check if the types are compatible if(createField && jf.getInheritedField(gmo.getId()) != null) { try { - Class inheritedClazz = Class.forName(jf.getInheritedField(gmo.getId()).getType()); + Class inheritedClazz = gwtClassLoader.loadClass(jf.getInheritedField(gmo.getId()).getType()); if(!inheritedClazz.isAssignableFrom(clazz)) { throw new ClassCastException(); } } catch(ClassNotFoundException eee) { - throw new ClassCastException(); + try { + Class inheritedClazz = ClassLoader.getSystemClassLoader().loadClass(jf.getInheritedField(gmo.getId()).getType()); + if(!inheritedClazz.isAssignableFrom(clazz)) { + throw new ClassCastException(); + } + } + catch(ClassNotFoundException eeee) { + throw new ClassCastException(); + } } } if(createField) { jf.addField(new JavaField(Modifier.PROTECTED, - clazz.getName(), gmo.getId(), gmo.getJavadoc(), menuBar), - true); + clazz.getName(), gmo.getId(), gmo.getJavadoc(), menuBarHandler), + gmo.isJavaBean()); componentsCreation.append(gmo.getId()).append(" = new ").append(clazz.getName()) .append("(").append(gmo.getConstructor() != null ? gmo.getConstructor() : "").append(");\n"); @@ -342,14 +424,20 @@ if(jf.isSuperclassIsGuixObject() && jf.getInheritedField(gmo.getId()) != null) { settingsMethod.insert(0, "super." + gmo.getId() + "Settings();\n"); } - processAttributes(clazz, gmo, settingsMethod, geh, menuBar); + processAttributes(clazz, gmo, settingsMethod, geh, menuBarHandler); //add the component to its parent - componentsTree.append(gmo.getParent().getParent() == null ? "this" : gmo.getParent().getId()).append(".add(").append(gmo.getId()); - if(tabName != null) { - componentsTree.append(",").append(tabName); + if (!ignoreTag(gmo)) { + if(gmo.getParent().getParent() == null && jf.getInheritedField(gmo.getId()) != null) { + componentsTree.append(gmo.getParent().getParent() != null ? gmo.getParent().getId() : "this").append(".set").append(capitalizedId).append("(").append(gmo.getId()).append(");\n"); + } + else if(addItemComponent(gmo)) { + componentsTree.append(gmo.getParent().getParent() != null ? gmo.getParent().getId() : "this").append(".addItem(").append(gmo.getId()).append(");\n"); + } + else { + componentsTree.append(gmo.getParent().getParent() == null ? "this" : gmo.getParent().getId()).append(".add(").append(gmo.getId()).append(");\n"); + } } - componentsTree.append(");\n"); for (GuixModelObject child : gmo.getChildren()) { //browse the children of the child of the menubar @@ -361,6 +449,7 @@ //create the menu componentsSettings.append(gmo.getId()).append("Settings();\n"); } + //if gmo represents a "normal" tag else { //TagHandler of gmo's class @@ -382,41 +471,54 @@ clazz = th.getClassToGenerate(); } } - //check if gmo's superclass has a TagHandler and get the class to generate instead - else if(gmo.getParent() == null && gmo.getClassDescriptor().getSuperClass() != null && TagManager.getGuixClassHandler(gmo.getClassDescriptor().getSuperClass().getName()) != null) { - th = TagManager.getGuixClassHandler(gmo.getClassDescriptor().getSuperClass().getName()); - if(th != null) { - clazz = th.getClassToGenerate(); - } - } - //check if gmo's type is a generated class - else if(gmo.getClassDescriptor() != null && classes.get(gmo.getClassDescriptor().toString()) != null) { - jFile = classes.get(gmo.getClassDescriptor().toString()); - } - //check if gmo is the first tag and its superclass is a generated class - else if(gmo.getParent() == null && gmo.getClassDescriptor().getSuperClass() != null && classes.get(gmo.getClassDescriptor().getSuperClass().toString()) != null) { - jFile = classes.get(gmo.getClassDescriptor().getSuperClass().toString()); - } + //check if gmo's class has a TagHandler and get the class to generate instead else { - try{ - //get the class represented by cd - clazz = gwtClassLoader.loadClass(gmo.getClassDescriptor().toString()); + if(gmo.getClassDescriptor().getPackageName() == null) { + gmo.getClassDescriptor().setPackageName(GWT_DEFAULT_PACKAGE); } - catch (ClassNotFoundException eee) { - try { - clazz = ClassLoader.getSystemClassLoader().loadClass(gmo.getClassDescriptor().toString()); + if(TagManager.getGuixClassHandler(gmo.getClassDescriptor().toString()) != null) { + th = TagManager.getGuixClassHandler(gmo.getClassDescriptor().toString()); + if(th != null) { + clazz = th.getClassToGenerate(); } - catch(ClassNotFoundException eeee) { - File f = new File(gwtGenerator.getSrcDir(), gmo.getClassDescriptor().toString().replace('.', File.separatorChar) + ".java"); + } + //check if gmo's superclass has a TagHandler and get the class to generate instead + else if(gmo.getParent() == null && gmo.getClassDescriptor().getSuperClass() != null && TagManager.getGuixClassHandler(gmo.getClassDescriptor().getSuperClass().getName()) != null) { + th = TagManager.getGuixClassHandler(gmo.getClassDescriptor().getSuperClass().getName()); + if(th != null) { + clazz = th.getClassToGenerate(); + } + } + //check if gmo's type is a generated class + else if(gmo.getClassDescriptor() != null && classes.get(gmo.getClassDescriptor().toString()) != null) { + jFile = classes.get(gmo.getClassDescriptor().toString()); + } + //check if gmo is the first tag and its superclass is a generated class + else if(gmo.getParent() == null && gmo.getClassDescriptor().getSuperClass() != null && classes.get(gmo.getClassDescriptor().getSuperClass().toString()) != null) { + jFile = classes.get(gmo.getClassDescriptor().getSuperClass().toString()); + } + else { + try{ + //get the class represented by cd + clazz = gwtClassLoader.loadClass(gmo.getClassDescriptor().toString()); + } + catch (ClassNotFoundException eee) { try { - Reader isr = new InputStreamReader(new FileInputStream(f)); - jFile = JavaFileParser.parseJavaFile(gmo.getClassDescriptor().toString(), isr); + clazz = ClassLoader.getSystemClassLoader().loadClass(gmo.getClassDescriptor().toString()); } - catch (FileNotFoundException eeeee) { - log.error("error : " + gmo.getClassDescriptor().toString()); - log.error(eeeee); - eeeee.printStackTrace(); - throw new ClassNotFoundException(); + catch(ClassNotFoundException eeee) { + File f = new File(gwtGenerator.getSrcDir(), gmo.getClassDescriptor().toString().replace('.', File.separatorChar) + ".java"); + try { + Reader isr = new InputStreamReader(new FileInputStream(f)); + jFile = JavaFileParser.parseJavaFile(gmo.getClassDescriptor().toString(), isr); + gwtGenerator.getPropertyChangeListenerDependencies().add(jFile); + } + catch (FileNotFoundException eeeee) { + log.error("error : " + gmo.getClassDescriptor().toString()); + log.error(eeeee); + eeeee.printStackTrace(); + throw new ClassNotFoundException(); + } } } } @@ -502,14 +604,12 @@ //if gmo has a TagHandler, add a field to the JavaFile with this TagHandler (used for the databinding generation) if(th != null && th.getClassToGenerate() != null) { jf.addField(new JavaField(Modifier.PROTECTED, - clazz.getName(), gmo.getId(), - " new " + clazz.getName() + "(" + ((gmo.getConstructor() != null) ? gmo.getConstructor() : "") + ")", - gmo.getJavadoc(), th), true); + clazz.getName(), gmo.getId(), gmo.getJavadoc(), th), gmo.isJavaBean()); } else { jf.addField(new JavaField(Modifier.PROTECTED, (classes != null && classes.containsKey(gmo.getClassDescriptor().toString())) ? gmo.getClassDescriptor().toString() + "Abstract" - : gmo.getClassDescriptor().toString(), gmo.getId(), gmo.getJavadoc(), superTh != null ? superTh : th), true); + : gmo.getClassDescriptor().toString(), gmo.getId(), gmo.getJavadoc(), superTh), gmo.isJavaBean()); } componentsCreation.append(gmo.getId()).append(" = new "); @@ -546,19 +646,17 @@ } //if gmo is the child of a cell - if (!(gmo.getParent().getClassDescriptor().getPackageName() == null && gmo.getParent().getClassDescriptor().getName().equalsIgnoreCase("Cell")) && !gmo.getClassDescriptor().toString().equals("javax.swing.JMenuBar")) { + if (!ignoreTag(gmo)) { if((jFile != null && (jFile.getField(gmo.getId()) != null || jFile.getInheritedField(gmo.getId()) != null)) || (gmo.getParent().getParent() == null && jf.getInheritedField(gmo.getId()) != null)) { componentsTree.append(gmo.getParent().getParent() != null ? gmo.getParent().getId() : "this").append(".set").append(capitalizedId).append("(").append(gmo.getId()).append(");\n"); } + else if(addItemComponent(gmo)) { + componentsTree.append(gmo.getParent().getParent() != null ? gmo.getParent().getId() : "this").append(".addItem(").append(gmo.getId()).append(");\n"); + } //add the component to its parent else if(superClazz != null && com.google.gwt.user.client.ui.Widget.class.isAssignableFrom(superClazz)) { - componentsTree.append(gmo.getParent().getParent() != null ? gmo.getParent().getId() : "this").append(".add(").append(gmo.getId()); - //with a tabName if it is not null - if(tabName != null) { - componentsTree.append(",").append(tabName); - } - componentsTree.append(");\n"); + componentsTree.append(gmo.getParent().getParent() != null ? gmo.getParent().getId() : "this").append(".add(").append(gmo.getId()).append(");\n"); } } } @@ -610,7 +708,7 @@ jf.addInheritedField(f); } } - processAttributes(jFile, superClazz, gmo, settingsMethod, geh, superTh); + processAttributes(jFile, superClazz, gmo, settingsMethod, geh, superTh != null ? superTh: th); } else { log.error("Allo Houston, on a un probleme !"); @@ -633,6 +731,32 @@ } /** + * + * @return true if the tag does not represent a real object but is just useful to ease the creation of the UI + */ + private boolean ignoreTag(GuixModelObject gmo) { + return (gmo.getParent() != null && (gmo.getParent().getClassDescriptor().getPackageName() == null + && (gmo.getParent().getClassDescriptor().getName().equalsIgnoreCase("Cell") || gmo.getParent().getClassDescriptor().getName().equalsIgnoreCase("Tab"))) + && !(gmo.getParent().getClassDescriptor().getPackageName() == null && gmo.getParent().getClassDescriptor().getName().equalsIgnoreCase("VerticalSplitPanel")) + && !gmo.getParent().getClassDescriptor().toString().equals("com.google.gwt.user.client.ui.VerticalSplitPanel") + && !(gmo.getParent().getClassDescriptor().getPackageName() == null && gmo.getParent().getClassDescriptor().getName().equalsIgnoreCase("HorizontalSplitPanel")) + && !gmo.getParent().getClassDescriptor().toString().equals("com.google.gwt.user.client.ui.HorizontalSplitPanel")); + } + + /** + * + * @return true if the component parent needs the "addItem" method to add the child + */ + private boolean addItemComponent(GuixModelObject gmo) { + return (gmo.getParent() != null && (gmo.getParent().getClassDescriptor().getPackageName() == null && gmo.getParent().getClassDescriptor().getName().equalsIgnoreCase("Tree")) + || gmo.getParent().getClassDescriptor().toString().equals("com.google.gwt.user.client.ui.Tree") + || (gmo.getParent().getClassDescriptor().getPackageName() == null && gmo.getParent().getClassDescriptor().getName().equalsIgnoreCase("TreeNode")) + || gmo.getParent().getClassDescriptor().toString().equals("com.google.gwt.user.client.ui.TreeItem") + || (gmo.getParent().getClassDescriptor().getPackageName() == null && gmo.getParent().getClassDescriptor().getName().equalsIgnoreCase("ComboBox")) + || gmo.getParent().getClassDescriptor().toString().equals("com.google.gwt.user.client.ui.ListBox")); + } + + /** * Generates the code to set the attributes of the gmo * * @param clazz class represented by gmo @@ -799,7 +923,6 @@ StringBuffer componentsSettings = new StringBuffer(""); StringBuffer componentsTree = new StringBuffer(""); StringBuffer creationMethod = new StringBuffer(""); - StringBuffer bindings = new StringBuffer(""); String text = null, cmd = null; //gmo's id with the first letter capitalized String capitalizedId = (gmo.getId().length() > 0) ? Character.toUpperCase(gmo.getId().charAt(0)) + gmo.getId().substring(1) : gmo.getId(); @@ -808,10 +931,7 @@ TagHandler th = new MenuHandler(); Class clazz = th.getClassToGenerate(); jf.addField(new JavaField(Modifier.PROTECTED, - clazz.getName(), gmo.getId(), - " new " + clazz.getName() + "(" + - ((gmo.getConstructor() != null) ? gmo.getConstructor() : "") + ")", gmo.getJavadoc(), th), - true); + clazz.getName(), gmo.getId(), gmo.getJavadoc(), th), gmo.isJavaBean()); componentsCreation.append(gmo.getId()).append(" = new ").append(clazz.getName()) .append("(").append(gmo.getConstructor() != null ? gmo.getConstructor() : "").append(");\n"); @@ -856,7 +976,6 @@ componentsCreation.append(methodBodies.get(Method.COMPONENTS_CREATION)); componentsSettings.append(methodBodies.get(Method.COMPONENTS_SETTINGS)); componentsTree.append(methodBodies.get(Method.COMPONENTS_TREE)); - bindings.append(methodBodies.get(Method.DATABINDING_INIT)); } } else if(gmo.getClassDescriptor().getPackageName() == null && gmo.getClassDescriptor().getName().equals("MenuItem")) { @@ -889,7 +1008,6 @@ result.put(Method.COMPONENTS_CREATION, componentsCreation.toString()); result.put(Method.COMPONENTS_SETTINGS, componentsSettings.toString()); result.put(Method.COMPONENTS_TREE, componentsTree.toString()); - result.put(Method.DATABINDING_INIT, bindings.toString()); return result; } Deleted: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtConfigGenerator.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtConfigGenerator.java 2009-08-25 10:49:26 UTC (rev 1574) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtConfigGenerator.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -1,112 +0,0 @@ -/** - * *##% 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 java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.guix.model.GuixModelObject; -import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlPullParserFactory; -import org.xmlpull.v1.XmlSerializer; - -/** - * Generator of the config file - * - * @author kmorin - */ -public class GwtConfigGenerator { - - /** GuixModelObject representing the main class */ - private GuixModelObject gmo; - /** List of the CSS files needed of the generation */ - protected List<File> cssFiles; - /** log */ - private Log log = LogFactory.getLog(GwtConfigGenerator.class); - - /** - * Constructor - * - * @param gmo GuixModelObject representing the class to generate - */ - public GwtConfigGenerator(GuixModelObject gmo, List<File> cssFiles) { - this.gmo = gmo; - this.cssFiles = cssFiles; - } - - /** - * Generates the configuration file - * - * @param config the file to generate - */ - public void generate(File config) { - try { - XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null); - - XmlSerializer serializer = factory.newSerializer(); - - 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.startTag("", "module"); - serializer.comment("Inherit the core Web Toolkit stuff."); - serializer.startTag("", "inherits"); - serializer.attribute("", "name", "com.google.gwt.user.User"); - serializer.endTag("","inherits"); - - serializer.startTag("", "inherits"); - int i = 0; - while(i < gmo.getAttributeDescriptors().size() - && !gmo.getAttributeDescriptors().get(i).getName().equals("theme")) { - i++; - } - serializer.attribute("", "name", i < gmo.getAttributeDescriptors().size() ? - gmo.getAttributeDescriptors().get(i).getValue() - : "com.google.gwt.user.theme.standard.Standard"); - serializer.endTag("","inherits"); - - serializer.comment("Specify the app entry point class."); - serializer.startTag("","entry-point"); - serializer.attribute("", "class", gmo.getClassDescriptor().getPackageName() - + "." + gmo.getClassDescriptor().getName() + "Impl"); - serializer.endTag("","entry-point"); - - serializer.comment("Specify the application specific style sheet."); - for(File f : cssFiles) { - serializer.startTag("", "stylesheet"); - serializer.attribute("","src", f.getName()); - serializer.endTag("", "stylesheet"); - } - - serializer.endTag("", "module"); - serializer.endDocument(); - } - catch (XmlPullParserException ex) { - log.error(ex); - } - catch (IOException ex) { - log.error(ex); - } - } -} 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-08-25 10:49:26 UTC (rev 1574) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -19,6 +19,7 @@ package org.nuiton.guix.generator; import com.google.gwt.user.client.ui.Label; +import java.beans.PropertyChangeListener; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -95,23 +96,18 @@ if (mainClass) { gimg.addMainMethod(); - GwtConfigGenerator gcg = new GwtConfigGenerator(gmo, getCSSFiles()); - GwtHtmlGenerator ghg = new GwtHtmlGenerator(gmo, launcherName); File javaClientDir = javaOutDir; while(!javaClientDir.getPath().substring(javaClientDir.getPath().lastIndexOf(File.separatorChar) + 1).equals("client")) { javaClientDir = javaClientDir.getParentFile(); } - File outConfigMain = new File(javaClientDir.getParentFile(), launcherName.substring(launcherName.lastIndexOf('.') + 1) + ".gwt.xml"); -// File resourcesClientDir = resourcesOutDir; -// while(!resourcesClientDir.getPath().substring(resourcesClientDir.getPath().lastIndexOf(File.separatorChar) + 1).equals("client")) { -// resourcesClientDir = resourcesClientDir.getParentFile(); -// } + File publicDir = new File(javaClientDir.getParentFile(), "public"); if (!publicDir.exists()) { publicDir.mkdirs(); } - File outHtmlMain = new File(publicDir, launcherName.substring(launcherName.lastIndexOf('.') + 1) + ".html"); - gcg.generate(outConfigMain); + + generateConfig(javaClientDir, publicDir); + for(File f : getCSSFiles()) { try { File fPublic = new File(publicDir, f.getName()); @@ -131,7 +127,6 @@ log.error(eee); } } - ghg.generate(outHtmlMain); } ging.generate(); @@ -145,7 +140,7 @@ 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()); -g(); + return jf; } catch (IllegalArgumentException eee) { @@ -178,7 +173,7 @@ return null; } - private void g() { + private void generateConfig(File javaClientDir, File publicDir) { try { XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null); @@ -192,6 +187,8 @@ if(!webInfDir.exists()) { webInfDir.mkdirs(); } + + //generates web.xml serializer.setOutput(new PrintWriter(new File(webInfDir, "web.xml"))); serializer.startDocument("UTF-8", null); @@ -209,8 +206,8 @@ serializer.endTag("", "web-app"); serializer.endDocument(); + //generates index.html serializer = factory.newSerializer(); - serializer.setOutput(new PrintWriter(new File(webappDir, "index.html"))); serializer.startDocument("UTF-8", null); serializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n"); @@ -230,6 +227,113 @@ serializer.endTag("", "html"); serializer.endDocument(); + //generates the .gwt.xml file + serializer = factory.newSerializer(); + + serializer.setOutput(new PrintWriter(new File(javaClientDir.getParentFile(), launcherName.substring(launcherName.lastIndexOf('.') + 1) + ".gwt.xml"))); + 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.startTag("", "module"); + serializer.comment("Inherit the core Web Toolkit stuff."); + serializer.startTag("", "inherits"); + serializer.attribute("", "name", "com.google.gwt.user.User"); + serializer.endTag("","inherits"); + + serializer.startTag("", "inherits"); + serializer.attribute("", "name", "com.googlecode.gwtx.Java"); + serializer.endTag("","inherits"); + + serializer.startTag("", "inherits"); + int i = 0; + while(i < gmo.getAttributeDescriptors().size() + && !gmo.getAttributeDescriptors().get(i).getName().equals("theme")) { + i++; + } + serializer.attribute("", "name", i < gmo.getAttributeDescriptors().size() ? + gmo.getAttributeDescriptors().get(i).getValue() + : "com.google.gwt.user.theme.standard.Standard"); + serializer.endTag("","inherits"); + + serializer.comment("Specify the app entry point class."); + serializer.startTag("","entry-point"); + serializer.attribute("", "class", gmo.getClassDescriptor().getPackageName() + + "." + gmo.getClassDescriptor().getName() + "Impl"); + serializer.endTag("","entry-point"); + + serializer.comment("Specify the application specific style sheet."); + for(File f : cssFiles) { + serializer.startTag("", "stylesheet"); + serializer.attribute("","src", f.getName()); + serializer.endTag("", "stylesheet"); + } + + serializer.endTag("", "module"); + serializer.endDocument(); + + //generates the .html file + serializer = factory.newSerializer(); + + serializer.setOutput(new PrintWriter(new File(publicDir, launcherName.substring(launcherName.lastIndexOf('.') + 1) + ".html"))); + 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.docdecl(" HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\""); + serializer.comment("The HTML 4.01 Transitional DOCTYPE declaration above " + + "set at the top of the file will set the browser's rendering engine " + + "into \"Quirks Mode\". Replacing this declaration with a \"Standards Mode\" doctype is supported, " + + "but may lead to some differences in layout."); + serializer.startTag("", "html"); + serializer.startTag("", "head"); + + serializer.startTag("","meta"); + serializer.attribute("", "http-equiv", "content-type"); + serializer.attribute("", "content", "text/html; charset=UTF-8"); + serializer.endTag("","meta"); + + serializer.comment("This script loads your compiled module. " + + "If you add any GWT meta tags, they must " + + "be added before this line."); + serializer.startTag("","script"); + serializer.attribute("", "type", "text/javascript"); + serializer.attribute("", "language", "javascript"); + serializer.attribute("", "src", launcherName + ".nocache.js"); + serializer.text("\n"); + serializer.endTag("","script"); + + serializer.startTag("","title"); + i = 0; + while(i < gmo.getAttributeDescriptors().size() + && !gmo.getAttributeDescriptors().get(i).getName().equals("title")) + i++; + serializer.text(i < gmo.getAttributeDescriptors().size() ? + gmo.getAttributeDescriptors().get(i).getValue() : + "My Application"); + serializer.endTag("","title"); + + + + serializer.endTag("", "head"); + + serializer.comment("The body can have arbitrary html, or " + + "you can leave the body empty if you want " + + "to create a completely dynamic UI."); + serializer.startTag("", "body"); + + serializer.comment("OPTIONAL: include this if you want history support"); + serializer.startTag("", "iframe"); + serializer.attribute("", "src", "javascript:''"); + serializer.attribute("", "id", "__gwt_historyFrame"); + serializer.attribute("", "tabIndex", "-1"); + serializer.attribute("", "style", "position:absolute;width:0;height:0;border:0"); + serializer.endTag("", "iframe"); + + serializer.endTag("", "body"); + serializer.endTag("", "html"); + serializer.endDocument(); + } catch (XmlPullParserException ex) { log.error(ex); @@ -280,128 +384,190 @@ String realMethodName = null; String realAttributename = null; - //if the part of the binding is a method - if (binding[i].endsWith(")")) { - //the method name is all what is before the first open bracket - realMethodName = binding[i].substring(0, binding[i].indexOf("(")); - //if the parent of the method has a TagHandler, then check that the method is the generic method name for all the libraries - //or if it is the right name, and then determine the corresponding attribute - 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); + if(Character.isUpperCase(binding[i].charAt(binding[i].lastIndexOf(".") + 1))) { + try { + Label.class.getClassLoader().loadClass(binding[i]); + } + catch (ClassNotFoundException eee) { + try { + ClassLoader.getSystemClassLoader().loadClass(binding[i]); + } + catch (ClassNotFoundException eeee) { + return null; + } + } + bindingExists = false; + } + else { + //if the part of the binding is a method + if (binding[i].endsWith(")")) { + //the method name is all what is before the first open bracket + realMethodName = binding[i].substring(0, binding[i].indexOf('(')); + //if the parent of the method has a TagHandler, then check that the method is the generic method name for all the libraries + //or if it is the right name, and then determine the corresponding attribute + 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); + } + } } - 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 the method name is the real one, get the corresponding attribute name + 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 the method name is the real one, get the corresponding attribute name - if(realAttributename == null) { - if(binding[i].startsWith("get")) { - realAttributename = Character.toLowerCase(binding[i].charAt(3)) + binding[i].substring(4, binding[i].indexOf("(")); + //if the parent of the method is an instance of a generated class + 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 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("(")); + try { + returnType = clazz.getMethod(realMethodName, (Class[])null).getReturnType().getName(); + bindingExists = true; + } + catch (NoSuchMethodException eee) { + bindingExists = false; + } } + getter = realMethodName + binding[i].substring(binding[i].indexOf('(')); } - //if the parent of the method is an instance of a generated class - if (jf != null) { - bindingExists = jf.getMethod(realMethodName, null) != null; - if (bindingExists) { - returnType = jf.getMethod(realMethodName, null).getReturnType(); + //if the part of the binding is an attribute + else { + //if the parent of the attribute has a TagHandler, then check that the attribute is the generic attribute name for all the libraries + //or if it is the right name + if(prevTh != null) { + realAttributename = prevTh.getAttrToGenerate(binding[i]); + } + //if it is its real name + if(realAttributename == null) { + realAttributename = binding[i]; + } + //if the parent of the attribute is an instance of a generated class + 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 { - returnType = clazz.getMethod(realMethodName, (Class[])null).getReturnType().getName(); - bindingExists = true; + else { + try { + returnType = clazz.getMethod("get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), (Class[])null).getReturnType().getName(); + getter = "get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1) + "()"; + bindingExists = true; + } + catch (NoSuchMethodException eee) { + try { + returnType = clazz.getMethod("is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), (Class[])null).getReturnType().getName(); + getter = "is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1) + "()"; + bindingExists = true; + } + catch (NoSuchMethodException eeee) { + bindingExists = false; + } + } } - catch (NoSuchMethodException eee) { - bindingExists = false; - } } - getter = realMethodName + binding[i].substring(binding[i].indexOf("(")); - //replace the value of the binding by the getter method - binding[i] = getter; - } - //if the part of the binding is an attribute - else { - //if the parent of the attribute has a TagHandler, then check that the attribute is the generic attribute name for all the libraries - //or if it is the right name - if(prevTh != null) { - realAttributename = prevTh.getAttrToGenerate(binding[i]); - } - //if it is its real name - if(realAttributename == null) { - realAttributename = binding[i]; - } - //if the parent of the attribute is an instance of a generated class - 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(); + //if the binding binds an existing attribute or method + if (bindingExists) { + //replace the value of the binding by the getter method + binding[i] = getter; + //if the parent has a taghandler + if (prevTh != null) { + String getterWoBrackets = getter.substring(0, getter.indexOf('(')); + //for GWT the only objects that can be bound are the ones which have got a TagHandler that defines methods which can be bound + if (prevTh.hasEventInfosAboutMethod(getterWoBrackets)) { + model = prevTh.getEventInfosModelName(getterWoBrackets); + listener = prevTh.getEventInfosListenerClass(getterWoBrackets); + addMethod = prevTh.getEventInfosAddListenerMethodName(getterWoBrackets); + removeMethod = prevTh.getEventInfosRemoveListenerMethodName(getterWoBrackets); + } } - - 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 { + //get the class of the current token or its JavaFile try { - returnType = clazz.getMethod("get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), (Class[])null).getReturnType().getName(); - getter = "get" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1) + "()"; - bindingExists = true; + nextClazz = Label.class.getClassLoader().loadClass(returnType); } - catch (NoSuchMethodException eee) { + catch (ClassNotFoundException eee) { try { - returnType = clazz.getMethod("is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1), (Class[])null).getReturnType().getName(); - getter = "is" + Character.toUpperCase(realAttributename.charAt(0)) + realAttributename.substring(1) + "()"; - bindingExists = true; + nextClazz = ClassLoader.getSystemClassLoader().loadClass(returnType); } - catch (NoSuchMethodException eee2) { - bindingExists = false; + catch (ClassNotFoundException eeee) { + for(JavaFile javaFile : generatedFiles.values()) { + if(returnType.equals(javaFile.getPackageName() + "." + javaFile.getClassName())) { + nextFile = javaFile; + break; + } + } + if(nextFile == null) { + for(JavaFile javaFile : propertyChangeListenerDependencies) { + if(returnType.equals(javaFile.getPackageName() + "." + javaFile.getClassName())) { + nextFile = javaFile; + break; + } + } + } } } - } - binding[i] = getter; - } - //if the binding binds an existing attribute or method - if (bindingExists) { - //if it is the last element of the binding and its parent has a taghandler - if (i == binding.length - 1 && prevTh != null) { - String getterWoBrackets = getter.substring(0, getter.indexOf("(")); - //for GWT the only objects that can be bound are the ones which have got a TagHandler that defines methods which can be bound - if (prevTh.hasEventInfosAboutMethod(getterWoBrackets)) { - model = prevTh.getEventInfosModelName(getterWoBrackets); - listener = prevTh.getEventInfosListenerClass(getterWoBrackets); - addMethod = prevTh.getEventInfosAddListenerMethodName(getterWoBrackets); - removeMethod = prevTh.getEventInfosRemoveListenerMethodName(getterWoBrackets); + + if(listener == null && clazz != null) { + try { + clazz.getMethod("addPropertyChangeListener", PropertyChangeListener.class); + listener = PropertyChangeListener.class; + addMethod = "addPropertyChangeListener"; + removeMethod = "removePropertyChangeListener"; + } + catch(NoSuchMethodException eee) { + } } - else { - log.error("Impossible binding for the " + (realMethodName != null ? "method '" : "attribute '") + realAttributename + "' of the class '" + prevTh.getClassToGenerate().getName() + "'"); + else if(listener == null && jf != null) { + for(JavaMethod method : jf.getAllMethods()) { + if(method.getName().equals("addPropertyChangeListener") + && ((method.getArguments().length == 1 && method.getArguments()[0].getType().equals("java.beans.PropertyChangeListener")) + ||(method.getArguments().length == 2 && method.getArguments()[1].getType().equals("java.beans.PropertyChangeListener")))) { + listener = PropertyChangeListener.class; + addMethod = "addPropertyChangeListener"; + removeMethod = "removePropertyChangeListener"; + } + } } + + boolean ifAdded = false; if(listener != null) { - //starts to generate the code - dbCreation.append("if("); - dbDeletion.append("if("); if (alreadyChecked != null && !alreadyChecked.isEmpty()) { + ifAdded = true; + //starts to generate the code + dbCreation.append("if("); + dbDeletion.append("if("); //add not null parent condition for (int j = 0; j < alreadyChecked.size(); j++) { dbCreation.append(alreadyChecked.get(0)); @@ -414,7 +580,7 @@ dbDeletion.append(" != null && "); } - if (binding.length > alreadyChecked.size() + 1) { + if (binding.length > alreadyChecked.size() + 1 && nextClazz != null && !nextClazz.isPrimitive()) { for (int j = 0; j < alreadyChecked.size(); j++) { dbCreation.append(alreadyChecked.get(j)).append("."); dbDeletion.append(alreadyChecked.get(j)).append("."); @@ -426,13 +592,14 @@ dbCreation.delete(dbCreation.length() - 4, dbCreation.length()); dbDeletion.delete(dbDeletion.length() - 4, dbDeletion.length()); } + dbCreation.append(") {\n"); + dbDeletion.append(") {\n"); } - else { - dbCreation.append(getter).append(" != null"); - dbDeletion.append(getter).append(" != null"); + else if(nextClazz != null && !nextClazz.isPrimitive()) { + ifAdded = true; + dbCreation.append("if(").append(getter).append(" != null").append(") {\n"); + dbDeletion.append("if(").append(getter).append(" != null").append(") {\n"); } - dbCreation.append(") {\n"); - dbDeletion.append(") {\n"); if (alreadyChecked != null) { for (int j = 0; j < alreadyChecked.size(); j++) { @@ -444,10 +611,15 @@ 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"); + + dbCreation.append(addMethod).append("("); + dbDeletion.append(removeMethod).append("("); + if(listener == PropertyChangeListener.class) { + dbCreation.append("\"").append(realAttributename).append("\", "); + dbDeletion.append("\"").append(realAttributename).append("\", "); + } + dbCreation.append("new ").append(listener.getName()).append("() {\n"); + dbDeletion.append("new ").append(listener.getName()).append("() {\n"); for(Method m : listener.getMethods()) { StringBuffer sb = new StringBuffer(); for(Annotation a : m.getDeclaredAnnotations()) { @@ -473,46 +645,37 @@ 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; + dbCreation.append("});\n"); + dbDeletion.append("});\n"); + if(ifAdded) { + dbCreation.append("}\n"); + dbDeletion.append("}\n"); + } + + if (alreadyChecked == null) { + alreadyChecked = new ArrayList<String>(); + } + alreadyChecked.add(getter); + try { + //if it is not the last element of the binding + if(i + 1 < binding.length) { + result.addAll(generateBindings(dbCreation, dbDeletion, th, nextFile, nextClazz, binding, i+1, alreadyChecked, methodToInvoke, generatedFiles)); } + if(listener != null && !result.contains(listener)) { + result.add(listener); + } } + catch(NullPointerException eee) { + log.error(i); + eee.printStackTrace(); + return null; + } } } - if (alreadyChecked == null) { - alreadyChecked = new ArrayList<String>(); + else if (log.isErrorEnabled()) { + log.error("unable to bind " + binding[i]); } - alreadyChecked.add(getter); - //if it is not the last element of the binding - if (i + 1 < binding.length) { - return generateBindings(dbCreation, dbDeletion, th, nextFile, nextClazz, binding, i + 1, alreadyChecked, methodToInvoke, generatedFiles); - } - else { - if(listener == null) { - return null; - } - result.add(listener); - return result; - } } - else if (log.isErrorEnabled()) { - log.error("unable to bind " + binding[i]); - } return result; } } Deleted: 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 2009-08-25 10:49:26 UTC (rev 1574) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtGenerator1.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -1,303 +0,0 @@ -/** - * *##% 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, getCSSFiles()); - 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(); - generators.put(ging, out); - JavaFile jf = gacg.generate(); - generators.put(gacg, outAbstract); - gimg.generate(); - 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; - } -} Deleted: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtHtmlGenerator.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtHtmlGenerator.java 2009-08-25 10:49:26 UTC (rev 1574) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtHtmlGenerator.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -1,127 +0,0 @@ -/** - * *##% 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 java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.guix.model.GuixModelObject; -import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlPullParserFactory; -import org.xmlpull.v1.XmlSerializer; - -/** - * Generator of the Html file - * - * @author kmorin - */ -public class GwtHtmlGenerator { - - /** GuixModelObject representing the main class */ - private GuixModelObject gmo; - /** name of the launcher file */ - private String launcherName; - /** log */ - private Log log = LogFactory.getLog(GwtHtmlGenerator.class); - - /** - * Constructor - * - * @param gmo GuixModelObject representing the main class - * @param launcherName name of the launcher file - */ - public GwtHtmlGenerator(GuixModelObject gmo, String launcherName) { - this.gmo = gmo; - this.launcherName = launcherName; - } - - public void generate(File html) { - try { - XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null); - - XmlSerializer serializer = factory.newSerializer(); - - serializer.setOutput(new PrintWriter(html)); - 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.docdecl(" HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\""); - serializer.comment("The HTML 4.01 Transitional DOCTYPE declaration above " + - "set at the top of the file will set the browser's rendering engine " + - "into \"Quirks Mode\". Replacing this declaration with a \"Standards Mode\" doctype is supported, " + - "but may lead to some differences in layout."); - serializer.startTag("", "html"); - serializer.startTag("", "head"); - - serializer.startTag("","meta"); - serializer.attribute("", "http-equiv", "content-type"); - serializer.attribute("", "content", "text/html; charset=UTF-8"); - serializer.endTag("","meta"); - - serializer.comment("This script loads your compiled module. " + - "If you add any GWT meta tags, they must " + - "be added before this line."); - serializer.startTag("","script"); - serializer.attribute("", "type", "text/javascript"); - serializer.attribute("", "language", "javascript"); - serializer.attribute("", "src", launcherName + ".nocache.js"); - serializer.text("\n"); - serializer.endTag("","script"); - - serializer.startTag("","title"); - int i = 0; - while(i < gmo.getAttributeDescriptors().size() - && !gmo.getAttributeDescriptors().get(i).getName().equals("title")) - i++; - serializer.text(i < gmo.getAttributeDescriptors().size() ? - gmo.getAttributeDescriptors().get(i).getValue() : - "My Application"); - serializer.endTag("","title"); - - - - serializer.endTag("", "head"); - - serializer.comment("The body can have arbitrary html, or " + - "you can leave the body empty if you want " + - "to create a completely dynamic UI."); - serializer.startTag("", "body"); - - serializer.comment("OPTIONAL: include this if you want history support"); - serializer.startTag("", "iframe"); - serializer.attribute("", "src", "javascript:''"); - serializer.attribute("", "id", "__gwt_historyFrame"); - serializer.attribute("", "tabIndex", "-1"); - serializer.attribute("", "style", "position:absolute;width:0;height:0;border:0"); - serializer.endTag("", "iframe"); - - serializer.endTag("", "body"); - serializer.endTag("", "html"); - serializer.endDocument(); - } - catch (XmlPullParserException ex) { - log.error(ex); - } - catch (IOException ex) { - log.error(ex); - } - } -} Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtImplementationGenerator.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtImplementationGenerator.java 2009-08-25 10:49:26 UTC (rev 1574) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtImplementationGenerator.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -52,7 +52,7 @@ @Override public JavaFile generate() { - super.addImports(gmo); + super.addImports(); jf.addMethod(new JavaMethod(Modifier.PUBLIC, null, gmo.getClassDescriptor().getName() + "Impl", null, null, "super();", "Constructor")); return jf; 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-08-25 10:49:26 UTC (rev 1574) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtInterfaceGenerator.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -27,6 +27,7 @@ import java.lang.reflect.Modifier; import java.util.List; import java.util.Map; +import org.nuiton.guix.tags.TagManager; /** * Generator of interfaces @@ -53,16 +54,13 @@ @Override public JavaFile generate() { - super.addImports(gmo); + super.addImports(); addFields(gmo); - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "initialize", null, null, null, "initialization")); jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.BEFORE_CREATION), null, null, null, "")); - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.COMPONENTS_CREATION), null, null, null, "Components creation")); - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.BEFORE_INITIALIZATION), null, null, null, "")); - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.COMPONENTS_TREE), null, null, null, "components layout")); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.BEFORE_TREE), null, null, null, "")); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.BEFORE_SETTINGS), null, null, null, "")); jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.BEFORE_BINDING), null, null, null, "")); - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.DATABINDING_INIT), null, null, null, "initilization of databinding")); jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", getMethodName(Method.IN_THE_END), null, null, null, "")); return jf; @@ -75,21 +73,20 @@ */ private void addFields(GuixModelObject gmo) { for (GuixModelObject child : gmo.getChildren()) { - if (child.getClassDescriptor().getPackageName() == null || child.getClassDescriptor().getPackageName().equals("org.nuiton.guix.tags.swing")) { - //if it is a table - if (child.getClassDescriptor().getName() != null && child.getClassDescriptor().getName().equals("Table")) { - //the table is represented by a JPanel - jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE, - "com.google.gwt.user.client.ui.FlexTable", + if (child.getClassDescriptor().getPackageName() == null + && TagManager.getGuixClassHandler(child.getClassDescriptor().getName()) != null) { + if(TagManager.getGuixClassHandler(child.getClassDescriptor().getName()).getClassToGenerate() != null) { + jf.addField(new JavaField(Modifier.PRIVATE, + TagManager.getGuixClassHandler(child.getClassDescriptor().getName()).getClassToGenerate().getName(), child.getId(), child.getJavadoc()), - false); + gmo.isJavaBean()); } } else { - jf.addField(new JavaField(Modifier.FINAL | Modifier.PRIVATE, - (classes != null && classes.containsKey(child.getClassDescriptor().toString())) ? child.getClassDescriptor().getName() + "Abstract" : child.getClassDescriptor().getName(), - child.getId(), child.getJavadoc()), - false); + jf.addField(new JavaField(Modifier.PRIVATE, + (classes != null && classes.containsKey(child.getClassDescriptor().toString())) ? child.getClassDescriptor().toString() + "Abstract" : child.getClassDescriptor().toString(), + child.getId(), child.getJavadoc()), + gmo.isJavaBean()); } addFields(child); } Modified: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtJavaFileGenerator.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtJavaFileGenerator.java 2009-08-25 10:49:26 UTC (rev 1574) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/generator/GwtJavaFileGenerator.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -41,37 +41,10 @@ @Override /** * Add imports to the generated file - * - * @param gmo GuixModelObject which represents the class to generate */ - protected void addImports(GuixModelObject gmo) { - if(gmo == null) { - return; - } - for (GuixModelObject child : gmo.getChildren()) { - if (child.getClassDescriptor().getPackageName() == null - && TagManager.getGuixClassHandler(child.getClassDescriptor().getName()) != null) { - Class clazz; - try { - clazz = TagManager.getGuixClassHandler(child.getClassDescriptor().getName()).getClassToGenerate(); - if (imports != null && !imports.contains(clazz.getName())) { - imports.add(clazz.getName()); - jf.addImport(clazz); - } - } - catch(NullPointerException eee) { - clazz = null; - } - } - else if (imports != null && !imports.contains(child.getClassDescriptor().toString())) { - imports.add(child.getClassDescriptor().toString()); - jf.addImport(classes.containsKey(child.getClassDescriptor().toString()) ? - child.getClassDescriptor().getPackageName() + "." + - child.getClassDescriptor().getName() + "Abstract" : - child.getClassDescriptor().toString()); - } - addImports(child); - } + protected void addImports() { + + jf.addImport("com.google.gwt.user.client.ui.*"); } } Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/CheckBoxHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/CheckBoxHandler.java (rev 0) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/CheckBoxHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -0,0 +1,27 @@ + +package org.nuiton.guix.tags.gwt; + +import com.google.gwt.user.client.ui.ClickListener; + +/** + * Handles the ChackBox tag + * + * @author kmorin + */ +public class CheckBoxHandler extends UIObjectHandler { + + public CheckBoxHandler() { + super(); + } + + @Override + public Class getClassToGenerate() { + return com.google.gwt.user.client.ui.CheckBox.class; + } + + @Override + protected void configureProxyEventInfo() { + super.configureProxyEventInfo(); + addProxyEventInfo("isChecked", ClickListener.class); + } +} Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ComboBoxHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ComboBoxHandler.java (rev 0) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ComboBoxHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -0,0 +1,26 @@ + +package org.nuiton.guix.tags.gwt; +import com.google.gwt.user.client.ui.ChangeListener; + +/** + * Handles the combobox tag + * + * @author kmorin + */ +public class ComboBoxHandler extends UIObjectHandler { + + public ComboBoxHandler() { + super(); + } + + @Override + public Class getClassToGenerate() { + return com.google.gwt.user.client.ui.ListBox.class; + } + + @Override + protected void configureProxyEventInfo() { + super.configureProxyEventInfo(); + addProxyEventInfo("getSelectedIndex", ChangeListener.class); + } +} Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/DialogBoxHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/DialogBoxHandler.java (rev 0) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/DialogBoxHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -0,0 +1,20 @@ + +package org.nuiton.guix.tags.gwt; + +/** + * Handles DialogBox tag + * + * @author kmorin + */ +public class DialogBoxHandler extends UIObjectHandler { + + public DialogBoxHandler() { + super(); + } + + @Override + public Class getClassToGenerate() { + return com.google.gwt.user.client.ui.DialogBox.class; + } + +} Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/HorizontalSplitPanelHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/HorizontalSplitPanelHandler.java (rev 0) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/HorizontalSplitPanelHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -0,0 +1,20 @@ + +package org.nuiton.guix.tags.gwt; + +/** + * Handles HorizontalSplitPanel tag + * + * @author kmorin + */ +public class HorizontalSplitPanelHandler extends UIObjectHandler { + + public HorizontalSplitPanelHandler() { + super(); + } + + @Override + public Class getClassToGenerate() { + return com.google.gwt.user.client.ui.HorizontalSplitPanel.class; + } + +} Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ListHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ListHandler.java (rev 0) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ListHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -0,0 +1,20 @@ + +package org.nuiton.guix.tags.gwt; + +/** + * Handles the List tag + * + * @author kmorin + */ +public class ListHandler extends UIObjectHandler { + + public ListHandler() { + super(); + } + + @Override + public Class getClassToGenerate() { + return com.google.gwt.user.client.ui.ListBox.class; + } + +} Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/PasswordFieldHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/PasswordFieldHandler.java (rev 0) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/PasswordFieldHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -0,0 +1,19 @@ + +package org.nuiton.guix.tags.gwt; + +/** + * Handles the PasswordField tag + * + * @author kmorin + */ +public class PasswordFieldHandler extends TextFieldHandler { + + public PasswordFieldHandler() { + super(); + } + + @Override + public Class getClassToGenerate() { + return com.google.gwt.user.client.ui.PasswordTextBox.class; + } +} Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ProgressBarHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ProgressBarHandler.java (rev 0) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ProgressBarHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -0,0 +1,20 @@ + +package org.nuiton.guix.tags.gwt; + +/** + * Handles the ProgressBar tag + * + * @author kmorin + */ +public class ProgressBarHandler extends UIObjectHandler { + + public ProgressBarHandler() { + super(); + } + + @Override + public Class getClassToGenerate() { + return org.gwtwidgets.client.ui.ProgressBar.class; + } + +} Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/RadioButtonHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/RadioButtonHandler.java (rev 0) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/RadioButtonHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -0,0 +1,19 @@ + +package org.nuiton.guix.tags.gwt; + +/** + * Handles the RadioButton tag + * + * @author kmorin + */ +public class RadioButtonHandler extends CheckBoxHandler { + + public RadioButtonHandler() { + super(); + } + + @Override + public Class getClassToGenerate() { + return com.google.gwt.user.client.ui.RadioButton.class; + } +} Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ScrollPanelHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ScrollPanelHandler.java (rev 0) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/ScrollPanelHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -0,0 +1,20 @@ + +package org.nuiton.guix.tags.gwt; + +/** + * Handles the ScrollPanel tag + * + * @author kmorin + */ +public class ScrollPanelHandler extends UIObjectHandler { + + public ScrollPanelHandler() { + super(); + } + + @Override + public Class getClassToGenerate() { + return com.google.gwt.user.client.ui.ScrollPanel.class; + } + +} Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TabHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TabHandler.java (rev 0) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TabHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -0,0 +1,16 @@ + +package org.nuiton.guix.tags.gwt; +import org.nuiton.guix.tags.DefaultTagHandler; + +/** + * + * @author kmorin + */ +public class TabHandler extends DefaultTagHandler { + + @Override + public Class getClassToGenerate() { + return null; + } + +} Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TextAreaHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TextAreaHandler.java (rev 0) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TextAreaHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -0,0 +1,16 @@ + +package org.nuiton.guix.tags.gwt; + +/** + * Handles the TextArea tag + * + * @author kmorin + */ +public class TextAreaHandler extends TextFieldHandler { + + @Override + public Class getClassToGenerate() { + return com.google.gwt.user.client.ui.TextArea.class; + } + +} 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-08-25 10:49:26 UTC (rev 1574) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TextFieldHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -17,7 +17,6 @@ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ package org.nuiton.guix.tags.gwt; - import com.google.gwt.user.client.ui.KeyboardListener; /** @@ -40,7 +39,7 @@ } @Override - public void configureProxyEventInfo() { + protected void configureProxyEventInfo() { super.configureProxyEventInfo(); addProxyEventInfo("getText", KeyboardListener.class); } Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TreeHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TreeHandler.java (rev 0) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TreeHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -0,0 +1,26 @@ + +package org.nuiton.guix.tags.gwt; +import com.google.gwt.user.client.ui.TreeListener; + +/** + * Handles the tree tag + * + * @author kmorin + */ +public class TreeHandler extends UIObjectHandler { + + public TreeHandler() { + super(); + } + + @Override + public Class getClassToGenerate() { + return com.google.gwt.user.client.ui.Tree.class; + } + + @Override + protected void configureProxyEventInfo() { + super.configureProxyEventInfo(); + addProxyEventInfo("getSelectedItem", TreeListener.class); + } +} Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TreeNodeHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TreeNodeHandler.java (rev 0) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/TreeNodeHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -0,0 +1,19 @@ + +package org.nuiton.guix.tags.gwt; + +/** + * + * @author kmorin + */ +public class TreeNodeHandler extends UIObjectHandler { + + public TreeNodeHandler() { + super(); + } + + @Override + public Class getClassToGenerate() { + return com.google.gwt.user.client.ui.TreeItem.class; + } + +} Added: trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/VerticalSplitPanelHandler.java =================================================================== --- trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/VerticalSplitPanelHandler.java (rev 0) +++ trunk/guix-compiler-gwt/src/main/java/org/nuiton/guix/tags/gwt/VerticalSplitPanelHandler.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -0,0 +1,20 @@ + +package org.nuiton.guix.tags.gwt; + +/** + * Handles VerticalSplitPanel tag + * + * @author kmorin + */ +public class VerticalSplitPanelHandler extends UIObjectHandler { + + public VerticalSplitPanelHandler() { + super(); + } + + @Override + public Class getClassToGenerate() { + return com.google.gwt.user.client.ui.VerticalSplitPanel.class; + } + +} Modified: trunk/guix-compiler-gwt/src/test/java/org/nuiton/guix/generator/GwtGeneratorTest.java =================================================================== --- trunk/guix-compiler-gwt/src/test/java/org/nuiton/guix/generator/GwtGeneratorTest.java 2009-08-25 10:49:26 UTC (rev 1574) +++ trunk/guix-compiler-gwt/src/test/java/org/nuiton/guix/generator/GwtGeneratorTest.java 2009-08-25 10:50:11 UTC (rev 1575) @@ -19,7 +19,6 @@ package org.nuiton.guix.generator; import org.nuiton.guix.*; -import com.google.gwt.user.client.ui.ClickListener; import com.google.gwt.user.client.ui.ToggleButton; import java.lang.reflect.Modifier; import java.util.HashMap; @@ -49,117 +48,117 @@ @Test public void testGenerateBinding() { - GwtGuixInitializer.initialize(); - GwtGenerator gg = new GwtGenerator(); - //tests the not null condition for the parameters that needs to be not null - List<Class> l = gg.generateBindings(null, new StringBuffer(), null, null, Class.class, new String[0], 0, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(), 0); - l = gg.generateBindings(new StringBuffer(), null, null, null, Class.class, new String[0], 0, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(), 0); - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, null, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(), 0); - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], -1, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(), 0); - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], -1, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(), 0); - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], 0, null, null, new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(), 0); - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], 0, null, "", null); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(), 0); - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, null, new String[0], 0, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(), 0); - //tests with a class parameter not null - //tests if a null listener as result returns null - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, ToggleButton.class, new String[]{"isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNull(l); - //tests a successful generation with a method as a binding - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(),1); - Assert.assertNotNull(l.get(0)); - Assert.assertEquals(l.get(0),ClickListener.class); - //tests a successful generation with an attribute as a binding - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"down"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(),1); - Assert.assertNotNull(l.get(0)); - Assert.assertEquals(l.get(0),ClickListener.class); - //tests a successful generation with a method with the generic name as a binding - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"isSelected()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(),1); - Assert.assertNotNull(l.get(0)); - Assert.assertEquals(l.get(0),ClickListener.class); - //tests a successful generation with an attribute with the generic name as a binding - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"selected"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(),1); - Assert.assertNotNull(l.get(0)); - Assert.assertEquals(l.get(0),ClickListener.class); - - //tests with a javafile parameter not null - //tests if the result is null without the taghandler associated to the field - JavaFile jf = new JavaFile(); - jf.addField(new JavaField(Modifier.PRIVATE, "com.google.gwt.user.client.ui.ToggleButton", "button", null)); - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "com.google.gwt.user.client.ui.ToggleButton", "getButton", null, null, "", null)); - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getButton()", "isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNull(l); - //tests a successful generation with a method as a binding - jf = new JavaFile(); - jf.addField(new JavaField(Modifier.PRIVATE, "com.google.gwt.user.client.ui.ToggleButton", "button", null, new ToggleButtonHandler())); - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "com.google.gwt.user.client.ui.ToggleButton", "getButton", null, null, "", null)); - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getButton()", "isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(),1); - Assert.assertNotNull(l.get(0)); - Assert.assertEquals(l.get(0),ClickListener.class); - //tests a successful generation with an attribute as a binding - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"button","down"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(),1); - Assert.assertNotNull(l.get(0)); - Assert.assertEquals(l.get(0),ClickListener.class); - - //tests with a javafile parameter not null with an attribute whose type is another generated file - //tests if the result is null without the taghandler associated to the field - jf = new JavaFile(); - jf.addField(new JavaField(Modifier.PRIVATE, "test.Test", "test", null)); - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "test.Test", "getTest", null, null, "", null)); - JavaFile jf2 = new JavaFile(Modifier.PUBLIC, JavaFile.CLASS, "test", "Test", null, null); - jf2.addField(new JavaField(Modifier.PRIVATE, "com.google.gwt.user.client.ui.ToggleButton", "button", null)); - jf2.addMethod(new JavaMethod(Modifier.PUBLIC, "com.google.gwt.user.client.ui.ToggleButton", "getButton", null, null, "", null)); - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()","isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(), 0); - //test without jf2 in the map of generators with JavaFile - jf2 = new JavaFile(Modifier.PUBLIC, JavaFile.CLASS, "test", "Test", null, null); - jf2.addField(new JavaField(Modifier.PRIVATE, "com.google.gwt.user.client.ui.ToggleButton", "button", null, new ToggleButtonHandler())); - jf2.addMethod(new JavaMethod(Modifier.PUBLIC, "com.google.gwt.user.client.ui.ToggleButton", "getButton", null, null, "", null)); - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()","isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(), 0); - Map<GuixGenerator,JavaFile> map = new HashMap<GuixGenerator, JavaFile>(); - map.put(gg, jf2); - //tests a successful generation with a method as a binding - l =gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()", "isDown()"}, 0, null, "", map); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(),1); - Assert.assertNotNull(l.get(0)); - Assert.assertEquals(l.get(0),ClickListener.class); - //tests a successful generation with an attribute as a binding - l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"test","button","down"}, 0, null, "", map); - Assert.assertNotNull(l); - Assert.assertEquals(l.size(),1); - Assert.assertNotNull(l.get(0)); - Assert.assertEquals(l.get(0),ClickListener.class); +// GwtGuixInitializer.initialize(); +// GwtGenerator gg = new GwtGenerator(); +// //tests the not null condition for the parameters that needs to be not null +// List<Class> l = gg.generateBindings(null, new StringBuffer(), null, null, Class.class, new String[0], 0, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(), 0); +// l = gg.generateBindings(new StringBuffer(), null, null, null, Class.class, new String[0], 0, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(), 0); +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, null, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(), 0); +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], -1, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(), 0); +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], -1, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(), 0); +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], 0, null, null, new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(), 0); +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, Class.class, new String[0], 0, null, "", null); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(), 0); +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, null, new String[0], 0, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(), 0); +// //tests with a class parameter not null +// //tests if a null listener as result returns null +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, null, ToggleButton.class, new String[]{"isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNull(l); +// //tests a successful generation with a method as a binding +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(),1); +// Assert.assertNotNull(l.get(0)); +// Assert.assertEquals(l.get(0),ClickHandler.class); +// //tests a successful generation with an attribute as a binding +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"down"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(),1); +// Assert.assertNotNull(l.get(0)); +// Assert.assertEquals(l.get(0),ClickHandler.class); +// //tests a successful generation with a method with the generic name as a binding +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"isSelected()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(),1); +// Assert.assertNotNull(l.get(0)); +// Assert.assertEquals(l.get(0),ClickHandler.class); +// //tests a successful generation with an attribute with the generic name as a binding +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), new ToggleButtonHandler(), null, ToggleButton.class, new String[]{"selected"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(),1); +// Assert.assertNotNull(l.get(0)); +// Assert.assertEquals(l.get(0),ClickHandler.class); +// +// //tests with a javafile parameter not null +// //tests if the result is null without the taghandler associated to the field +// JavaFile jf = new JavaFile(); +// jf.addField(new JavaField(Modifier.PRIVATE, "com.google.gwt.user.client.ui.ToggleButton", "button", null)); +// jf.addMethod(new JavaMethod(Modifier.PUBLIC, "com.google.gwt.user.client.ui.ToggleButton", "getButton", null, null, "", null)); +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getButton()", "isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNull(l); +// //tests a successful generation with a method as a binding +// jf = new JavaFile(); +// jf.addField(new JavaField(Modifier.PRIVATE, "com.google.gwt.user.client.ui.ToggleButton", "button", null, new ToggleButtonHandler())); +// jf.addMethod(new JavaMethod(Modifier.PUBLIC, "com.google.gwt.user.client.ui.ToggleButton", "getButton", null, null, "", null)); +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getButton()", "isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(),1); +// Assert.assertNotNull(l.get(0)); +// Assert.assertEquals(l.get(0),ClickHandler.class); +// //tests a successful generation with an attribute as a binding +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"button","down"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(),1); +// Assert.assertNotNull(l.get(0)); +// Assert.assertEquals(l.get(0),ClickHandler.class); +// +// //tests with a javafile parameter not null with an attribute whose type is another generated file +// //tests if the result is null without the taghandler associated to the field +// jf = new JavaFile(); +// jf.addField(new JavaField(Modifier.PRIVATE, "test.Test", "test", null)); +// jf.addMethod(new JavaMethod(Modifier.PUBLIC, "test.Test", "getTest", null, null, "", null)); +// JavaFile jf2 = new JavaFile(Modifier.PUBLIC, JavaFile.CLASS, "test", "Test", null, null); +// jf2.addField(new JavaField(Modifier.PRIVATE, "com.google.gwt.user.client.ui.ToggleButton", "button", null)); +// jf2.addMethod(new JavaMethod(Modifier.PUBLIC, "com.google.gwt.user.client.ui.ToggleButton", "getButton", null, null, "", null)); +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()","isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(), 0); +// //test without jf2 in the map of generators with JavaFile +// jf2 = new JavaFile(Modifier.PUBLIC, JavaFile.CLASS, "test", "Test", null, null); +// jf2.addField(new JavaField(Modifier.PRIVATE, "com.google.gwt.user.client.ui.ToggleButton", "button", null, new ToggleButtonHandler())); +// jf2.addMethod(new JavaMethod(Modifier.PUBLIC, "com.google.gwt.user.client.ui.ToggleButton", "getButton", null, null, "", null)); +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()","isDown()"}, 0, null, "", new HashMap<GuixGenerator, JavaFile>()); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(), 0); +// Map<GuixGenerator,JavaFile> map = new HashMap<GuixGenerator, JavaFile>(); +// map.put(gg, jf2); +// //tests a successful generation with a method as a binding +// l =gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"getTest()","getButton()", "isDown()"}, 0, null, "", map); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(),1); +// Assert.assertNotNull(l.get(0)); +// Assert.assertEquals(l.get(0),ClickHandler.class); +// //tests a successful generation with an attribute as a binding +// l = gg.generateBindings(new StringBuffer(), new StringBuffer(), null, jf, null, new String[]{"test","button","down"}, 0, null, "", map); +// Assert.assertNotNull(l); +// Assert.assertEquals(l.size(),1); +// Assert.assertNotNull(l.get(0)); +// Assert.assertEquals(l.get(0),ClickHandler.class); } }
participants (1)
-
kmorin@users.nuiton.org