r2065 - in trunk/jaxx-compiler/src/main/java/jaxx/compiler: . tags/swing
Author: tchemit Date: 2010-09-06 15:01:38 +0200 (Mon, 06 Sep 2010) New Revision: 2065 Url: http://nuiton.org/repositories/revision/jaxx/2065 Log: Evolution #854: Can add the columnHeaderView component in the tag JScrollPane + reformat code Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JScrollPaneHandler.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2010-09-06 12:55:58 UTC (rev 2064) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2010-09-06 13:01:38 UTC (rev 2065) @@ -31,6 +31,8 @@ import jaxx.compiler.tags.DefaultComponentHandler; import jaxx.compiler.tags.TagHandler; import jaxx.compiler.tags.TagManager; +import jaxx.compiler.types.TypeManager; +import org.apache.commons.lang.StringUtils; import java.awt.Container; import java.lang.reflect.Method; @@ -39,9 +41,6 @@ import java.util.List; import java.util.Map; -import jaxx.compiler.types.TypeManager; -import org.apache.commons.lang.StringUtils; - /** * Represents an object in the <code>.java</code> file being generated during compilation. There is * a <code>CompiledObject</code> for each class tag encountered, and certain tags may generate @@ -49,94 +48,91 @@ */ public class CompiledObject { - /** - * The object's id. - */ + /** The object's id. */ private String id; - /** - * Java code referring to the object. - */ + + /** Java code referring to the object. */ private String javaCode; - /** - * The object's class. - */ + + /** The object's class. */ private ClassDescriptor objectClass; - /** - * The style class. - */ + + /** The style class. */ private String styleClass; - /** - * The container containing this CompiledObject. - */ + + /** The container containing this CompiledObject. */ private CompiledObject parent; + /** * true if this object overrides an object of the same id in a superclass * of the object being compiled */ private boolean override; + /** - * Comma-separated Java code snippets representing the parameters that + * Comma-separated Java code snippets representing the parameters that * should be passed to the object's constructor. */ private String constructorParams; + /** * Java code snippet which performs basic initialization of the object (after it has already been constructed). * Because CompiledObject initialization order cannot be guaranteed, it is not safe to refer to other * CompiledObjects from initializationCode -- you must refer to them from additionCode instead. */ private StringBuffer initializationCode = new StringBuffer(); + /** * Java code snippet which completes setup by adding any child objects, or otherwise manipulates any refererenced * objects. Because CompiledObject initialization order cannot be guaranteed, it is not safe to refer to other * CompiledObjects from initializationCode -- you must refer to them from additionCode instead. */ private StringBuffer additionCode = new StringBuffer(); - /** - * List of all registered event handlers. - */ + + /** List of all registered event handlers. */ private List<EventHandler> eventHandlers = new ArrayList<EventHandler>(); - /** - * All properties that have been applied to this CompiledObject. - */ + + /** All properties that have been applied to this CompiledObject. */ private Map<String, String> properties = new HashMap<String, String>(); - /** - * generic types of the compiled object - */ + + /** generic types of the compiled object */ private String[] genericTypes; + /** * a flag to indicate if javaBean full support must be support for this * object by root object */ private boolean javaBean; - /** - * code to initialize the bean (can be null) - */ + + /** code to initialize the bean (can be null) */ private String javaBeanInitCode; - /** - * the type of the override object (can be null if no overide) - */ + + /** the type of the override object (can be null if no overide) */ private ClassDescriptor overrideType; - /** - * the decorator - */ + + /** the decorator */ private CompiledObjectDecorator decorator; - /** - * client properties - */ + + /** client properties */ private Map<String, String> clientProperties; - /** - * initializer of the object - */ + + /** initializer of the object */ private String initializer; public class ChildRef { CompiledObject child; + String constraints; + String childJavaCode; + private String delegateCode; - public ChildRef(CompiledObject child, String constraints, String childJavaCode, String delegateCode) { + public ChildRef(CompiledObject child, + String constraints, + String childJavaCode, + String delegateCode) { this.child = child; this.constraints = constraints; this.childJavaCode = childJavaCode; @@ -155,7 +151,8 @@ this.childJavaCode = childJavaCode; } - public void addToAdditionCode(StringBuffer buffer, boolean isRootObject) { + public void addToAdditionCode(StringBuffer buffer, + boolean isRootObject) { //TC-20091026 do not prefix if on root object String prefix; if (isRootObject) { @@ -164,18 +161,30 @@ prefix = javaCode + delegateCode + "."; } if (constraints != null) { - buffer.append(prefix).append("add(").append(childJavaCode).append(", ").append(constraints).append(");"); + buffer.append(prefix); + buffer.append("add("); + buffer.append(childJavaCode); + buffer.append(", "); + buffer.append(constraints); + buffer.append(");"); } else { - buffer.append(prefix).append("add(").append(childJavaCode).append(");"); + buffer.append(prefix); + buffer.append("add("); + buffer.append(childJavaCode); + buffer.append(");"); } buffer.append(JAXXCompiler.getLineSeparator()); } } + private List<ChildRef> childs; /** - * Creates a new <code>CompiledObject</code>. To be useful, the object should be registered with a - * <code>JAXXCompiler</code> using {@link JAXXCompiler#registerCompiledObject registerCompiledObject}. + * Creates a new <code>CompiledObject</code>. + * <p/> + * To be useful, the object should be registered with a + * <code>JAXXCompiler</code> using + * {@link JAXXCompiler#registerCompiledObject registerCompiledObject}. * * @param id the object's id * @param objectClass the object's class @@ -260,7 +269,7 @@ } /** - * True if this object overrides an object in the superclass of the class + * True if this object overrides an object in the superclass of the class * being compiled. For this to be true, the class currently being compiled * must be a subclass of another <code>JAXXObject</code> which has an * identically-named object. @@ -325,7 +334,7 @@ * Sets this object's parent container. * * @param parent the parent container - * @throws IllegalArgumentException if parent is not a {@link Container} + * @throws IllegalArgumentException if parent is not a {@link Container} */ public void setParent(CompiledObject parent) throws IllegalArgumentException { if (!ClassDescriptorHelper.getClassDescriptor(Container.class).isAssignableFrom(parent.getObjectClass())) { @@ -347,7 +356,7 @@ } /** - * Returns the name of the method that should be generated in the compiled + * Returns the name of the method that should be generated in the compiled * <code>.java</code> file in order to add children to this object. This * is just a suggestion and may be ignored. * @@ -378,7 +387,7 @@ } /** - * Returns Java code used to refer to this object in the compiled Java file. + * Returns Java code used to refer to this object in the compiled Java file. * This is usually the same as its id. * * @return the Java code for this object @@ -415,7 +424,7 @@ } /** - * Returns a list of comma-separated Java code snippets that represent the + * Returns a list of comma-separated Java code snippets that represent the * parameters to pass to this object's constructor. * * @return the raw constructor params @@ -429,7 +438,7 @@ * Sets the parameters to pass to this object's constructor. * * @param constructorParams comma-separated Java code snippets representing - * constructor params + * constructor params * @see #getConstructorParams */ public void setConstructorParams(String constructorParams) { @@ -447,7 +456,7 @@ /** * Returns the code that performs basic initialization of this object, * after it has already been constructed. - * This basic code should not reference any other + * This basic code should not reference any other * <code>CompiledObjects</code> as they may not have been created yet. * * @param compiler compiler to use @@ -468,8 +477,8 @@ //TC-20091026 use 'this' instead of root object javaCode //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple name return getJavaCode() + '.' + addMethod.getName() + "(JAXXUtil.getEventListener(" + listenerClass.getSimpleName() + ".class, " + - TypeManager.getJavaCode(handler.getListenerMethod().getName()) + ", this, " + - TypeManager.getJavaCode(compiler.getEventHandlerMethodName(handler)) + "));" + JAXXCompiler.getLineSeparator(); + TypeManager.getJavaCode(handler.getListenerMethod().getName()) + ", this, " + + TypeManager.getJavaCode(compiler.getEventHandlerMethodName(handler)) + "));" + JAXXCompiler.getLineSeparator(); } /** @@ -512,7 +521,7 @@ } /** - * Stores a property for this object. The only effect of calling this + * Stores a property for this object. The only effect of calling this * method is that the property will be returned by {@code getProperties()}. * * @param property the name of the property @@ -556,7 +565,12 @@ } // TODO: remove this temporary method and complete switchover to MethodDescriptors - public void addEventHandler(String eventId, Method addMethod, Method listenerMethod, String code, JAXXCompiler compiler) { + + public void addEventHandler(String eventId, + Method addMethod, + Method listenerMethod, + String code, + JAXXCompiler compiler) { try { ClassDescriptor descriptor = ClassDescriptorHelper.getClassDescriptor(getObjectClass().getName()); String listenerClassName = addMethod.getParameterTypes()[0].getName(); @@ -580,14 +594,26 @@ * @param compiler the current <code>JAXXCompiler</code> * @see #getInitializationCode */ - public void addEventHandler(String eventId, MethodDescriptor addMethod, MethodDescriptor listenerMethod, String code, JAXXCompiler compiler) { - EventHandler handler = new EventHandler(getId() + "." + eventId, getJavaCode(), addMethod, addMethod.getParameterTypes()[0], listenerMethod, code); + public void addEventHandler(String eventId, + MethodDescriptor addMethod, + MethodDescriptor listenerMethod, + String code, + JAXXCompiler compiler) { + EventHandler handler = new EventHandler( + getId() + "." + eventId, + getJavaCode(), + addMethod, + addMethod.getParameterTypes()[0], + listenerMethod, + code + ); compiler.registerEventHandler(handler); eventHandlers.add(handler); if (getJavaCode().contains(".")) { // object lives in another JAXX file and consequently its initialization code won't be output - compiler.appendInitializerCode(getInitializationCode(handler, compiler)); + compiler.appendInitializerCode( + getInitializationCode(handler, compiler)); } } @@ -600,12 +626,13 @@ * @throws CompilerException if this object is not a container * @see #addChild(CompiledObject, String, JAXXCompiler) */ - public void addChild(CompiledObject child, JAXXCompiler compiler) throws CompilerException { + public void addChild(CompiledObject child, + JAXXCompiler compiler) throws CompilerException { addChild(child, null, compiler); } /** - * Adds a child component to this container. This variant allows the Java + * Adds a child component to this container. This variant allows the Java * code for a layout constraints object to be specified. * * @param child the component to add @@ -614,28 +641,38 @@ * @throws CompilerException if this object is not a container * @see #addChild(CompiledObject, JAXXCompiler) */ - public void addChild(CompiledObject child, String constraints, JAXXCompiler compiler) throws CompilerException { + public void addChild(CompiledObject child, + String constraints, + JAXXCompiler compiler) throws CompilerException { try { if (constraints != null) { constraints = compiler.checkJavaCode(constraints); } } catch (CompilerException e) { - compiler.reportError("While parsing 'constraints' attribute: " + e.getMessage()); + compiler.reportError( + "While parsing 'constraints' attribute: " + e.getMessage()); } if (!child.isOverride()) { TagHandler tagHandler = TagManager.getTagHandler(getObjectClass()); if (tagHandler instanceof DefaultComponentHandler && - !((DefaultComponentHandler) tagHandler).isContainer()) { + !((DefaultComponentHandler) tagHandler).isContainer()) { compiler.reportError("component " + this + " may not have children"); } String containerDelegate = ((DefaultComponentHandler) tagHandler).getContainerDelegate(); - String delegateCode = containerDelegate != null ? "." + containerDelegate + "()" : ""; + String delegateCode = containerDelegate != null ? + "." + containerDelegate + "()" : + ""; child.setParent(this); - childs.add(new ChildRef(child, constraints, child.getJavaCode(), delegateCode)); + ChildRef ref = new ChildRef(child, + constraints, + child.getJavaCode(), + delegateCode + ); + childs.add(ref); } } @@ -710,7 +747,8 @@ // compute additionCode for all childs StringBuffer buffer = new StringBuffer(); for (ChildRef childRef : refList) { - childRef.addToAdditionCode(buffer, equals(compiler.getRootObject())); + childRef.addToAdditionCode(buffer, + equals(compiler.getRootObject())); } additionCode = buffer.append(additionCode); } @@ -721,6 +759,6 @@ } public String getGetterName() { - return "get"+StringUtils.capitalize(id); + return "get" + StringUtils.capitalize(id); } } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JScrollPaneHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JScrollPaneHandler.java 2010-09-06 12:55:58 UTC (rev 2064) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JScrollPaneHandler.java 2010-09-06 13:01:38 UTC (rev 2065) @@ -25,39 +25,80 @@ package jaxx.compiler.tags.swing; +import jaxx.compiler.CompiledObject; import jaxx.compiler.CompilerException; -import jaxx.compiler.CompiledObject; import jaxx.compiler.JAXXCompiler; import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorHelper; import jaxx.compiler.tags.DefaultComponentHandler; +import org.apache.commons.lang.StringUtils; import javax.swing.JScrollPane; public class JScrollPaneHandler extends DefaultComponentHandler { - public JScrollPaneHandler(ClassDescriptor beanClass) { - super(beanClass); - ClassDescriptorHelper.checkSupportClass(getClass(), beanClass, JScrollPane.class); - } + public static class JScrollPaneCompiledObject extends CompiledObject { - @Override - public CompiledObject createCompiledObject(String id, JAXXCompiler compiler) throws CompilerException { - return new CompiledObject(id, getBeanClass(), compiler) { + boolean hasChild; - boolean hasChild; + boolean hasColumnViewHeader; - @Override - public void addChild(CompiledObject child, String constraints, JAXXCompiler compiler) throws CompilerException { - if (constraints != null) { - compiler.reportError("JScrollPane does not accept constraints"); - } - if (hasChild) { - compiler.reportError("JScrollPane may only have one child"); - } + public static final String COLUMN_HEADER_VIEW = "columnHeaderView"; + + public JScrollPaneCompiledObject(String id, + ClassDescriptor beanclass, + JAXXCompiler compiler) { + super(id, beanclass, compiler); + } + + @Override + public void addChild(CompiledObject child, + String constraints, + JAXXCompiler compiler) throws CompilerException { + if (constraints != null) { + compiler.reportError("JScrollPane does not accept constraints"); + } + + if (!hasChild) { + // first child is always the view port component super.addChild(child, constraints, compiler); hasChild = true; + return; } - }; + + if (!hasColumnViewHeader) { + + // try to add a column view header + String property = + (String) getProperties().get(COLUMN_HEADER_VIEW); + + if (log.isDebugEnabled()) { + log.info("property to match " + property + " against child " + child.getId()); + } + if (!StringUtils.isEmpty(property) && + ("{" + child.getId() + "}").equals(property)) { + hasColumnViewHeader = true; + return; + } + } + + compiler.reportError( + "JScrollPane may only have one child (found another child : " + child.getId() + ")."); + + } } + + public JScrollPaneHandler(ClassDescriptor beanClass) { + super(beanClass); + ClassDescriptorHelper.checkSupportClass(getClass(), + beanClass, + JScrollPane.class + ); + } + + @Override + public CompiledObject createCompiledObject(String id, + JAXXCompiler compiler) throws CompilerException { + return new JScrollPaneCompiledObject(id, getBeanClass(), compiler); + } }
participants (1)
-
tchemit@users.nuiton.org