You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by calathus <ca...@gmail.com> on 2010/12/20 04:26:22 UTC

[pivot] are there any tools to convert bxml to Java?

Hi,
I'm looking for a tool to convert bxml file to equivalent Java source
program.
Are there such tools?

I just started using pivot, but many of sample is based on bxml.
I think in order to develop a UI library with Java generic class, XML file
based approach is not appropriate.

And xml based approach will reduce static error detection capability.
I liked to see  more examples using  Java classes to define GUI without
relying on bxml files.

-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Chris Bartlett <cb...@gmail.com>.
Pivot does not include a tool to convert WTKX/BXML into Java source, but if
you take a look at the WTKX/BXML Primer pages, you will see how Pivot
processes WTKX/BXML and therefore how you could convert to source if you
wanted.

For instance...
java packages = wtkx/bxml namespaces
java classes = elements starting with an upper case character / create new
object
java class bean properties = elements starting with a lower case character

Reference for Pivot 1.5.2 and earlier releases (WTKX)
http://pivot.apache.org/tutorials/wtkx-primer.html

Pre-release reference documentation for Pivot 2.0 (BXML)
http://ixnay.biz/pivot-tutorials/bxml-primer.html

The source for BXMLSerializer might also prove to be helpful if you did want
to write such a tool.  You might be able to extend or modify it without too
much effort in order to spit out java source, or at least some data that
could then be post-processed.
http://svn.apache.org/repos/asf/pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java

Chris

On 20 December 2010 10:26, calathus <ca...@gmail.com> wrote:

> Hi,
> I'm looking for a tool to convert bxml file to equivalent Java source
> program.
> Are there such tools?
>
> I just started using pivot, but many of sample is based on bxml.
> I think in order to develop a UI library with Java generic class, XML file
> based approach is not appropriate.
>
> And xml based approach will reduce static error detection capability.
> I liked to see  more examples using  Java classes to define GUI without
> relying on bxml files.
>
> --
> Cheers,
> calathus
>
>
>
>

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
In order to make GenericTableView work in BXML at all, you'd need to move the Class<T> argument from the constructor to a property. You could do something like:

public Class<?> getBeanType();
public void setBeanType(Class<?> beanType);
public void setBeanType(String beanType);

The String overload of setBeanType() would simply call class.forName() internally, so you could do this in your BXML:

<GenericTableView beanType="com.foo.MyBean"/>

Alternatively, since it is really just being used to initialize the columns, perhaps this would be more appropriate:

public void setColumns(Class<?> beanType);
public void setColumns(String beanType);

Then you could potentially attach annotations to each property (via the getter method) to return things like default column width, etc. 

G

On Jan 4, 2011, at 12:47 PM, Gerrick Bivins wrote:

> +1 for this example!
>  I had been thinking about something like this as well to simplify creating table views for java Beans, ie, dynamically creating the table columns based on properties. This addresses part of what I was trying to do.
> What would really be slick is if that Class parameter in the constructor could be made Bindable so it could dynamically specified via BXML ala:
> 
> ...
> <bxml:define>
>    <Class bxml:id="beanClass">
> </bxml:define>
> ...
> <GenericTableView class="$beanClass" ...>
> ...
> 
> 
> Gerrick
> 
> 
> On Tue, Jan 4, 2011 at 11:11 AM, calathus <ca...@gmail.com> wrote:
> 
> 
> On Mon, Dec 20, 2010 at 5:54 PM, Greg Brown <gk...@verizon.net> wrote:
> > My goal was to create a generic class to support CRUD GUI from a given Java Beans class. Although it is not generic version, Vaadin provides such sample implementation which may be  immediately used for real projects.
> 
> I'd be interested in learning more about how you envision something like this might work.
> 
> Greg,
> 
> I created a sample generic  TableView class which can take a parameter bean class and using the reflection library, it defines table view's column fields. This class is modified from tutorials tableviews sample.
> This is only for demonstration of the generic class approach in Pivot using builder class approach.
> 
> In general, if we introduce new annotations for entity beans class to define more presentation related information (like width of column) , we can fine tune the look and feels.
> And the same entity beans can have another JPA annotation from which DB scheme can be generated and also some utility (like in netbeans) will allow to generate restful API from the entity beans. 
> 
> So if we define more GUI feature to support CRUD operation as generic class library, it become very simple to develop DB based web application.
> There is an  open source project called openxava which has similar approach, but its GUI is based on JSP and not so impressive compared to other GUI(web) projects.
> The degree of usability of such generic library may not be so general, but if there are a lot of entity classes, this type of approach would be quite useful.
> Also the pattern of these class may be used as starting point for other type of CRUD GUI.
> 
> Following is the sample code:
> 
>     public static class GenericTableView<T> extends TableView {
>     	
>     	private final Class<T> cls;
>     	
>     	public GenericTableView(final Class<T> cls, final Map<String, Object> namespace) throws Exception {
>     		this.cls = cls;
> 
>             for (final Field field: cls.getFields()) {
>             	final String fname = field.getName();
>             	getColumns().add(new TableView.Column() {{
>             		setName(fname);
>                     setWidth(3, true);                            
>                     if (fname.equals("flag")) {
>                     	setCellRenderer(new TableViewImageCellRenderer() {{
>                     	}}); // INSTANCE, name: <content:TableViewImageCellRenderer>
>                     } else {
>                     	setHeaderData(getCapitalName(fname));
>                     }
>                     System.out.println(">>> fname: "+fname);
>                 }});
>             }
>             getTableViewSortListeners().add(new TableViewSortListener.Adapter() {
>                 @Override
>                 @SuppressWarnings("unchecked")
>                 public void sortChanged(TableView tableView) {
>                 	tableView.getTableData().setComparator(new org.apache.pivot.wtk.content.TableViewRowComparator(tableView));
>                 }
>             });
>         }
>     	
>     	public void add(T... ts) {
>     		for (T t: ts) {
>     			getTableData().add(t);
>     		}
>     	}
>     	
>     	static String getCapitalName(String name) {
>     		if (name.length() == 0) return name;
>     		return Character.toUpperCase(name.charAt(0))+name.substring(1);
>     	}
>     }
>     
>     static java.util.List<OlympicStanding> createOlympicStandings() throws Exception {
>         java.util.List<OlympicStanding> ts = new java.util.ArrayList<OlympicStanding>();
>         
>         // tableViewSortListeners(): LISTENER_LIST_PROPERTY
>         ts.add(new OlympicStanding() {{
>             setNation("China");
>             setGold(51);
>             setSilver(21);
>             setBronze(28);
>             setFlag(new URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/tableviews/cn.png"));
>         }}); // INSTANCE, name: <tableviews:OlympicStanding>
>         ts.add(new OlympicStanding() {{
>             setNation("United States");
>             setGold(36);
>             setSilver(38);
>             setBronze(36);
>             setFlag(new URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/tableviews/us.png"));
>         }}); // INSTANCE, name: <tableviews:OlympicStanding>
>         return ts;
> 	}
>     	
>     static Window create() throws Exception {
>         return new Window() {{
>             final Map<String, Object> namespace = new HashMap<String, Object>();
>             setTitle("Table Views");
>             setMaximized(true);
>             setContent(new Border() {{
>                 setContent(new ScrollPane() {{
>                     setHorizontalScrollBarPolicy(ScrollPane.ScrollBarPolicy.FILL);
>                     setView(new GenericTableView<OlympicStanding>(OlympicStanding.class, namespace){{
>                         namespace.put("tableView", this);
>                         
>                         for (OlympicStanding os: createOlympicStandings()) {
>                     		add(os);
>                     	}
>                     }}); // INSTANCE, name: <TableView>
>                     // columnHeader(): WRITABLE_PROPERTY
>                     setColumnHeader(new TableViewHeader() {{
>                         setTableView((TableView)namespace.get("tableView"));
>                         setSortMode(TableViewHeader.SortMode.MULTI_COLUMN);
>                     }}); // INSTANCE, name: <TableViewHeader>
>                 }}); // INSTANCE, name: <ScrollPane>
>             }}); // INSTANCE, name: <Border>
>             CodeEmitterRuntime.initialize(this, namespace);
>         }};
>     }
> 
>  
> 
> > I wondered if Pivot is really designed to support normal Java class based GUI implementation.
> 
> It most certainly is.  :-)  BXML is just a shortcut to coding your UI by hand. Anything you can do in BXML, you can do in Java (though, in many cases, not quite as conveniently).
> 
> > Regarding to the translator, since there is no detail sample how to use these Java API directly, it would be helpful if we have such bxml to Java translator.
> > But ideally, Pivot site should include more detailed sample/explanation for Java Pivot API based approach(without bxml). Then we would not need such a tool.
> 
> If you read the BXML Primer, you should have a good understanding of how BXML maps to Java. There's no magic to it - it is very straightforward.
> 
> > Also if we may really have declarative GUI design, using Scala may be more attractive way. Scala would allow declaring GUI in equivalent code side as BXML.
> 
> I'm not sure how this would work. Scala is conceptually more akin to Java than markup. Could you elaborate?
> 
> > BTW, I still wonder where the following code went wrong.  I would appreciate your suggestion for the following code(java verson of custom_table_view.bxml).
> > When it is run, it opens the applet window, but it does not show anything.
> 
> Two errors:
> 
> - You need to call border.setContent(scrollPane), not border.add(scrollPane).
> 
> - You need to call scrollPane.setView(tableView). Otherwise, the scroll pane won't know what it's content is.
> 
> I made these changes and the app worked fine.
> 
> G
> 
> 
> 
> 
> 
> -- 
> Cheers,
> calathus
> 
> 
> 
> 


Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
Incidentally, I think this discussion may actually argue in favor of adopting a "table column model" approach. Right now, the "columns" property is read only. If we make it writable, you could simply provide a custom Sequence wrapper around your bean Class<?>. It would also facilitate column model sharing. We currently support that via the "columnSource" property, but maybe the model approach would be better.

On Jan 4, 2011, at 2:45 PM, Greg Brown wrote:

>> > Since these class info is used to initialize the internal attributes and elements of TableView instance, if this class info was set after the generic class instance is created, we need to call some initialization method at the timing.
>> 
>> Can you elaborate on your concern here?
>> 
>> My concern is rather purity of implementation. If we don't call setBeanType(cls), the created object don't have any specific GUI info since it has no info to create it.
> 
> It will still have a GUI - by default, TableView contains an empty column sequence, which is perfectly valid. Calling setColumns(Class<?>) would simply create a new (non-empty) sequence.
> 
>> So the initialization must be taken place at the setter setBeanType(cls), 
>> for instance it will be :
>> 
>> void setBeanType(Class<?> cls) {
>>     this.cls = cls;
>>     initialize();
>> }
>> 
>> void initialize() {
>>     for (final Field field: cls.getFields()) {
>>             	final String fname = field.getName();
>>             	getColumns().add(new TableView.Column() {{
>>             		setName(fname);
>>                     setWidth(3, true);                            
>>                     ....
>> }
> 
> Why not just put the initialize() code in the setter? Nothing else needs to call it.
> 
>> If setter is invoked twice, i will initialize twice (although we can use some flag to avoid this, but I think it is ugly)
> 
> Why would the setter be invoked twice?
> 
>> So conceptually, it is better to pass class object at the time of instance creation.
> 
> That isn't supported in BXML. Anything instantiated in BXML needs a default no-arg constructor - all properties are specified via setters.
> 
> G
> 
> 


Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
On Tue, Jan 4, 2011 at 11:45 AM, Greg Brown <gk...@verizon.net> wrote:

> > Since these class info is used to initialize the internal attributes and
>> elements of TableView instance, if this class info was set after the generic
>> class instance is created, we need to call some initialization method at the
>> timing.
>>
>> Can you elaborate on your concern here?
>>
>
> My concern is rather purity of implementation. If we don't call
> setBeanType(cls), the created object don't have any specific GUI info since
> it has no info to create it.
>
>
> It will still have a GUI - by default, TableView contains an empty column
> sequence, which is perfectly valid. Calling setColumns(Class<?>) would
> simply create a new (non-empty) sequence.
>
> So the initialization must be taken place at the setter setBeanType(cls),
> for instance it will be :
>
> void setBeanType(Class<?> cls) {
>     this.cls = cls;
>     initialize();
> }
>
> void initialize() {
>     for (final Field field: cls.getFields()) {
>              final String fname = field.getName();
>              getColumns().add(new TableView.Column() {{
>              setName(fname);
>                     setWidth(3, true);
>                     ....
> }
>
>
> Why not just put the initialize() code in the setter? Nothing else needs to
> call it.
>
>
> If setter is invoked twice, i will initialize twice (although we can use
> some flag to avoid this, but I think it is ugly)
>
>
> Why would the setter be invoked twice?
>
> So conceptually, it is better to pass class object at the time of instance
> creation.
>
>
> That isn't supported in BXML. Anything instantiated in BXML needs a default
> no-arg constructor - all properties are specified via setters.
>

I prefer to use final for cls property in the generic class so that it won't
be changed, also this is not ordinary property of Java beans, conceptually
it is better to hide from user.
But if you cannot change BXML to support calling constructor with parameters
or just want to use current BXML, setBeanType would work. As I said this is
some purity issue of implementation.

Also if we want to use final properties which is assigned during
constructor, setBeanType approach will have restriction.



>
> G
>
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> > Since these class info is used to initialize the internal attributes and elements of TableView instance, if this class info was set after the generic class instance is created, we need to call some initialization method at the timing.
> 
> Can you elaborate on your concern here?
> 
> My concern is rather purity of implementation. If we don't call setBeanType(cls), the created object don't have any specific GUI info since it has no info to create it.

It will still have a GUI - by default, TableView contains an empty column sequence, which is perfectly valid. Calling setColumns(Class<?>) would simply create a new (non-empty) sequence.

> So the initialization must be taken place at the setter setBeanType(cls), 
> for instance it will be :
> 
> void setBeanType(Class<?> cls) {
>     this.cls = cls;
>     initialize();
> }
> 
> void initialize() {
>     for (final Field field: cls.getFields()) {
>             	final String fname = field.getName();
>             	getColumns().add(new TableView.Column() {{
>             		setName(fname);
>                     setWidth(3, true);                            
>                     ....
> }

Why not just put the initialize() code in the setter? Nothing else needs to call it.

> If setter is invoked twice, i will initialize twice (although we can use some flag to avoid this, but I think it is ugly)

Why would the setter be invoked twice?

> So conceptually, it is better to pass class object at the time of instance creation.

That isn't supported in BXML. Anything instantiated in BXML needs a default no-arg constructor - all properties are specified via setters.

G



Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
On Tue, Jan 4, 2011 at 11:13 AM, Greg Brown <gk...@verizon.net> wrote:

> > But using setBeanType() may not be so good idea.
>
> Did you see my earlier suggestion to use setColumns() rather than
> setBeanType()?
>
Yes, Initially I thought setBeanType is better than setColumns for the
uniformity for generic class, but afterthought, setBeanType seems not so
good idea also.


>
> > Since these class info is used to initialize the internal attributes and
> elements of TableView instance, if this class info was set after the generic
> class instance is created, we need to call some initialization method at the
> timing.
>
> Can you elaborate on your concern here?
>

My concern is rather purity of implementation. If we don't call
setBeanType(cls), the created object don't have any specific GUI info since
it has no info to create it.
So the initialization must be taken place at the setter setBeanType(cls),
for instance it will be :

void setBeanType(Class<?> cls) {
    this.cls = cls;
    initialize();
}

void initialize() {
    for (final Field field: cls.getFields()) {
             final String fname = field.getName();
             getColumns().add(new TableView.Column() {{
             setName(fname);
                    setWidth(3, true);
                    ....
}

If setter is invoked twice, i will initialize twice (although we can use
some flag to avoid this, but I think it is ugly)

So conceptually, it is better to pass class object at the time of instance
creation.


>
> > I think BXML may support passing bean class object by extending the BXML
> syntax also(if that is required).
>
> Not a bad idea - we could add a String to Class<?> conversion in the
> coerce() method of BeanAdapter.
>
>
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> But using setBeanType() may not be so good idea.

Did you see my earlier suggestion to use setColumns() rather than setBeanType()?

> Since these class info is used to initialize the internal attributes and elements of TableView instance, if this class info was set after the generic class instance is created, we need to call some initialization method at the timing.

Can you elaborate on your concern here?

> I think BXML may support passing bean class object by extending the BXML syntax also(if that is required). 

Not a bad idea - we could add a String to Class<?> conversion in the coerce() method of BeanAdapter.




Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
But using setBeanType() may not be so good idea.
Since these class info is used to initialize the internal attributes and
elements of TableView instance, if this class info was set after the generic
class instance is created, we need to call some initialization method at the
timing. This will work, but a bit ugly approach.. I think BXML may support
passing bean class object by extending the BXML syntax also(if that is
required).


On Tue, Jan 4, 2011 at 10:57 AM, calathus <ca...@gmail.com> wrote:

> It would not be possible to define generic table class in BXML, such
> generic classes may be definitely used from  BXML file.
> This is one part of CRUD, one more useful generic class is to generate Form
> GUI class from Java Beans.
> Since there are general pattern, it would be more consistent to use setter
> name setBeanType().
>
>
> On Tue, Jan 4, 2011 at 9:47 AM, Gerrick Bivins <
> gbivins@objectreservoir.com> wrote:
>
>> *+1* for this example!
>>  I had been thinking about something like this as well to simplify
>> creating table views for java Beans, ie, dynamically creating the table
>> columns based on properties. This addresses part of what I was trying to do.
>> What would really be slick is if that Class parameter in the constructor
>> could be made Bindable so it could dynamically specified via BXML ala:
>>
>> ...
>> *<bxml:define>*
>> *   <Class bxml:id="beanClass">*
>> *</bxml:define>*
>> ...
>> *<GenericTableView class="$beanClass" ...>*
>> ...
>>
>>
>> Gerrick
>>
>>
>> On Tue, Jan 4, 2011 at 11:11 AM, calathus <ca...@gmail.com> wrote:
>>
>>>
>>>
>>> On Mon, Dec 20, 2010 at 5:54 PM, Greg Brown <gk...@verizon.net>wrote:
>>>
>>>> > My goal was to create a generic class to support CRUD GUI from a given
>>>> Java Beans class. Although it is not generic version, Vaadin provides such
>>>> sample implementation which may be  immediately used for real projects.
>>>>
>>>> I'd be interested in learning more about how you envision something like
>>>> this might work.
>>>>
>>>
>>> Greg,
>>>
>>> I created a sample generic  TableView class which can take a parameter
>>> bean class and using the reflection library, it defines table view's column
>>> fields. This class is modified from tutorials tableviews sample.
>>> This is only for demonstration of the generic class approach in Pivot
>>> using builder class approach.
>>>
>>> In general, if we introduce new annotations for entity beans class to
>>> define more presentation related information (like width of column) , we can
>>> fine tune the look and feels.
>>> And the same entity beans can have another JPA annotation from which DB
>>> scheme can be generated and also some utility (like in netbeans) will allow
>>> to generate restful API from the entity beans.
>>>
>>> So if we define more GUI feature to support CRUD operation as generic
>>> class library, it become very simple to develop DB based web application.
>>> There is an  open source project called openxava which has similar
>>> approach, but its GUI is based on JSP and not so impressive compared to
>>> other GUI(web) projects.
>>> The degree of usability of such generic library may not be so general,
>>> but if there are a lot of entity classes, this type of approach would be
>>> quite useful.
>>> Also the pattern of these class may be used as starting point for other
>>> type of CRUD GUI.
>>>
>>> Following is the sample code:
>>>
>>>     public static class GenericTableView<T> extends TableView {
>>>
>>>      private final Class<T> cls;
>>>
>>>      public GenericTableView(final Class<T> cls, final Map<String,
>>> Object> namespace) throws Exception {
>>>      this.cls = cls;
>>>
>>>             for (final Field field: cls.getFields()) {
>>>              final String fname = field.getName();
>>>               getColumns().add(new TableView.Column() {{
>>>              setName(fname);
>>>                     setWidth(3, true);
>>>                     if (fname.equals("flag")) {
>>>                      setCellRenderer(new TableViewImageCellRenderer() {{
>>>                      }}); // INSTANCE, name:
>>> <content:TableViewImageCellRenderer>
>>>                     } else {
>>>                      setHeaderData(getCapitalName(fname));
>>>                     }
>>>                     System.out.println(">>> fname: "+fname);
>>>                 }});
>>>             }
>>>             getTableViewSortListeners().add(new
>>> TableViewSortListener.Adapter() {
>>>                 @Override
>>>                 @SuppressWarnings("unchecked")
>>>                 public void sortChanged(TableView tableView) {
>>>                  tableView.getTableData().setComparator(new
>>> org.apache.pivot.wtk.content.TableViewRowComparator(tableView));
>>>                 }
>>>             });
>>>         }
>>>
>>>      public void add(T... ts) {
>>>      for (T t: ts) {
>>>      getTableData().add(t);
>>>      }
>>>      }
>>>
>>>      static String getCapitalName(String name) {
>>>      if (name.length() == 0) return name;
>>>      return Character.toUpperCase(name.charAt(0))+name.substring(1);
>>>      }
>>>     }
>>>
>>>     static java.util.List<OlympicStanding> createOlympicStandings()
>>> throws Exception {
>>>         java.util.List<OlympicStanding> ts = new
>>> java.util.ArrayList<OlympicStanding>();
>>>
>>>         // tableViewSortListeners(): LISTENER_LIST_PROPERTY
>>>         ts.add(new OlympicStanding() {{
>>>             setNation("China");
>>>             setGold(51);
>>>             setSilver(21);
>>>             setBronze(28);
>>>             setFlag(new
>>> URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/tableviews/cn.png"));
>>>         }}); // INSTANCE, name: <tableviews:OlympicStanding>
>>>         ts.add(new OlympicStanding() {{
>>>             setNation("United States");
>>>             setGold(36);
>>>             setSilver(38);
>>>             setBronze(36);
>>>             setFlag(new
>>> URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/tableviews/us.png"));
>>>         }}); // INSTANCE, name: <tableviews:OlympicStanding>
>>>         return ts;
>>>  }
>>>
>>>     static Window create() throws Exception {
>>>         return new Window() {{
>>>             final Map<String, Object> namespace = new HashMap<String,
>>> Object>();
>>>             setTitle("Table Views");
>>>             setMaximized(true);
>>>             setContent(new Border() {{
>>>                 setContent(new ScrollPane() {{
>>>
>>>  setHorizontalScrollBarPolicy(ScrollPane.ScrollBarPolicy.FILL);
>>>                     setView(new
>>> GenericTableView<OlympicStanding>(OlympicStanding.class, namespace){{
>>>                         namespace.put("tableView", this);
>>>
>>>                         for (OlympicStanding os:
>>> createOlympicStandings()) {
>>>                      add(os);
>>>                      }
>>>                     }}); // INSTANCE, name: <TableView>
>>>                     // columnHeader(): WRITABLE_PROPERTY
>>>                     setColumnHeader(new TableViewHeader() {{
>>>
>>>  setTableView((TableView)namespace.get("tableView"));
>>>
>>>  setSortMode(TableViewHeader.SortMode.MULTI_COLUMN);
>>>                      }}); // INSTANCE, name: <TableViewHeader>
>>>                 }}); // INSTANCE, name: <ScrollPane>
>>>             }}); // INSTANCE, name: <Border>
>>>             CodeEmitterRuntime.initialize(this, namespace);
>>>         }};
>>>     }
>>>
>>>
>>>
>>>>
>>>> > I wondered if Pivot is really designed to support normal Java class
>>>> based GUI implementation.
>>>>
>>>> It most certainly is.  :-)  BXML is just a shortcut to coding your UI by
>>>> hand. Anything you can do in BXML, you can do in Java (though, in many
>>>> cases, not quite as conveniently).
>>>>
>>>> > Regarding to the translator, since there is no detail sample how to
>>>> use these Java API directly, it would be helpful if we have such bxml to
>>>> Java translator.
>>>> > But ideally, Pivot site should include more detailed
>>>> sample/explanation for Java Pivot API based approach(without bxml). Then we
>>>> would not need such a tool.
>>>>
>>>> If you read the BXML Primer, you should have a good understanding of how
>>>> BXML maps to Java. There's no magic to it - it is very straightforward.
>>>>
>>>> > Also if we may really have declarative GUI design, using Scala may be
>>>> more attractive way. Scala would allow declaring GUI in equivalent code side
>>>> as BXML.
>>>>
>>>> I'm not sure how this would work. Scala is conceptually more akin to
>>>> Java than markup. Could you elaborate?
>>>>
>>>> > BTW, I still wonder where the following code went wrong.  I would
>>>> appreciate your suggestion for the following code(java verson of
>>>> custom_table_view.bxml).
>>>> > When it is run, it opens the applet window, but it does not show
>>>> anything.
>>>>
>>>> Two errors:
>>>>
>>>> - You need to call border.setContent(scrollPane), not
>>>> border.add(scrollPane).
>>>>
>>>> - You need to call scrollPane.setView(tableView). Otherwise, the scroll
>>>> pane won't know what it's content is.
>>>>
>>>> I made these changes and the app worked fine.
>>>>
>>>> G
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Cheers,
>>> calathus
>>>
>>>
>>>
>>>
>>
>
>
> --
> Cheers,
> calathus
>
>
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
It would not be possible to define generic table class in BXML, such generic
classes may be definitely used from  BXML file.
This is one part of CRUD, one more useful generic class is to generate Form
GUI class from Java Beans.
Since there are general pattern, it would be more consistent to use setter
name setBeanType().


On Tue, Jan 4, 2011 at 9:47 AM, Gerrick Bivins
<gb...@objectreservoir.com>wrote:

> *+1* for this example!
>  I had been thinking about something like this as well to simplify creating
> table views for java Beans, ie, dynamically creating the table columns based
> on properties. This addresses part of what I was trying to do.
> What would really be slick is if that Class parameter in the constructor
> could be made Bindable so it could dynamically specified via BXML ala:
>
> ...
> *<bxml:define>*
> *   <Class bxml:id="beanClass">*
> *</bxml:define>*
> ...
> *<GenericTableView class="$beanClass" ...>*
> ...
>
>
> Gerrick
>
>
> On Tue, Jan 4, 2011 at 11:11 AM, calathus <ca...@gmail.com> wrote:
>
>>
>>
>> On Mon, Dec 20, 2010 at 5:54 PM, Greg Brown <gk...@verizon.net> wrote:
>>
>>> > My goal was to create a generic class to support CRUD GUI from a given
>>> Java Beans class. Although it is not generic version, Vaadin provides such
>>> sample implementation which may be  immediately used for real projects.
>>>
>>> I'd be interested in learning more about how you envision something like
>>> this might work.
>>>
>>
>> Greg,
>>
>> I created a sample generic  TableView class which can take a parameter
>> bean class and using the reflection library, it defines table view's column
>> fields. This class is modified from tutorials tableviews sample.
>> This is only for demonstration of the generic class approach in Pivot
>> using builder class approach.
>>
>> In general, if we introduce new annotations for entity beans class to
>> define more presentation related information (like width of column) , we can
>> fine tune the look and feels.
>> And the same entity beans can have another JPA annotation from which DB
>> scheme can be generated and also some utility (like in netbeans) will allow
>> to generate restful API from the entity beans.
>>
>> So if we define more GUI feature to support CRUD operation as generic
>> class library, it become very simple to develop DB based web application.
>> There is an  open source project called openxava which has similar
>> approach, but its GUI is based on JSP and not so impressive compared to
>> other GUI(web) projects.
>> The degree of usability of such generic library may not be so general, but
>> if there are a lot of entity classes, this type of approach would be quite
>> useful.
>> Also the pattern of these class may be used as starting point for other
>> type of CRUD GUI.
>>
>> Following is the sample code:
>>
>>     public static class GenericTableView<T> extends TableView {
>>
>>      private final Class<T> cls;
>>
>>      public GenericTableView(final Class<T> cls, final Map<String,
>> Object> namespace) throws Exception {
>>      this.cls = cls;
>>
>>             for (final Field field: cls.getFields()) {
>>              final String fname = field.getName();
>>               getColumns().add(new TableView.Column() {{
>>              setName(fname);
>>                     setWidth(3, true);
>>                     if (fname.equals("flag")) {
>>                      setCellRenderer(new TableViewImageCellRenderer() {{
>>                      }}); // INSTANCE, name:
>> <content:TableViewImageCellRenderer>
>>                     } else {
>>                      setHeaderData(getCapitalName(fname));
>>                     }
>>                     System.out.println(">>> fname: "+fname);
>>                 }});
>>             }
>>             getTableViewSortListeners().add(new
>> TableViewSortListener.Adapter() {
>>                 @Override
>>                 @SuppressWarnings("unchecked")
>>                 public void sortChanged(TableView tableView) {
>>                  tableView.getTableData().setComparator(new
>> org.apache.pivot.wtk.content.TableViewRowComparator(tableView));
>>                 }
>>             });
>>         }
>>
>>      public void add(T... ts) {
>>      for (T t: ts) {
>>      getTableData().add(t);
>>      }
>>      }
>>
>>      static String getCapitalName(String name) {
>>      if (name.length() == 0) return name;
>>      return Character.toUpperCase(name.charAt(0))+name.substring(1);
>>      }
>>     }
>>
>>     static java.util.List<OlympicStanding> createOlympicStandings() throws
>> Exception {
>>         java.util.List<OlympicStanding> ts = new
>> java.util.ArrayList<OlympicStanding>();
>>
>>         // tableViewSortListeners(): LISTENER_LIST_PROPERTY
>>         ts.add(new OlympicStanding() {{
>>             setNation("China");
>>             setGold(51);
>>             setSilver(21);
>>             setBronze(28);
>>             setFlag(new
>> URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/tableviews/cn.png"));
>>         }}); // INSTANCE, name: <tableviews:OlympicStanding>
>>         ts.add(new OlympicStanding() {{
>>             setNation("United States");
>>             setGold(36);
>>             setSilver(38);
>>             setBronze(36);
>>             setFlag(new
>> URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/tableviews/us.png"));
>>         }}); // INSTANCE, name: <tableviews:OlympicStanding>
>>         return ts;
>>  }
>>
>>     static Window create() throws Exception {
>>         return new Window() {{
>>             final Map<String, Object> namespace = new HashMap<String,
>> Object>();
>>             setTitle("Table Views");
>>             setMaximized(true);
>>             setContent(new Border() {{
>>                 setContent(new ScrollPane() {{
>>
>>  setHorizontalScrollBarPolicy(ScrollPane.ScrollBarPolicy.FILL);
>>                     setView(new
>> GenericTableView<OlympicStanding>(OlympicStanding.class, namespace){{
>>                         namespace.put("tableView", this);
>>
>>                         for (OlympicStanding os: createOlympicStandings())
>> {
>>                      add(os);
>>                      }
>>                     }}); // INSTANCE, name: <TableView>
>>                     // columnHeader(): WRITABLE_PROPERTY
>>                     setColumnHeader(new TableViewHeader() {{
>>
>>  setTableView((TableView)namespace.get("tableView"));
>>
>>  setSortMode(TableViewHeader.SortMode.MULTI_COLUMN);
>>                      }}); // INSTANCE, name: <TableViewHeader>
>>                 }}); // INSTANCE, name: <ScrollPane>
>>             }}); // INSTANCE, name: <Border>
>>             CodeEmitterRuntime.initialize(this, namespace);
>>         }};
>>     }
>>
>>
>>
>>>
>>> > I wondered if Pivot is really designed to support normal Java class
>>> based GUI implementation.
>>>
>>> It most certainly is.  :-)  BXML is just a shortcut to coding your UI by
>>> hand. Anything you can do in BXML, you can do in Java (though, in many
>>> cases, not quite as conveniently).
>>>
>>> > Regarding to the translator, since there is no detail sample how to use
>>> these Java API directly, it would be helpful if we have such bxml to Java
>>> translator.
>>> > But ideally, Pivot site should include more detailed sample/explanation
>>> for Java Pivot API based approach(without bxml). Then we would not need such
>>> a tool.
>>>
>>> If you read the BXML Primer, you should have a good understanding of how
>>> BXML maps to Java. There's no magic to it - it is very straightforward.
>>>
>>> > Also if we may really have declarative GUI design, using Scala may be
>>> more attractive way. Scala would allow declaring GUI in equivalent code side
>>> as BXML.
>>>
>>> I'm not sure how this would work. Scala is conceptually more akin to Java
>>> than markup. Could you elaborate?
>>>
>>> > BTW, I still wonder where the following code went wrong.  I would
>>> appreciate your suggestion for the following code(java verson of
>>> custom_table_view.bxml).
>>> > When it is run, it opens the applet window, but it does not show
>>> anything.
>>>
>>> Two errors:
>>>
>>> - You need to call border.setContent(scrollPane), not
>>> border.add(scrollPane).
>>>
>>> - You need to call scrollPane.setView(tableView). Otherwise, the scroll
>>> pane won't know what it's content is.
>>>
>>> I made these changes and the app worked fine.
>>>
>>> G
>>>
>>>
>>>
>>
>>
>> --
>> Cheers,
>> calathus
>>
>>
>>
>>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Gerrick Bivins <gb...@objectreservoir.com>.
*+1* for this example!
 I had been thinking about something like this as well to simplify creating
table views for java Beans, ie, dynamically creating the table columns based
on properties. This addresses part of what I was trying to do.
What would really be slick is if that Class parameter in the constructor
could be made Bindable so it could dynamically specified via BXML ala:

...
*<bxml:define>*
*   <Class bxml:id="beanClass">*
*</bxml:define>*
...
*<GenericTableView class="$beanClass" ...>*
...


Gerrick


On Tue, Jan 4, 2011 at 11:11 AM, calathus <ca...@gmail.com> wrote:

>
>
> On Mon, Dec 20, 2010 at 5:54 PM, Greg Brown <gk...@verizon.net> wrote:
>
>> > My goal was to create a generic class to support CRUD GUI from a given
>> Java Beans class. Although it is not generic version, Vaadin provides such
>> sample implementation which may be  immediately used for real projects.
>>
>> I'd be interested in learning more about how you envision something like
>> this might work.
>>
>
> Greg,
>
> I created a sample generic  TableView class which can take a parameter bean
> class and using the reflection library, it defines table view's column
> fields. This class is modified from tutorials tableviews sample.
> This is only for demonstration of the generic class approach in Pivot using
> builder class approach.
>
> In general, if we introduce new annotations for entity beans class to
> define more presentation related information (like width of column) , we can
> fine tune the look and feels.
> And the same entity beans can have another JPA annotation from which DB
> scheme can be generated and also some utility (like in netbeans) will allow
> to generate restful API from the entity beans.
>
> So if we define more GUI feature to support CRUD operation as generic class
> library, it become very simple to develop DB based web application.
> There is an  open source project called openxava which has similar
> approach, but its GUI is based on JSP and not so impressive compared to
> other GUI(web) projects.
> The degree of usability of such generic library may not be so general, but
> if there are a lot of entity classes, this type of approach would be quite
> useful.
> Also the pattern of these class may be used as starting point for other
> type of CRUD GUI.
>
> Following is the sample code:
>
>     public static class GenericTableView<T> extends TableView {
>
>      private final Class<T> cls;
>
>      public GenericTableView(final Class<T> cls, final Map<String, Object>
> namespace) throws Exception {
>      this.cls = cls;
>
>             for (final Field field: cls.getFields()) {
>              final String fname = field.getName();
>               getColumns().add(new TableView.Column() {{
>              setName(fname);
>                     setWidth(3, true);
>                     if (fname.equals("flag")) {
>                      setCellRenderer(new TableViewImageCellRenderer() {{
>                      }}); // INSTANCE, name:
> <content:TableViewImageCellRenderer>
>                     } else {
>                      setHeaderData(getCapitalName(fname));
>                     }
>                     System.out.println(">>> fname: "+fname);
>                 }});
>             }
>             getTableViewSortListeners().add(new
> TableViewSortListener.Adapter() {
>                 @Override
>                 @SuppressWarnings("unchecked")
>                 public void sortChanged(TableView tableView) {
>                  tableView.getTableData().setComparator(new
> org.apache.pivot.wtk.content.TableViewRowComparator(tableView));
>                 }
>             });
>         }
>
>      public void add(T... ts) {
>      for (T t: ts) {
>      getTableData().add(t);
>      }
>      }
>
>      static String getCapitalName(String name) {
>      if (name.length() == 0) return name;
>      return Character.toUpperCase(name.charAt(0))+name.substring(1);
>      }
>     }
>
>     static java.util.List<OlympicStanding> createOlympicStandings() throws
> Exception {
>         java.util.List<OlympicStanding> ts = new
> java.util.ArrayList<OlympicStanding>();
>
>         // tableViewSortListeners(): LISTENER_LIST_PROPERTY
>         ts.add(new OlympicStanding() {{
>             setNation("China");
>             setGold(51);
>             setSilver(21);
>             setBronze(28);
>             setFlag(new
> URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/tableviews/cn.png"));
>         }}); // INSTANCE, name: <tableviews:OlympicStanding>
>         ts.add(new OlympicStanding() {{
>             setNation("United States");
>             setGold(36);
>             setSilver(38);
>             setBronze(36);
>             setFlag(new
> URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/tableviews/us.png"));
>         }}); // INSTANCE, name: <tableviews:OlympicStanding>
>         return ts;
>  }
>
>     static Window create() throws Exception {
>         return new Window() {{
>             final Map<String, Object> namespace = new HashMap<String,
> Object>();
>             setTitle("Table Views");
>             setMaximized(true);
>             setContent(new Border() {{
>                 setContent(new ScrollPane() {{
>
>  setHorizontalScrollBarPolicy(ScrollPane.ScrollBarPolicy.FILL);
>                     setView(new
> GenericTableView<OlympicStanding>(OlympicStanding.class, namespace){{
>                         namespace.put("tableView", this);
>
>                         for (OlympicStanding os: createOlympicStandings())
> {
>                      add(os);
>                      }
>                     }}); // INSTANCE, name: <TableView>
>                     // columnHeader(): WRITABLE_PROPERTY
>                     setColumnHeader(new TableViewHeader() {{
>
>  setTableView((TableView)namespace.get("tableView"));
>                         setSortMode(TableViewHeader.SortMode.MULTI_COLUMN);
>                      }}); // INSTANCE, name: <TableViewHeader>
>                 }}); // INSTANCE, name: <ScrollPane>
>             }}); // INSTANCE, name: <Border>
>             CodeEmitterRuntime.initialize(this, namespace);
>         }};
>     }
>
>
>
>>
>> > I wondered if Pivot is really designed to support normal Java class
>> based GUI implementation.
>>
>> It most certainly is.  :-)  BXML is just a shortcut to coding your UI by
>> hand. Anything you can do in BXML, you can do in Java (though, in many
>> cases, not quite as conveniently).
>>
>> > Regarding to the translator, since there is no detail sample how to use
>> these Java API directly, it would be helpful if we have such bxml to Java
>> translator.
>> > But ideally, Pivot site should include more detailed sample/explanation
>> for Java Pivot API based approach(without bxml). Then we would not need such
>> a tool.
>>
>> If you read the BXML Primer, you should have a good understanding of how
>> BXML maps to Java. There's no magic to it - it is very straightforward.
>>
>> > Also if we may really have declarative GUI design, using Scala may be
>> more attractive way. Scala would allow declaring GUI in equivalent code side
>> as BXML.
>>
>> I'm not sure how this would work. Scala is conceptually more akin to Java
>> than markup. Could you elaborate?
>>
>> > BTW, I still wonder where the following code went wrong.  I would
>> appreciate your suggestion for the following code(java verson of
>> custom_table_view.bxml).
>> > When it is run, it opens the applet window, but it does not show
>> anything.
>>
>> Two errors:
>>
>> - You need to call border.setContent(scrollPane), not
>> border.add(scrollPane).
>>
>> - You need to call scrollPane.setView(tableView). Otherwise, the scroll
>> pane won't know what it's content is.
>>
>> I made these changes and the app worked fine.
>>
>> G
>>
>>
>>
>
>
> --
> Cheers,
> calathus
>
>
>
>

Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
I extended this approach to use annotation which support all
TableView.Column properties.
Since some of the object is not primitive type, the generic class will use
Javascripts(this can be any script though) to instantiate appropriate object
at runtime.

This sample is working. In this way, it would be useful to have these
view(table/form) specific annotations in the bean class.

-----------------------

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface PivotTableViewColumn {
    String name();

    String headerData(); // JavaScripts
    //HeaderDataRenderer headerDataRenderer = DEFAULT_HEADER_DATA_RENDERER;
    String headerDataRenderer() default ""; // JavaScripts
    int width() default 0;
    int minimumWidth() default 0;
    int maximumWidth() default Integer.MAX_VALUE;
    boolean relative() default false;
    //Object filter = null;
    String filter() default ""; // JavaScripts
    //CellRenderer cellRenderer = DEFAULT_CELL_RENDERER;
    String cellRenderer() default ""; // JavaScripts
}

---------------

public class OlympicStanding {
@PivotTableViewColumn(
    name = "flag",
    headerData = "'Flag'",
    width = 25,
    cellRenderer = "new
org.apache.pivot.wtk.content.TableViewImageCellRenderer()"
)
    public Image flag = null;
 @PivotTableViewColumn(
    name = "nation",
    headerData = "'Nation'",
    width = 3,
    relative = true
)
    public String nation = null;
    @PivotTableViewColumn(
    name = "gold",
    headerData = "'Gold'",
    width = 1,
    relative = true
)
    public int gold = 0;
 @PivotTableViewColumn(
    name = "silver",
    headerData = "'Silver'",
    width = 1,
    relative = true
)
public int silver = 0;

@PivotTableViewColumn(
    name = "bronze",
    headerData = "'Bronze'",
    width = 1,
    relative = true
)
    public int bronze = 0;

    public OlympicStanding() {
    }

    public Image getFlag() {
        return flag;
    }

    public void setFlag(Image flag) {
        this.flag = flag;
    }

    public void setFlag(URL flag) {
        try {
            setFlag(Image.load(flag));
        } catch (TaskExecutionException exception) {
            throw new IllegalArgumentException(exception);
        }
    }

    public String getNation() {
        return nation;
    }

    public void setNation(String nation) {
        this.nation = nation;
    }

    public int getGold() {
        return gold;
    }

    public void setGold(int gold) {
        this.gold = gold;
    }

    public int getSilver() {
        return silver;
    }

    public void setSilver(int silver) {
        this.silver = silver;
    }

    public int getBronze() {
        return bronze;
    }

    public void setBronze(int bronze) {
        this.bronze = bronze;
    }

    public int getTotal() {
        return (gold + silver + bronze);
    }
}

-------------------

      public static class GenericTableView<T> extends TableView {
        public static final String DEFAULT_LANGUAGE = "javascript";

     private final Class<T> cls;
     private final ScriptEngineManager scriptEngineManager;

     public GenericTableView(final Class<T> cls, final Map<String, Object>
namespace) throws Exception {
     this.cls = cls;
     this.scriptEngineManager = createScriptEngineManager(namespace);
            final ScriptEngine scriptEngine =
scriptEngineManager.getEngineByName(DEFAULT_LANGUAGE);
            for (final Field field: cls.getFields()) {
             final PivotTableViewColumn column =
getPivotTableViewColumn(field);
             if (column == null) {
             continue;
             }
             getColumns().add(new TableView.Column() {{
             setName(column.name());
                    setWidth(column.width(), column.relative());
                    setMinimumWidth(column.minimumWidth());
                    setMaximumWidth(column.maximumWidth());

                 final String headerData = column.headerData();
                 if (headerData != null && !headerData.equals("")) {
                 setHeaderData(scriptEngine.eval(headerData));
                 }

                 final String headerDataRenderer =
column.headerDataRenderer();
                 if (headerDataRenderer != null &&
!headerDataRenderer.equals("")) {

setHeaderDataRenderer((HeaderDataRenderer)scriptEngine.eval(headerDataRenderer));
                 }
                    final String cellRenderer = column.cellRenderer();
                 if (cellRenderer != null && !cellRenderer.equals("")) {

setCellRenderer((CellRenderer)scriptEngine.eval(cellRenderer));
                 }
                 final String filter = column.filter();
                 if (filter != null && !filter.equals("")) {
                 setFilter(scriptEngine.eval(filter));
                 }
                }});
            }
            getTableViewSortListeners().add(new
TableViewSortListener.Adapter() {
                @Override
                @SuppressWarnings("unchecked")
                public void sortChanged(TableView tableView) {
                 tableView.getTableData().setComparator(new
org.apache.pivot.wtk.content.TableViewRowComparator(tableView));
                }
            });
        }

     public void add(T... ts) {
     for (T t: ts) {
     getTableData().add(t);
     }
     }

     //
     static ScriptEngineManager createScriptEngineManager(final Map<String,
Object> namespace) {
     final ScriptEngineManager scriptEngineManager = new
javax.script.ScriptEngineManager();
            scriptEngineManager.setBindings(new Bindings() {
                @Override
                public Object get(Object key) {
                    return namespace.get(key.toString());
                }

                @Override
                public Object put(String key, Object value) {
                    return namespace.put(key, value);
                }

                @Override
                public void putAll(java.util.Map<? extends String, ? extends
Object> map) {
                    for (String key : map.keySet()) {
                        put(key, map.get(key));
                    }
                }

                @Override
                public Object remove(Object key) {
                    return namespace.remove(key.toString());
                }

                @Override
                public void clear() {
                    namespace.clear();
                }

                @Override
                public boolean containsKey(Object key) {
                    return namespace.containsKey(key.toString());
                }

                @Override
                public boolean containsValue(Object value) {
                    boolean contains = false;
                    for (String key : namespace) {
                        if (namespace.get(key).equals(value)) {
                            contains = true;
                            break;
                        }
                    }

                    return contains;
                }

                @Override
                public boolean isEmpty() {
                    return namespace.isEmpty();
                }

                @Override
                public java.util.Set<String> keySet() {
                    java.util.HashSet<String> keySet = new
java.util.HashSet<String>();
                    for (String key : namespace) {
                        keySet.add(key);
                    }

                    return keySet;
                }

                @Override
                public java.util.Set<Entry<String, Object>> entrySet() {
                    java.util.HashMap<String, Object> hashMap = new
java.util.HashMap<String, Object>();
                    for (String key : namespace) {
                        hashMap.put(key, namespace.get(key));
                    }

                    return hashMap.entrySet();
                }

                @Override
                public int size() {
                    return namespace.getCount();
                }

                @Override
                public Collection<Object> values() {
                    java.util.ArrayList<Object> values = new
java.util.ArrayList<Object>();
                    for (String key : namespace) {
                        values.add(namespace.get(key));
                    }
                    return values;
                }
            });
            return scriptEngineManager;
     }

     static PivotTableViewColumn getPivotTableViewColumn(final Field field)
{
     for(Annotation annotation: field.getDeclaredAnnotations()){
            if (annotation instanceof PivotTableViewColumn){
             return (PivotTableViewColumn) annotation;
            }
         }
     return null;
     }
    }

    static Window create() throws Exception {
        return new Window() {{
            final Map<String, Object> namespace = new HashMap<String,
Object>();
            setTitle("Generic Table Views");
            setMaximized(true);
            setContent(new Border() {{
                setContent(new ScrollPane() {{

 setHorizontalScrollBarPolicy(ScrollPane.ScrollBarPolicy.FILL);
                    setView(new
GenericTableView<OlympicStanding>(OlympicStanding.class, namespace){{
                        namespace.put("tableView", this);

                        for (OlympicStanding os: createOlympicStandings()) {
                     add(os);
                     }
                    }}); // INSTANCE, name: <TableView>
                    // columnHeader(): WRITABLE_PROPERTY
                    setColumnHeader(new TableViewHeader() {{
                        setTableView((TableView)namespace.get("tableView"));
                        setSortMode(TableViewHeader.SortMode.MULTI_COLUMN);
                    }}); // INSTANCE, name: <TableViewHeader>
                }}); // INSTANCE, name: <ScrollPane>
            }}); // INSTANCE, name: <Border>
            CodeEmitterRuntime.initialize(this, namespace);
        }};
    }

    static java.util.List<OlympicStanding> createOlympicStandings() throws
Exception {
        java.util.List<OlympicStanding> ts = new
java.util.ArrayList<OlympicStanding>();

        // tableViewSortListeners(): LISTENER_LIST_PROPERTY
        ts.add(new OlympicStanding() {{
            setNation("China");
            setGold(51);
            setSilver(21);
            setBronze(28);
            setFlag(new
URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/tableviews/cn.png"));
        }}); // INSTANCE, name: <tableviews:OlympicStanding>
        ts.add(new OlympicStanding() {{
            setNation("United States");
            setGold(36);
            setSilver(38);
            setBronze(36);
            setFlag(new
URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/tableviews/us.png"));
        }}); // INSTANCE, name: <tableviews:OlympicStanding>
  }
}

On Tue, Jan 4, 2011 at 9:11 AM, calathus <ca...@gmail.com> wrote:

>
>
> On Mon, Dec 20, 2010 at 5:54 PM, Greg Brown <gk...@verizon.net> wrote:
>
>> > My goal was to create a generic class to support CRUD GUI from a given
>> Java Beans class. Although it is not generic version, Vaadin provides such
>> sample implementation which may be  immediately used for real projects.
>>
>> I'd be interested in learning more about how you envision something like
>> this might work.
>>
>
> Greg,
>
> I created a sample generic  TableView class which can take a parameter bean
> class and using the reflection library, it defines table view's column
> fields. This class is modified from tutorials tableviews sample.
> This is only for demonstration of the generic class approach in Pivot using
> builder class approach.
>
> In general, if we introduce new annotations for entity beans class to
> define more presentation related information (like width of column) , we can
> fine tune the look and feels.
> And the same entity beans can have another JPA annotation from which DB
> scheme can be generated and also some utility (like in netbeans) will allow
> to generate restful API from the entity beans.
>
> So if we define more GUI feature to support CRUD operation as generic class
> library, it become very simple to develop DB based web application.
> There is an  open source project called openxava which has similar
> approach, but its GUI is based on JSP and not so impressive compared to
> other GUI(web) projects.
> The degree of usability of such generic library may not be so general, but
> if there are a lot of entity classes, this type of approach would be quite
> useful.
> Also the pattern of these class may be used as starting point for other
> type of CRUD GUI.
>
> Following is the sample code:
>
>     public static class GenericTableView<T> extends TableView {
>
>      private final Class<T> cls;
>
>      public GenericTableView(final Class<T> cls, final Map<String, Object>
> namespace) throws Exception {
>      this.cls = cls;
>
>             for (final Field field: cls.getFields()) {
>              final String fname = field.getName();
>              getColumns().add(new TableView.Column() {{
>              setName(fname);
>                     setWidth(3, true);
>                     if (fname.equals("flag")) {
>                      setCellRenderer(new TableViewImageCellRenderer() {{
>                      }}); // INSTANCE, name:
> <content:TableViewImageCellRenderer>
>                     } else {
>                      setHeaderData(getCapitalName(fname));
>                     }
>                     System.out.println(">>> fname: "+fname);
>                 }});
>             }
>             getTableViewSortListeners().add(new
> TableViewSortListener.Adapter() {
>                 @Override
>                 @SuppressWarnings("unchecked")
>                 public void sortChanged(TableView tableView) {
>                  tableView.getTableData().setComparator(new
> org.apache.pivot.wtk.content.TableViewRowComparator(tableView));
>                 }
>             });
>         }
>
>      public void add(T... ts) {
>      for (T t: ts) {
>      getTableData().add(t);
>      }
>      }
>
>      static String getCapitalName(String name) {
>      if (name.length() == 0) return name;
>      return Character.toUpperCase(name.charAt(0))+name.substring(1);
>      }
>     }
>
>     static java.util.List<OlympicStanding> createOlympicStandings() throws
> Exception {
>         java.util.List<OlympicStanding> ts = new
> java.util.ArrayList<OlympicStanding>();
>
>         // tableViewSortListeners(): LISTENER_LIST_PROPERTY
>         ts.add(new OlympicStanding() {{
>             setNation("China");
>             setGold(51);
>             setSilver(21);
>             setBronze(28);
>             setFlag(new
> URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/tableviews/cn.png"));
>         }}); // INSTANCE, name: <tableviews:OlympicStanding>
>         ts.add(new OlympicStanding() {{
>             setNation("United States");
>             setGold(36);
>             setSilver(38);
>             setBronze(36);
>             setFlag(new
> URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/tableviews/us.png"));
>         }}); // INSTANCE, name: <tableviews:OlympicStanding>
>         return ts;
>  }
>
>     static Window create() throws Exception {
>         return new Window() {{
>             final Map<String, Object> namespace = new HashMap<String,
> Object>();
>             setTitle("Table Views");
>             setMaximized(true);
>             setContent(new Border() {{
>                 setContent(new ScrollPane() {{
>
>  setHorizontalScrollBarPolicy(ScrollPane.ScrollBarPolicy.FILL);
>                     setView(new
> GenericTableView<OlympicStanding>(OlympicStanding.class, namespace){{
>                         namespace.put("tableView", this);
>
>                         for (OlympicStanding os: createOlympicStandings())
> {
>                      add(os);
>                      }
>                     }}); // INSTANCE, name: <TableView>
>                     // columnHeader(): WRITABLE_PROPERTY
>                     setColumnHeader(new TableViewHeader() {{
>
>  setTableView((TableView)namespace.get("tableView"));
>                         setSortMode(TableViewHeader.SortMode.MULTI_COLUMN);
>                     }}); // INSTANCE, name: <TableViewHeader>
>                 }}); // INSTANCE, name: <ScrollPane>
>             }}); // INSTANCE, name: <Border>
>             CodeEmitterRuntime.initialize(this, namespace);
>         }};
>     }
>
>
>
>>
>> > I wondered if Pivot is really designed to support normal Java class
>> based GUI implementation.
>>
>> It most certainly is.  :-)  BXML is just a shortcut to coding your UI by
>> hand. Anything you can do in BXML, you can do in Java (though, in many
>> cases, not quite as conveniently).
>>
>> > Regarding to the translator, since there is no detail sample how to use
>> these Java API directly, it would be helpful if we have such bxml to Java
>> translator.
>> > But ideally, Pivot site should include more detailed sample/explanation
>> for Java Pivot API based approach(without bxml). Then we would not need such
>> a tool.
>>
>> If you read the BXML Primer, you should have a good understanding of how
>> BXML maps to Java. There's no magic to it - it is very straightforward.
>>
>> > Also if we may really have declarative GUI design, using Scala may be
>> more attractive way. Scala would allow declaring GUI in equivalent code side
>> as BXML.
>>
>> I'm not sure how this would work. Scala is conceptually more akin to Java
>> than markup. Could you elaborate?
>>
>> > BTW, I still wonder where the following code went wrong.  I would
>> appreciate your suggestion for the following code(java verson of
>> custom_table_view.bxml).
>> > When it is run, it opens the applet window, but it does not show
>> anything.
>>
>> Two errors:
>>
>> - You need to call border.setContent(scrollPane), not
>> border.add(scrollPane).
>>
>> - You need to call scrollPane.setView(tableView). Otherwise, the scroll
>> pane won't know what it's content is.
>>
>> I made these changes and the app worked fine.
>>
>> G
>>
>>
>>
>
>
> --
> Cheers,
> calathus
>
>
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
On Mon, Dec 20, 2010 at 5:54 PM, Greg Brown <gk...@verizon.net> wrote:

> > My goal was to create a generic class to support CRUD GUI from a given
> Java Beans class. Although it is not generic version, Vaadin provides such
> sample implementation which may be  immediately used for real projects.
>
> I'd be interested in learning more about how you envision something like
> this might work.
>

Greg,

I created a sample generic  TableView class which can take a parameter bean
class and using the reflection library, it defines table view's column
fields. This class is modified from tutorials tableviews sample.
This is only for demonstration of the generic class approach in Pivot using
builder class approach.

In general, if we introduce new annotations for entity beans class to define
more presentation related information (like width of column) , we can fine
tune the look and feels.
And the same entity beans can have another JPA annotation from which DB
scheme can be generated and also some utility (like in netbeans) will allow
to generate restful API from the entity beans.

So if we define more GUI feature to support CRUD operation as generic class
library, it become very simple to develop DB based web application.
There is an  open source project called openxava which has similar approach,
but its GUI is based on JSP and not so impressive compared to other GUI(web)
projects.
The degree of usability of such generic library may not be so general, but
if there are a lot of entity classes, this type of approach would be quite
useful.
Also the pattern of these class may be used as starting point for other type
of CRUD GUI.

Following is the sample code:

    public static class GenericTableView<T> extends TableView {

     private final Class<T> cls;

     public GenericTableView(final Class<T> cls, final Map<String, Object>
namespace) throws Exception {
     this.cls = cls;

            for (final Field field: cls.getFields()) {
             final String fname = field.getName();
             getColumns().add(new TableView.Column() {{
             setName(fname);
                    setWidth(3, true);
                    if (fname.equals("flag")) {
                     setCellRenderer(new TableViewImageCellRenderer() {{
                     }}); // INSTANCE, name:
<content:TableViewImageCellRenderer>
                    } else {
                     setHeaderData(getCapitalName(fname));
                    }
                    System.out.println(">>> fname: "+fname);
                }});
            }
            getTableViewSortListeners().add(new
TableViewSortListener.Adapter() {
                @Override
                @SuppressWarnings("unchecked")
                public void sortChanged(TableView tableView) {
                 tableView.getTableData().setComparator(new
org.apache.pivot.wtk.content.TableViewRowComparator(tableView));
                }
            });
        }

     public void add(T... ts) {
     for (T t: ts) {
     getTableData().add(t);
     }
     }

     static String getCapitalName(String name) {
     if (name.length() == 0) return name;
     return Character.toUpperCase(name.charAt(0))+name.substring(1);
     }
    }

    static java.util.List<OlympicStanding> createOlympicStandings() throws
Exception {
        java.util.List<OlympicStanding> ts = new
java.util.ArrayList<OlympicStanding>();

        // tableViewSortListeners(): LISTENER_LIST_PROPERTY
        ts.add(new OlympicStanding() {{
            setNation("China");
            setGold(51);
            setSilver(21);
            setBronze(28);
            setFlag(new
URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/tableviews/cn.png"));
        }}); // INSTANCE, name: <tableviews:OlympicStanding>
        ts.add(new OlympicStanding() {{
            setNation("United States");
            setGold(36);
            setSilver(38);
            setBronze(36);
            setFlag(new
URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/tableviews/us.png"));
        }}); // INSTANCE, name: <tableviews:OlympicStanding>
        return ts;
}

    static Window create() throws Exception {
        return new Window() {{
            final Map<String, Object> namespace = new HashMap<String,
Object>();
            setTitle("Table Views");
            setMaximized(true);
            setContent(new Border() {{
                setContent(new ScrollPane() {{

 setHorizontalScrollBarPolicy(ScrollPane.ScrollBarPolicy.FILL);
                    setView(new
GenericTableView<OlympicStanding>(OlympicStanding.class, namespace){{
                        namespace.put("tableView", this);

                        for (OlympicStanding os: createOlympicStandings()) {
                     add(os);
                     }
                    }}); // INSTANCE, name: <TableView>
                    // columnHeader(): WRITABLE_PROPERTY
                    setColumnHeader(new TableViewHeader() {{
                        setTableView((TableView)namespace.get("tableView"));
                        setSortMode(TableViewHeader.SortMode.MULTI_COLUMN);
                    }}); // INSTANCE, name: <TableViewHeader>
                }}); // INSTANCE, name: <ScrollPane>
            }}); // INSTANCE, name: <Border>
            CodeEmitterRuntime.initialize(this, namespace);
        }};
    }



>
> > I wondered if Pivot is really designed to support normal Java class based
> GUI implementation.
>
> It most certainly is.  :-)  BXML is just a shortcut to coding your UI by
> hand. Anything you can do in BXML, you can do in Java (though, in many
> cases, not quite as conveniently).
>
> > Regarding to the translator, since there is no detail sample how to use
> these Java API directly, it would be helpful if we have such bxml to Java
> translator.
> > But ideally, Pivot site should include more detailed sample/explanation
> for Java Pivot API based approach(without bxml). Then we would not need such
> a tool.
>
> If you read the BXML Primer, you should have a good understanding of how
> BXML maps to Java. There's no magic to it - it is very straightforward.
>
> > Also if we may really have declarative GUI design, using Scala may be
> more attractive way. Scala would allow declaring GUI in equivalent code side
> as BXML.
>
> I'm not sure how this would work. Scala is conceptually more akin to Java
> than markup. Could you elaborate?
>
> > BTW, I still wonder where the following code went wrong.  I would
> appreciate your suggestion for the following code(java verson of
> custom_table_view.bxml).
> > When it is run, it opens the applet window, but it does not show
> anything.
>
> Two errors:
>
> - You need to call border.setContent(scrollPane), not
> border.add(scrollPane).
>
> - You need to call scrollPane.setView(tableView). Otherwise, the scroll
> pane won't know what it's content is.
>
> I made these changes and the app worked fine.
>
> G
>
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Clint Gilbert <cl...@hms.harvard.edu>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/21/2010 08:06 AM, Greg Brown wrote:
> OK, now I get it. Groovy allows you to do something similar. However, I believe this approach requires creating "builder" classes, correct? 

More or less.  My approach uses Scala implicits to (effectively) add
methods to Pivot classes like Component and Container.  It's basic, but
could be extended into a real Scala-Pivot binding using builder-type
objects or methods for more things.

> BXML offers a similar capability, but without the need for builders:

No doubt, I don't mean to knock the XML-based approach at all - it
clearly works for lots of people.  It's just that I, like the OP it
seems, prefer doing things programmatically (especially with Scala) to
detect more errors statically.

> 
> <Window>
>   <BoxPane>
>     <Label text="here's a Label inside a BoxPane inside a Window"/>
>   </BoxPane>
> </Window>
> 
> You can also define event listeners in BXML.
> 
> However, I see value in both approaches, I think a Scala builder library would be a great addition to the platform. By all means, please consider submitting it if you would like.
> 
> On Dec 21, 2010, at 12:42 AM, Gilbert, Clint wrote:
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk0RWi0ACgkQ0GFaTS4nYxu5VACfQ5+GrQjgOKbU7+9GYir9y0st
VSAAn1lf53433b/9iQhxAvRaRQu/y2hB
=/ciH
-----END PGP SIGNATURE-----

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
OK, now I get it. Groovy allows you to do something similar. However, I believe this approach requires creating "builder" classes, correct? BXML offers a similar capability, but without the need for builders:

<Window>
  <BoxPane>
    <Label text="here's a Label inside a BoxPane inside a Window"/>
  </BoxPane>
</Window>

You can also define event listeners in BXML.

However, I see value in both approaches, I think a Scala builder library would be a great addition to the platform. By all means, please consider submitting it if you would like.

On Dec 21, 2010, at 12:42 AM, Gilbert, Clint wrote:

> 
> ________________________________________
> From: Greg Brown [gk_brown@verizon.net]
> Sent: Monday, December 20, 2010 8:54 PM
> To: calathus
> Cc: user@pivot.apache.org
> Subject: Re: [pivot] are there any tools to convert bxml to Java?
> 
>> Also if we may really have declarative GUI design, using Scala may be more attractive way. Scala would allow declaring GUI in equivalent code side as BXML.
> 
> I'm not sure how this would work. Scala is conceptually more akin to Java than markup. Could you elaborate?
> 
> 
> I've been moving a Pivot project of mine bit-by-bit from Java to Scala, so I think I know what he's getting at here.  Scala makes nice-looking, declarative DSLs possible.  I'm not familiar with BXML, but I'm guessing you can declare things like: "here's a window and here's what it contains".  A Scala DSL for this might look like
> 
> val window = Window {
>  BoxPane { 
>    new Label("here's a Label inside a BoxPane inside a Window")
> }
> }
> 
> I have a very small Scala lib to allow syntax like:
> 
> val component = new Button("Hello")
> 
> button onClick {
>  println("You clicked the button!")
> }
> 
> and 
> 
> val container = new BoxPane
> 
> container += new Label("A label")
> 
> and 
> 
> 
> val label = new Label("A label")
> val widget = new SomeWidget
> 
> container ++ (label, widget)
> 
> etc.
> 
> It's extremely rudimentary, but if anyone's interested I can share it with the list.


Re: unsubscribe

Posted by Greg Brown <gk...@verizon.net>.
Send a message to user-unsubscribe@pivot.apache.org.

On Jan 6, 2011, at 10:08 AM, Marco.Hostos wrote:

> Please how unsuscribe??
>  
>  


unsubscribe

Posted by "Marco.Hostos" <ma...@aditiva.com>.
Please how unsuscribe??

 

 


unsubscribe

Posted by Felix Eckhardt <Fe...@starfinanz.de>.

Re: Scala "DSL" (was Re: [pivot] are there any tools to convert bxml to Java?)

Posted by Sandro Martini <sa...@gmail.com>.
Hi all,

@Calatus:
I think we really need some cases like yours to improve some parts of Pivot
... very good.
A simple way to  manage fast a typical CRUD application is a great feature
to have.

@Clint:
thanks for the sample, I'll try to look as soon as possible (but with my
slow timings :-) ), and don't worry I'm a Scala newbie, and you have already
do much than me with Pivot and Scala ... but it's definitely an area that I
(and Greg, and maybe others here) want to improve.
My problem here is that at the moment I haven't a real application to do
with Scala and Pivot, I hope to start to make something real with both in
the near future.

Greg, what do you think on grant Clint as committer (if he wants) on
Pivot-Scala (currently here: http://code.google.com/p/pivot-scala/ ) ?
So maybe we can start to define some elements to put there (what and how, as
a structure) ... or at least use these as a starting point (if Clint is not
against this).


Bye,
Sandro

-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/pivot-are-there-any-tools-to-convert-bxml-to-Java-tp2118284p2197512.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Scala "DSL" (was Re: [pivot] are there any tools to convert bxml to Java?)

Posted by Clint Gilbert <cl...@hms.harvard.edu>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Sandro,

I finally got my Scala wrapper in a not-too-embarrassing state.  You'll
find it attached to this message.

I must stress that I'm not a Scala or Pivot expert, just an average dev
with a decent-sized hobby project that uses Pivot, a bias against XML,
and a love of static typing.  The Scala abstractions could undoubtedly
be better, and the lib encodes many simplifying assumptions that are ok
for my app, will not be for others.

Still, I hope it's useful to someone.  The ScalaPivot object is
executable, and the Main class shows how things work:

> val window = new Window
> 
> import Implicits._
> 
> val text = label("Here's a label!") 
> 
> text onMouseOver {
>     println("You moused over the label")
> } 
> 
> text onMouseOut {
>     println("You moused out of the label")
> }
> 
> val pane = horizontal(
>     text,
>     button("Here's a button") {
>         println("You pushed the button!")
>     });
> 
> val list = listView("A value", "Another value", "Yet another value") { (index: Int, value: String) =>
>     println("You selected '" + value + "' (position " + index + ")")
> }
> 
> val input = textInput { self: TextInput =>
>     println("So far, you typed '" + self.getText + "'")
> }
> 
> window.setContent(vertical(pane, horizontal(list), horizontal(input)))
> 
> window.open(display)

This grew out of my need to solve certain small problems while porting
my hobby app from Java to Scala class-by-class.  It wraps the tiny slice
of Pivot that the UI part of my app uses most frequently.  A more
general, declarative DSL, perhaps similar to Scala's collection
"literal" syntax is possible with a little effort.


On 12/21/2010 04:46 AM, Sandro Martini wrote:
> 
> Hi Clint,
> I think your code could be really useful even to others (and to me, I like
> very much Scala :-) but too little time to make something real at the
> moment). If you want to post it here, probably it's the best place until
> we'll enable a pivot-contrib project or something similar.
> 
> Or if you are interested, for this or for other things (maybe later), we
> have some project on GoogleCode, so we can enable you to commit there, for
> example pivot-scala, pivot-stuff, etc ...
> 
> Thank you very much,
> Sandro
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk0kDYoACgkQ0GFaTS4nYxtZwwCcDQHFy09mk22qrsrlZxiPHLcc
aX8AoKEvoSBcZwjEt4WP1gLNt9/eJc5y
=DFZM
-----END PGP SIGNATURE-----

RE: [pivot] are there any tools to convert bxml to Java?

Posted by Sandro Martini <sa...@gmail.com>.
Hi Clint,
I think your code could be really useful even to others (and to me, I like
very much Scala :-) but too little time to make something real at the
moment). If you want to post it here, probably it's the best place until
we'll enable a pivot-contrib project or something similar.

Or if you are interested, for this or for other things (maybe later), we
have some project on GoogleCode, so we can enable you to commit there, for
example pivot-scala, pivot-stuff, etc ...

Thank you very much,
Sandro

-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/pivot-are-there-any-tools-to-convert-bxml-to-Java-tp2118284p2125170.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: [pivot] are there any tools to convert bxml to Java?

Posted by "Gilbert, Clint" <Cl...@hms.harvard.edu>.
________________________________________
From: Greg Brown [gk_brown@verizon.net]
Sent: Monday, December 20, 2010 8:54 PM
To: calathus
Cc: user@pivot.apache.org
Subject: Re: [pivot] are there any tools to convert bxml to Java?

> Also if we may really have declarative GUI design, using Scala may be more attractive way. Scala would allow declaring GUI in equivalent code side as BXML.

I'm not sure how this would work. Scala is conceptually more akin to Java than markup. Could you elaborate?


I've been moving a Pivot project of mine bit-by-bit from Java to Scala, so I think I know what he's getting at here.  Scala makes nice-looking, declarative DSLs possible.  I'm not familiar with BXML, but I'm guessing you can declare things like: "here's a window and here's what it contains".  A Scala DSL for this might look like

val window = Window {
  BoxPane { 
    new Label("here's a Label inside a BoxPane inside a Window")
 }
}

I have a very small Scala lib to allow syntax like:

val component = new Button("Hello")

button onClick {
  println("You clicked the button!")
}

and 

val container = new BoxPane

container += new Label("A label")

and 


val label = new Label("A label")
val widget = new SomeWidget

container ++ (label, widget)

etc.

It's extremely rudimentary, but if anyone's interested I can share it with the list.

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> My goal was to create a generic class to support CRUD GUI from a given Java Beans class. Although it is not generic version, Vaadin provides such sample implementation which may be  immediately used for real projects.

I'd be interested in learning more about how you envision something like this might work. 

> I wondered if Pivot is really designed to support normal Java class based GUI implementation. 

It most certainly is.  :-)  BXML is just a shortcut to coding your UI by hand. Anything you can do in BXML, you can do in Java (though, in many cases, not quite as conveniently).

> Regarding to the translator, since there is no detail sample how to use these Java API directly, it would be helpful if we have such bxml to Java translator. 
> But ideally, Pivot site should include more detailed sample/explanation for Java Pivot API based approach(without bxml). Then we would not need such a tool. 

If you read the BXML Primer, you should have a good understanding of how BXML maps to Java. There's no magic to it - it is very straightforward.

> Also if we may really have declarative GUI design, using Scala may be more attractive way. Scala would allow declaring GUI in equivalent code side as BXML.

I'm not sure how this would work. Scala is conceptually more akin to Java than markup. Could you elaborate?

> BTW, I still wonder where the following code went wrong.  I would appreciate your suggestion for the following code(java verson of custom_table_view.bxml).
> When it is run, it opens the applet window, but it does not show anything. 

Two errors:

- You need to call border.setContent(scrollPane), not border.add(scrollPane).

- You need to call scrollPane.setView(tableView). Otherwise, the scroll pane won't know what it's content is.

I made these changes and the app worked fine.

G



Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
Chris, Greg,
Thanks for the reply.

I've already checked the source code of BXMLSerializer to see how I can
write a corresponding Java code for a custom_table_view.bxml.

My goal was to create a generic class to support CRUD GUI from a given Java
Beans class. Although it is not generic version, Vaadin provides such sample
implementation which may be  immediately used for real projects. I wanted to
have such a sample code in Pivot too. (Since a lot of application require
this type of GUI interface for DB, it will be quite useful if Pivot provide
such basic CRUD library, or sample codes.)

But when I translated it into Java with guess work, the code did not show
anything. It looks like there might be more implicit code generation
involved.
Also quite strange thing was the most of TableView class methods  are just
throwing exception including the constructor, and when I created a new
instance of the TableView instance, it did not throw exception! I guessed
BXMLSerializer may create anonymous subclass(instance) for TableView class.

I wondered if Pivot is really designed to support normal Java class based
GUI implementation.

Regarding to the translator, since there is no detail sample how to use
these Java API directly, it would be helpful if we have such bxml to Java
translator.
But ideally, Pivot site should include more detailed sample/explanation for
Java Pivot API based approach(without bxml). Then we would not need such a
tool.
Also if we may really have declarative GUI design, using Scala may be more
attractive way. Scala would allow declaring GUI in equivalent code side as
BXML. I think generic, and dynamic GUI generation can be supported with this
approach.(Although Scala does not support static methods  in generic class,
but for GUI design, that restriction would be OK.)

BTW, I still wonder where the following code went wrong.  I would appreciate
your suggestion for the following code(java verson
of custom_table_view.bxml).
When it is run, it opens the applet window, but it does not show anything.

------------------
package com.sample;

import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.collections.List;
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.Border;
import org.apache.pivot.wtk.DesktopApplicationContext;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.ScrollPane;
import org.apache.pivot.wtk.SortDirection;
import org.apache.pivot.wtk.TableView.ColumnSequence;
import org.apache.pivot.wtk.TableView;
import org.apache.pivot.wtk.TableViewHeader;
import org.apache.pivot.wtk.TableViewSortListener;
import org.apache.pivot.wtk.Window;
import org.apache.pivot.wtk.content.TableViewRowComparator;

public class SampleTableView implements Application {

    private Window window = null;
    public static final String LANGUAGE_KEY = "language";
    private List<OlympicStanding> tableData = new
ArrayList<OlympicStanding>();

    @Override
    public void startup(Display display, Map<String, String> properties)
throws Exception {
        try {
            window = new Window();
            window.setTitle("SampleTableView");
            window.setMaximized(true);

            final Border border = new Border();
            final ScrollPane scrollPane = new ScrollPane();

 scrollPane.setHorizontalScrollBarPolicy(ScrollPane.ScrollBarPolicy.FILL_TO_CAPACITY);
            border.add(scrollPane);

            final TableView tableView = new TableView(tableData);
            scrollPane.setColumnHeader(new TableViewHeader(tableView));

            tableView.getTableViewSortListeners().add(new
TableViewSortListener() {
                public void sortAdded(TableView tableView, String
columnName) {}

                public void sortUpdated(TableView tableView, String
columnName,
                        SortDirection previousSortDirection) {}

                public void sortRemoved(TableView tableView, String
columnName,
                       SortDirection sortDirection) {}

                public void sortChanged(TableView tableView) {
                    final List<Object> tableData =
(List<Object>)tableView.getTableData();
                    tableData.setComparator(new
TableViewRowComparator(tableView));
                }
            });

            {
                final ColumnSequence colmns = tableView.getColumns();
                colmns.add(new TableView.Column("flag", 180));
                colmns.add(new TableView.Column("nation", "Nation", 180));
                colmns.add(new TableView.Column("gold", "Gold", 60));
                colmns.add(new TableView.Column("silver", "Silver", 60));
                colmns.add(new TableView.Column("bronze", "Bronze", 60));
                colmns.add(new TableView.Column("total", "Total", 60));

                addOlympicStanding("China", 51, 21, 28, "images/cn.png");
                addOlympicStanding("United States", 36, 38, 36,
"images/us.png");
                addOlympicStanding("Russia", 23, 21, 28, "images/ru.png");
                addOlympicStanding("Great Britain", 19, 13, 15,
"images/gb.png");
            }

            window.setContent(border);

            window.open(display);
        } catch (Throwable e) {
            e.printStackTrace();
            System.out.println(">> error ==>" + e.getClass());
            throw new RuntimeException(e);
        }
    }

    void addOlympicStanding(String nation, int gold, int silver, int bronze,
String flag) {
        OlympicStanding olympicStanding = new OlympicStanding();
        olympicStanding.setNation(nation);
        olympicStanding.setGold(gold);
        olympicStanding.setSilver(silver);
        olympicStanding.setBronze(bronze);
        //olympicStanding.setFlag(ClassLoader.getSystemResource(flag));
        tableData.add(olympicStanding);
    }

    @Override
    public boolean shutdown(boolean optional) {
        if (window != null) {
            window.close();
        }

        return false;
    }

    @Override
    public void suspend() {
    }

    @Override
    public void resume() {
    }

    public static void main(String[] args) {
        DesktopApplicationContext.main(SampleTableView.class, args);
    }
}

---------------------------
this is the original bxml code.(custom_table_view.bxml)


<Window title="Table Views" maximized="true"
    xmlns:bxml="http://pivot.apache.org/bxml"
    xmlns:content="org.apache.pivot.wtk.content"
    xmlns:tableviews="org.apache.pivot.tutorials.tableviews"
    xmlns="org.apache.pivot.wtk">
    <Border>
        <ScrollPane horizontalScrollBarPolicy="fill">
            <TableView bxml:id="tableView">
                <columns>
                    <TableView.Column name="flag" width="20">
                        <cellRenderer>
                            <content:TableViewImageCellRenderer/>
                        </cellRenderer>
                    </TableView.Column>
                    <TableView.Column name="nation" width="3*"
headerData="Nation"/>
                    <TableView.Column name="gold" width="1*"
headerData="Gold"/>
                    <TableView.Column name="silver" width="1*"
headerData="Silver"/>
                    <TableView.Column name="bronze" width="1*"
headerData="Bronze"/>
                    <TableView.Column name="total" width="1*"
headerData="Total"/>
                </columns>

                <tableViewSortListeners>
                    <![CDATA[
                    function sortChanged(tableView) {
                        var tableData = tableView.getTableData();
                        tableData.setComparator(new
org.apache.pivot.wtk.content.TableViewRowComparator(tableView));
                    }
                    ]]>
                </tableViewSortListeners>

                <!-- Source:
http://en.wikipedia.org/wiki/2008_Summer_Olympics_medal_table -->
                <tableviews:OlympicStanding nation="China" gold="51"
silver="21" bronze="28" flag="@cn.png"/>
                <tableviews:OlympicStanding nation="United States" gold="36"
silver="38" bronze="36" flag="@us.png"/>
                <tableviews:OlympicStanding nation="Russia" gold="23"
silver="21" bronze="28" flag="@ru.png"/>
                <tableviews:OlympicStanding nation="Great Britain" gold="19"
silver="13" bronze="15" flag="@gb.png"/>
                <tableviews:OlympicStanding nation="Germany" gold="16"
silver="10" bronze="15" flag="@de.png"/>
                <tableviews:OlympicStanding nation="Australia" gold="14"
silver="15" bronze="17" flag="@au.png"/>
                <tableviews:OlympicStanding nation="South Korea" gold="13"
silver="10" bronze="8" flag="@kr.png"/>
                <tableviews:OlympicStanding nation="Japan" gold="9"
silver="6" bronze="11" flag="@jp.png"/>
                <tableviews:OlympicStanding nation="Italy" gold="8"
silver="10" bronze="10" flag="@it.png"/>
                <tableviews:OlympicStanding nation="France" gold="7"
silver="16" bronze="17" flag="@fr.png"/>
            </TableView>

            <columnHeader>
                <TableViewHeader tableView="$tableView"
sortMode="single_column"/>
            </columnHeader>
        </ScrollPane>
    </Border>
</Window>


On Mon, Dec 20, 2010 at 6:04 AM, Greg Brown <gk...@verizon.net> wrote:

> As Chris mentioned, Pivot does not currently provide a BXML to Java
> compiler. We actually prototyped one a while back, but it was never
> completed due to other priorities.
>
> Generating byte code from BXML might be tough, but converting it to a Java
> source file would probably be pretty easy. Let me know if you are interested
> in trying to write something like this - I would be happy to try to help
> when I can.
>
> G
>
> On Dec 19, 2010, at 10:26 PM, calathus wrote:
>
> > Hi,
> > I'm looking for a tool to convert bxml file to equivalent Java source
> program.
> > Are there such tools?
> >
> > I just started using pivot, but many of sample is based on bxml.
> > I think in order to develop a UI library with Java generic class, XML
> file based approach is not appropriate.
> >
> > And xml based approach will reduce static error detection capability.
> > I liked to see  more examples using  Java classes to define GUI without
> relying on bxml files.
> >
> > --
> > Cheers,
> > calathus
> >
> >
> >
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Todd Volkert <tv...@gmail.com>.
+1!  I created a rough-draft BXMLCompiler back in the day and never
completed it.  It used variables whose names were determined by counters,
but the generated code you have is SO much easier to read.

-T

On Mon, Dec 27, 2010 at 9:03 AM, Greg Brown <gk...@verizon.net> wrote:

> Great approach! Is that representative of what your BXML->Java compiler
> generates? I really like how it uses anonymous inner classes as the
> "builder" mechanism.
>
> On Dec 27, 2010, at 7:41 AM, calathus wrote:
>
> Greg,
> I considered implementing Pivot builder in Scala following scala-squib, but
> I found a few issues for this type of approach.
> Basically, it will depend on more runtime binding, so it will reduce the
> advantage of statically typed language.
> After I implemented bxml to Java converter, it became clear that the
> translation can be done more directly reflecting the original BXML
> structure, also without using variable in translated Java codes.
>
> For example,  detail_pane.bxml can be translated in Java as following. This
> style may be used instead of BXML.
> Do you have any opinion for this approach?
>
>     public static Object getComponent() {
>         try {
>             return new BoxPane() {{
>                 setOrientation(Orientation.VERTICAL);
>                 setStyles("{fill:true}");
>                 add(new Label() {{
>                     setTextKey("companyName");
>                     setStyles("{font:{size:12, bold:true}}");
>                 }});
>                 add(new Separator() {{
>                 }});
>                 add(new Form() {{
>                     setStyles("{padding:0, fill:true, showFlagIcons:false,
> showFlagHighlight:false,         leftAlignLabels:true}");
>                     getSections().add(new Form.Section() {{
>                         final ValueMapping valueMapping_5 = new
> ValueMapping();
>                         final ChangeMapping changeMapping_6 = new
> ChangeMapping();
>                         final VolumeMapping volumeMapping_7 = new
> VolumeMapping();
>                         add(new Label() {{
>                             setTextKey("value");
>                             setTextBindMapping(valueMapping_5);
>                             setStyles("{horizontalAlignment:'right'}");
>                             Form.setLabel(this, "value");
>                         }});
>                         add(new Label() {{
>                             setTextKey("change");
>                             setTextBindMapping(changeMapping_6);
>                             setStyles("{horizontalAlignment:'right'}");
>                             Form.setLabel(this, "change");
>                         }});
>                         add(new Label() {{
>                             setTextKey("openingValue");
>                             setTextBindMapping(valueMapping_5);
>                             setStyles("{horizontalAlignment:'right'}");
>                             Form.setLabel(this, "openingValue");
>                         }});
>                         add(new Label() {{
>                             setTextKey("highValue");
>                             setTextBindMapping(valueMapping_5);
>                             setStyles("{horizontalAlignment:'right'}");
>                             Form.setLabel(this, "highValue");
>                         }});
>                         add(new Label() {{
>                             setTextKey("lowValue");
>                             setTextBindMapping(valueMapping_5);
>                             setStyles("{horizontalAlignment:'right'}");
>                             Form.setLabel(this, "lowValue");
>                         }});
>                         add(new Label() {{
>                             setTextKey("volume");
>                             setTextBindMapping(volumeMapping_7);
>                             setStyles("{horizontalAlignment:'right'}");
>                             Form.setLabel(this, "volume");
>                         }});
>                     }});
>                 }});
>             }};
>         } catch (Exception e) {
>             e.printStackTrace();
>             throw new RuntimeException(e);
>         }
>     }
>
> -----
> detail_pane.bxml
>
> <BoxPane orientation="vertical" styles="{fill:true}"
>     xmlns:bxml="http://pivot.apache.org/bxml"
>     xmlns:stocktracker="org.apache.pivot.tutorials.stocktracker"
>     xmlns="org.apache.pivot.wtk">
>     <Label textKey="companyName" styles="{font:{size:12, bold:true}}"/>
>
>     <Separator/>
>
>     <Form styles="{padding:0, fill:true, showFlagIcons:false,
> showFlagHighlight:false,
>         leftAlignLabels:true}">
>         <Form.Section>
>             <bxml:define>
>                 <stocktracker:ValueMapping bxml:id="valueMapping"/>
>                 <stocktracker:ChangeMapping bxml:id="changeMapping"/>
>                 <stocktracker:VolumeMapping bxml:id="volumeMapping"/>
>             </bxml:define>
>
>             <Label bxml:id="valueLabel" Form.label="%value"
>                 textKey="value" textBindMapping="$valueMapping"
>                 styles="{horizontalAlignment:'right'}"/>
>             <Label bxml:id="changeLabel" Form.label="%change"
>                 textKey="change" textBindMapping="$changeMapping"
>                 styles="{horizontalAlignment:'right'}"/>
>             <Label bxml:id="openingValueLabel" Form.label="%openingValue"
>                 textKey="openingValue" textBindMapping="$valueMapping"
>                 styles="{horizontalAlignment:'right'}"/>
>             <Label bxml:id="highValueLabel" Form.label="%highValue"
>                 textKey="highValue" textBindMapping="$valueMapping"
>                 styles="{horizontalAlignment:'right'}"/>
>             <Label bxml:id="lowValueLabel" Form.label="%lowValue"
>                 textKey="lowValue" textBindMapping="$valueMapping"
>                 styles="{horizontalAlignment:'right'}"/>
>             <Label bxml:id="volumeLabel" Form.label="%volume"
>                 textKey="volume" textBindMapping="$volumeMapping"
>                 styles="{horizontalAlignment:'right'}"/>
>         </Form.Section>
>     </Form>
> </BoxPane>
>
> On Tue, Dec 21, 2010 at 11:06 AM, calathus <ca...@gmail.com> wrote:
>
>> Greg,
>> There were a few questions, and I did not have investigated these lines
>> much, so I searched the similar projects.
>>
>> For the CRUD stuff, I will answer later.
>>
>> For the Scala Pivot builder approach, as you and Clint suggested, I was
>> thinking something similar o Gvoovy's SwingBuilder approach.
>> Right now, Scala 2.8.1's scala.swing library is not taking this type of
>> builder approach. So I looked for some other library.
>> I found squib project:
>> http://code.google.com/p/scala-squib/
>>
>>
>> Unfortunately, Scala is still evolving language, this squid project could
>> not be compiled in the latest 2.8.1, but with a few code changes, I could
>> resolved these errors. (but somehow how, running demo did not work with ant)
>>
>> So If we change Swing API to Pivot API, we will be able to have similar
>> builder.
>> Here is a sample code from the squib project:
>>
>> import java.awt.GridBagConstraints._
>> import java.beans.{PropertyChangeListener, PropertyChangeEvent}
>> import java.lang.reflect.Method
>> import javax.swing._
>> import javax.swing.event._
>>
>> import scala.reflect.BeanProperty
>>
>> import net.miginfocom.swing.MigLayout
>>
>> package tfd.scala.squib.demo {
>>
>> import tfd.scala.squib._
>> import tfd.scala.squib.event._
>>
>>  object RGBSliders extends Application {
>>     class RGBCanvasComponent extends JComponent {
>>         private var red:Int = 0
>>         private var green:Int = 0
>>         private var blue:Int = 0
>>
>>         def setRed(value:Int) = {
>>             if (value != red) {
>>                 red = value
>>                 repaint()
>>             }
>>         }
>>
>>         def setGreen(value:Int) = {
>>             if (value != green) {
>>                 green = value
>>                 repaint()
>>             }
>>         }
>>
>>         def setBlue(value:Int) = {
>>             if (value != blue) {
>>                 blue = value
>>                 repaint()
>>             }
>>         }
>>
>>         override def paint(g: Graphics):Unit = {
>>             g.setColor(new Color(red, green, blue))
>>             val d = getSize()
>>             g.fillRect(0,0, d.width, d.height)
>>         }
>>     }
>>
>>     object rgbcanvas extends BuiltComponent[RGBCanvasComponent] {
>>         def newComponent = new RGBCanvasComponent()
>>     }
>>
>>      lazy val rgb = rgbcanvas.id("rgbcanvas")
>>
>>     frame(
>>             'title->"RGB Selector",
>>             'visible -> true,
>>             'defaultCloseOperation -> JFrame.EXIT_ON_CLOSE,
>>             'layout -> new MigLayout("fill, wrap 3", "align right, grow",
>> "align top, grow"),
>>             contents(
>>                  label("Red:"),
>>                  slider("red", 'maximum -> 255, 'minimum-> 0, 'value->0,
>> sliderValueChanged(&rgb.setRed)),
>>                  rgbcanvas("rgbcanvas",
>>                                'preferredSize -> new Dimension(100,100),
>>                                'red -> 0,
>>                                'green -> 0,
>>                                'blue -> 0
>>                  ) -> "spany 3",
>>                  label("Green:"),
>>                  slider("green", 'maximum -> 255, 'minimum-> 0, 'value->0,
>> sliderValueChanged(&rgb.setGreen)),
>>                  label("Blue:"),
>>                  slider("blue", 'maximum -> 255, 'minimum-> 0, 'value->0,
>> sliderValueChanged(&rgb.setBlue))
>>             )
>>     ).pack
>>  }
>> }
>>
>>
>> On Mon, Dec 20, 2010 at 6:04 AM, Greg Brown <gk...@verizon.net> wrote:
>>
>>> As Chris mentioned, Pivot does not currently provide a BXML to Java
>>> compiler. We actually prototyped one a while back, but it was never
>>> completed due to other priorities.
>>>
>>> Generating byte code from BXML might be tough, but converting it to a
>>> Java source file would probably be pretty easy. Let me know if you are
>>> interested in trying to write something like this - I would be happy to try
>>> to help when I can.
>>>
>>> G
>>>
>>> On Dec 19, 2010, at 10:26 PM, calathus wrote:
>>>
>>> > Hi,
>>> > I'm looking for a tool to convert bxml file to equivalent Java source
>>> program.
>>> > Are there such tools?
>>> >
>>> > I just started using pivot, but many of sample is based on bxml.
>>> > I think in order to develop a UI library with Java generic class, XML
>>> file based approach is not appropriate.
>>> >
>>> > And xml based approach will reduce static error detection capability.
>>> > I liked to see  more examples using  Java classes to define GUI without
>>> relying on bxml files.
>>> >
>>> > --
>>> > Cheers,
>>> > calathus
>>> >
>>> >
>>> >
>>>
>>>
>>
>>
>> --
>> Cheers,
>> calathus
>>
>>
>>
>>
>
>
> --
> Cheers,
> calathus
>
>
>
>
>

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Sandro Martini <sa...@gmail.com>.
Hi, just created the ticket (to not forget it):
https://issues.apache.org/jira/browse/PIVOT-691

It's for the 2.1 release, but maybe even before (it it will be the case) ...

Bye,
Sandro

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
I haven't had a chance to look at the code yet, but I am thinking that we could probably add events to BXMLSerializer that this code could hook into (similar to the events fired by CSVSerializer, JSONSerializer, and XMLSerializer).
G

On Dec 30, 2010, at 4:32 AM, Sandro Martini wrote:

> 
> Hi, 
> thanks for the new link, but as you I'm too much busy at the moment (and I
> have not so much knowledge on BXML internals at the moment) ... if you do
> not hurry I can try to take a look in next weeks, and tell you.
> 
> Greg (and others) what do you think on see what should be changed in
> BXMLSerializer (for the 2.1 release) to enable a subclass of it to do the
> code generation stuff ? 
> I can add a jira ticket and put some info there so we can keep track of this
> ... tell me.
> 
> Bye,
> Sandro
> 
> -- 
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/pivot-are-there-any-tools-to-convert-bxml-to-Java-tp2118284p2166783.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> I'm not familar with the implemetation of selectedIndex, but my guess is that it is used when some getSelectedElement is called. If that is the case, if there are no selected element is found, it can use the selectedDefaultIndex information to get the element from the elements. These or some lazy evaluation function are often used idiom, it is not umbiguos.

Again, Pivot components have no knowledge of "elements". "selectedIndex" simply maps to getSelectedIndex() and setSelectedIndex() in the TabPane class.

> As I said, (although I mentioned code generator), my main concern is what kind of hand write coding style can be supported with Pivot library.
> If there is not much such exception like selectedIndex, I do not care much for this issue.

These cases certainly exist, but they are not the common case.

> But I think there are useful information for you to understand what kind of problems pivot users would face when they start writing Java code directly.

I do understand these issues. Pivot is fundamentally a Java UI toolkit. Originally, it didn't even have a markup language - all user interfaces were constructed entirely programmatically. We added markup support later for the sake of convenience and readability.

G



Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
On Mon, Jan 3, 2011 at 3:37 PM, Greg Brown <gk...@verizon.net> wrote:

> > It would be confusing to change the semantics of existing selectedIndex.
> It looks like very imperative operator which is not appropriate for using
> element attribute declaration.
>
> ...and yet BXML, which uses attributes extensively, handles it just fine.
>  :-)
>
> > The clearer approach would be to introduce new declarative attribute
> operator like selectedDefaultIndex, which will not apply immediately for the
> existing element list.
>
> When would it be applied? This is what I mean when I say it would be more
> confusing. I know immediately what "selectedIndex" and setSelectedIndex()
> do. I have no idea what "selectedDefaultIndex" means.
>

I'm not familar with the implemetation of selectedIndex, but my guess is
that it is used when some getSelectedElement is called. If that is the case,
if there are no selected element is found, it can use the
selectedDefaultIndex information to get the element from the elements. These
or some lazy evaluation function are often used idiom, it is not umbiguos.



>
> > But as you will see, we need to know which attributes need to be defined
> later, we must have detailed knowledge for the API. these are not so
> easy/simple API for the user.
>
> I think you may be getting hung up on trying to automatically generate code
> that is organized the way you want it. A developer writing out your builder
> syntax by hand will know when it is appropriate to call each setter, and
> (once again) it does not matter where these attributes are set in generated
> code.
>

As I said, (although I mentioned code generator), my main concern is what
kind of hand write coding style can be supported with Pivot library.
If there is not much such exception like selectedIndex, I do not care much
for this issue.
But I think there are useful information for you to understand what kind of
problems pivot users would face when they start writing Java code directly.


>
> G
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> It would be confusing to change the semantics of existing selectedIndex. It looks like very imperative operator which is not appropriate for using element attribute declaration.

...and yet BXML, which uses attributes extensively, handles it just fine.  :-)

> The clearer approach would be to introduce new declarative attribute operator like selectedDefaultIndex, which will not apply immediately for the existing element list.

When would it be applied? This is what I mean when I say it would be more confusing. I know immediately what "selectedIndex" and setSelectedIndex() do. I have no idea what "selectedDefaultIndex" means.

> But as you will see, we need to know which attributes need to be defined later, we must have detailed knowledge for the API. these are not so easy/simple API for the user.

I think you may be getting hung up on trying to automatically generate code that is organized the way you want it. A developer writing out your builder syntax by hand will know when it is appropriate to call each setter, and (once again) it does not matter where these attributes are set in generated code.

G


Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
On Mon, Jan 3, 2011 at 2:07 PM, Greg Brown <gk...@verizon.net> wrote:

> > If the bxml definition(or GUI) is so simple, this attributes order would
> not be a big issue.
> > but if we have more complex definition like stock_tracker_window.bxml
> file, the corresponding Java code will be following big size.
> > You would imagine how frustration to find corresponding element from
> attribute definitions  if they are moved to after inner class definitions.
>
> If you prefer to see most of your attribute setters before the creation of
> the sub-elements, there's no reason you can't do that. However, there's
> simply no way to avoid calling some setters after sub-element creation. I
> don't see this as a big deal at all, and I actually think it helps improve
> readability - it makes it obvious that those setters depend on the prior
> code having been executed.
>
> And again, this only applies to hand-coded builder code. For the reasons I
> mentioned before, it isn't relevant to generated code. I understand that it
> would be ideal to be able to put all of your setters in one place, but
> logically it just doesn't work (unless you do some sort of deferred set,
> which I actually think has the potential to make the code more confusing).
>

It would be confusing to change the semantics of existing selectedIndex. It
looks like very imperative operator which is not appropriate for using
element attribute declaration.
The clearer approach would be to introduce new declarative attribute
operator like selectedDefaultIndex, which will not apply immediately for the
existing element list.

As a workaround, I would change the code so that selectedIndex java code
will be commented out, but declared at opening tag.
then only selectedIndex type java code will be generated at the closing tag
without comment.
But as you will see, we need to know which attributes need to be defined
later, we must have detailed knowledge for the API. these are not so
easy/simple API for the user.




>
> G
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> If the bxml definition(or GUI) is so simple, this attributes order would not be a big issue.
> but if we have more complex definition like stock_tracker_window.bxml file, the corresponding Java code will be following big size.
> You would imagine how frustration to find corresponding element from attribute definitions  if they are moved to after inner class definitions.

If you prefer to see most of your attribute setters before the creation of the sub-elements, there's no reason you can't do that. However, there's simply no way to avoid calling some setters after sub-element creation. I don't see this as a big deal at all, and I actually think it helps improve readability - it makes it obvious that those setters depend on the prior code having been executed.

And again, this only applies to hand-coded builder code. For the reasons I mentioned before, it isn't relevant to generated code. I understand that it would be ideal to be able to put all of your setters in one place, but logically it just doesn't work (unless you do some sort of deferred set, which I actually think has the potential to make the code more confusing).

G


Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
If the bxml definition(or GUI) is so simple, this attributes order would not
be a big issue.
but if we have more complex definition like stock_tracker_window.bxml file,
the corresponding Java code will be following big size.
You would imagine how frustration to find corresponding element from
attribute definitions  if they are moved to after inner class definitions.


    static StockTrackerWindow create() throws Exception {
        return new StockTrackerWindow() {{
            final Map<String, Object> namespace = new HashMap<String, Object>();
            setTitle("Pivot Stock Tracker");
            setMaximized(true);
            setContent(new TablePane() {{
                setStyles("{padding:8, horizontalSpacing:6,
verticalSpacing:6}");
                // columns(): READ_ONLY_PROPERTY
                getColumns().add(new TablePane.Column() {{
                    setWidth(1, true);
                }}); // INSTANCE, name: <TablePane.Column>
                getRows().add(new TablePane.Row() {{
                    setHeight(-1);
                    add(new Label() {{
                        setText("Pivot Stock Tracker");
                        setStyles("{font:{size:14, bold:true},
verticalAlignment:'center'}");
                    }}); // INSTANCE, name: <Label>
                }}); // INSTANCE, name: <TablePane.Row>
                getRows().add(new TablePane.Row() {{
                    setHeight(1, true);
                    add(new SplitPane() {{
                        setSplitRatio(0.4f);
                        // left(): WRITABLE_PROPERTY
                        setLeft(new Border() {{
                            setStyles("{color:10}");
                            setContent(new ScrollPane() {{

setHorizontalScrollBarPolicy(ScrollPane.ScrollBarPolicy.FILL_TO_CAPACITY);

setVerticalScrollBarPolicy(ScrollPane.ScrollBarPolicy.FILL_TO_CAPACITY);
                                setView(new StackPane() {{
                                    add(new TableView() {{
                                        namespace.put("stocksTableView", this);

setSelectMode(TableView.SelectMode.MULTI);

setStyles("{showHorizontalGridLines:false}");
                                        // columns(): READ_ONLY_PROPERTY
                                        getColumns().add(new
TableView.Column() {{
                                            setName("symbol");
                                            setHeaderData("Symbol");
                                            setWidth(1, true);
                                        }}); // INSTANCE, name:
<TableView.Column>
                                        getColumns().add(new
TableView.Column() {{
                                            setName("value");
                                            setHeaderData("Value");
                                            setWidth(1, true);
                                            // cellRenderer(): WRITABLE_PROPERTY
                                            setCellRenderer(new
TableViewNumberCellRenderer() {{

setStyles("{horizontalAlignment:'right'}");
                                                setNumberFormat("$0.00");
                                            }}); // INSTANCE, name:
<content:TableViewNumberCellRenderer>
                                        }}); // INSTANCE, name:
<TableView.Column>
                                        getColumns().add(new
TableView.Column() {{
                                            setName("change");
                                            setHeaderData("Change");
                                            setWidth(1, true);
                                            // cellRenderer(): WRITABLE_PROPERTY
                                            setCellRenderer(new
ChangeCellRenderer() {{

setStyles("{horizontalAlignment:'right'}");
                                                setNumberFormat("+0.00;-0.00");
                                            }}); // INSTANCE, name:
<stocktracker:ChangeCellRenderer>
                                        }}); // INSTANCE, name:
<TableView.Column>
                                    }}); // INSTANCE, name: <TableView>
                                }}); // INSTANCE, name: <StackPane>
                                // columnHeader(): WRITABLE_PROPERTY
                                setColumnHeader(new TableViewHeader() {{

setTableView((TableView)namespace.get("stocksTableView"));

setSortMode(TableViewHeader.SortMode.SINGLE_COLUMN);
                                }}); // INSTANCE, name: <TableViewHeader>
                            }}); // INSTANCE, name: <ScrollPane>
                        }}); // INSTANCE, name: <Border>
                        // right(): WRITABLE_PROPERTY
                        setRight(new Border() {{
                            setStyles("{padding:6, color:10}");
                                setContent(new BoxPane() {{
                                    namespace.put("detailPane", this);
                                    setOrientation(Orientation.VERTICAL);
                                    setStyles("{fill:true}");
                                    add(new Label() {{
                                        setTextKey("companyName");
                                        setStyles("{font:{size:12,
bold:true}}");
                                    }}); // INSTANCE, name: <Label>
                                    add(new Separator() {{
                                    }}); // INSTANCE, name: <Separator>
                                    add(new Form() {{
                                        setStyles("{padding:0,
fill:true, showFlagIcons:false, showFlagHighlight:false,
leftAlignLabels:true}");
                                        getSections().add(new Form.Section() {{
                                            final ValueMapping
valueMapping_0 = (new ValueMapping() {{

namespace.put("valueMapping", this);
                                                }}); // INSTANCE,
name: <stocktracker:ValueMapping>
                                            final ChangeMapping
changeMapping_1 = (new ChangeMapping() {{

namespace.put("changeMapping", this);
                                                }}); // INSTANCE,
name: <stocktracker:ChangeMapping>
                                            final VolumeMapping
volumeMapping_2 = (new VolumeMapping() {{

namespace.put("volumeMapping", this);
                                                }}); // INSTANCE,
name: <stocktracker:VolumeMapping>
                                            add(new Label() {{

namespace.put("valueLabel", this);
                                                setTextKey("value");

setTextBindMapping(valueMapping_0);

setStyles("{horizontalAlignment:'right'}");
                                                Form.setLabel(this, "Value");
                                            }}); // INSTANCE, name: <Label>
                                            add(new Label() {{

namespace.put("changeLabel", this);
                                                setTextKey("change");

setTextBindMapping(changeMapping_1);

setStyles("{horizontalAlignment:'right'}");
                                                Form.setLabel(this, "Change");
                                            }}); // INSTANCE, name: <Label>
                                            add(new Label() {{

namespace.put("openingValueLabel", this);
                                                setTextKey("openingValue");

setTextBindMapping(valueMapping_0);

setStyles("{horizontalAlignment:'right'}");
                                                Form.setLabel(this, "Open");
                                            }}); // INSTANCE, name: <Label>
                                            add(new Label() {{

namespace.put("highValueLabel", this);
                                                setTextKey("highValue");

setTextBindMapping(valueMapping_0);

setStyles("{horizontalAlignment:'right'}");
                                                Form.setLabel(this, "High");
                                            }}); // INSTANCE, name: <Label>
                                            add(new Label() {{

namespace.put("lowValueLabel", this);
                                                setTextKey("lowValue");

setTextBindMapping(valueMapping_0);

setStyles("{horizontalAlignment:'right'}");
                                                Form.setLabel(this, "Low");
                                            }}); // INSTANCE, name: <Label>
                                            add(new Label() {{

namespace.put("volumeLabel", this);
                                                setTextKey("volume");

setTextBindMapping(volumeMapping_2);

setStyles("{horizontalAlignment:'right'}");
                                                Form.setLabel(this, "Volume");
                                            }}); // INSTANCE, name: <Label>
                                        }}); // INSTANCE, name: <Form.Section>
                                    }}); // INSTANCE, name: <Form>

CodeEmitterRuntime.initialize(this, namespace);
                                }}); // INSTANCE, name: <BoxPane>
                        }}); // INSTANCE, name: <Border>
                    }}); // INSTANCE, name: <SplitPane>
                }}); // INSTANCE, name: <TablePane.Row>
                getRows().add(new TablePane.Row() {{
                    setHeight(-1);
                    add(new BoxPane() {{
                        setStyles("{horizontalAlignment:'left',
verticalAlignment:'center'}");
                        add(new Label() {{
                            setText("Symbol");
                            setStyles("{font:{bold:true}}");
                        }}); // INSTANCE, name: <Label>
                        add(new TextInput() {{
                            namespace.put("symbolTextInput", this);
                            setTextSize(10);
                            setMaximumLength(8);
                        }}); // INSTANCE, name: <TextInput>
                        add(new LinkButton() {{
                            namespace.put("addSymbolButton", this);
                            setEnabled(false);
                            setTooltipText("Add symbol");
                            setButtonData(new ButtonData() {{
                                setIcon(new
URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/stocktracker/add.png"));
                            }}); // INSTANCE, name: <content:ButtonData>
                        }}); // INSTANCE, name: <LinkButton>
                        add(new LinkButton() {{
                            namespace.put("removeSymbolsButton", this);
                            setEnabled(false);
                            setTooltipText("Remove selected symbols");
                            setButtonData(new ButtonData() {{
                                setIcon(new
URL("file:/share/workspace/pivot/tutorials/src/org/apache/pivot/tutorials/stocktracker/delete.png"));
                            }}); // INSTANCE, name: <content:ButtonData>
                        }}); // INSTANCE, name: <LinkButton>
                    }}); // INSTANCE, name: <BoxPane>
                }}); // INSTANCE, name: <TablePane.Row>
                getRows().add(new TablePane.Row() {{
                    setHeight(-1);
                    add(new TablePane() {{
                        // columns(): READ_ONLY_PROPERTY
                        getColumns().add(new TablePane.Column() {{
                            setWidth(1, true);
                        }}); // INSTANCE, name: <TablePane.Column>
                        getColumns().add(new TablePane.Column() {{
                            setWidth(-1);
                        }}); // INSTANCE, name: <TablePane.Column>
                        getRows().add(new TablePane.Row() {{
                            add(new BoxPane() {{
                                add(new Label() {{
                                    setText("Last Update");
                                }}); // INSTANCE, name: <Label>
                                add(new Label() {{
                                    namespace.put("lastUpdateLabel", this);
                                }}); // INSTANCE, name: <Label>
                            }}); // INSTANCE, name: <BoxPane>
                            add(new BoxPane() {{
                                setStyles("{horizontalAlignment:'right'}");
                                add(new Label() {{
                                    setText("Data provided by");
                                }}); // INSTANCE, name: <Label>
                                add(new LinkButton() {{
                                    namespace.put("yahooFinanceButton", this);
                                    setButtonData("Yahoo! Finance");
                                }}); // INSTANCE, name: <LinkButton>
                            }}); // INSTANCE, name: <BoxPane>
                        }}); // INSTANCE, name: <TablePane.Row>
                    }}); // INSTANCE, name: <TablePane>
                }}); // INSTANCE, name: <TablePane.Row>
            }}); // INSTANCE, name: <TablePane>
            CodeEmitterRuntime.bind(this, namespace, "stocksTableView");
            CodeEmitterRuntime.bind(this, namespace, "symbolTextInput");
            CodeEmitterRuntime.bind(this, namespace, "addSymbolButton");
            CodeEmitterRuntime.bind(this, namespace, "removeSymbolsButton");
            CodeEmitterRuntime.bind(this, namespace, "detailPane");
            CodeEmitterRuntime.bind(this, namespace, "lastUpdateLabel");
            CodeEmitterRuntime.bind(this, namespace, "yahooFinanceButton");
            CodeEmitterRuntime.initialize(this, namespace);
        }};
    }



On Mon, Jan 3, 2011 at 1:35 PM, Greg Brown <gk...@verizon.net> wrote:

> Here's an example of what I mean. The following two files generate the
> exact same output:
>
>
> http://svn.apache.org/repos/asf/pivot/trunk/examples/src/org/apache/pivot/examples/builder/BuilderExample.java
>
> http://svn.apache.org/repos/asf/pivot/trunk/examples/src/org/apache/pivot/examples/builder/builder_example.bxml
>
> The Java version uses your builder pattern, but sets the property values
> after processing the child content. I don't think readability suffers in the
> least - the logic is still quite easy to follow.
>
> G
>
> On Jan 3, 2011, at 4:09 PM, Greg Brown wrote:
>
> >> I understand your position. But the attribute order, final classes
> issues are independent from BXML to Java converter.
> >> The current API will prohibit readable Java code written by hand.
> >> If you check the generated code sample in my github, and move all
> attributes after all of inner elements declaration, you will not like to
> have that codes.
> >
> > The final class issue is definitely a problem for your pattern. But I
> don't see the issue with attribute ordering. There's simply no way to set
> the selectedIndex property of a tab pane before the tabs have been created.
> It has to be done afterwards.
> >
> >
> >
> >
> >
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
Here's an example of what I mean. The following two files generate the exact same output:

http://svn.apache.org/repos/asf/pivot/trunk/examples/src/org/apache/pivot/examples/builder/BuilderExample.java
http://svn.apache.org/repos/asf/pivot/trunk/examples/src/org/apache/pivot/examples/builder/builder_example.bxml

The Java version uses your builder pattern, but sets the property values after processing the child content. I don't think readability suffers in the least - the logic is still quite easy to follow.

G

On Jan 3, 2011, at 4:09 PM, Greg Brown wrote:

>> I understand your position. But the attribute order, final classes issues are independent from BXML to Java converter.
>> The current API will prohibit readable Java code written by hand.
>> If you check the generated code sample in my github, and move all attributes after all of inner elements declaration, you will not like to have that codes.
> 
> The final class issue is definitely a problem for your pattern. But I don't see the issue with attribute ordering. There's simply no way to set the selectedIndex property of a tab pane before the tabs have been created. It has to be done afterwards.
> 
> 
> 
> 
> 


Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
>  I understand your position. But the attribute order, final classes issues are independent from BXML to Java converter.
> The current API will prohibit readable Java code written by hand.
> If you check the generated code sample in my github, and move all attributes after all of inner elements declaration, you will not like to have that codes.

The final class issue is definitely a problem for your pattern. But I don't see the issue with attribute ordering. There's simply no way to set the selectedIndex property of a tab pane before the tabs have been created. It has to be done afterwards.






Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
On Mon, Jan 3, 2011 at 12:34 PM, Greg Brown <gk...@verizon.net> wrote:

> > OK, I'm not actually thinking BXML should be abandoned.  There are many
> type of user and usage scenario which would fit BXML approach.
> > But these approach is static, it is not good fit for creating more
> dynamic library for GUI(for instance the number of table columns are changed
> based on passed parameter class).
> > Since you put low priority for supporting readable Java code generation,
> I thought you may not be interested in this type of approach.
>
> I don't see the value in trying to generate "readable" Java code from BXML.
> If you are a developer who prefers to declare your UI in Java (perhaps using
> your builder approach), then you probably won't be using BXML anyways and
> won't care what the generated code looks like. If you are a developer who
> prefers BXML, you most likely will never look at the generated code, since
> presumably you want to continue developing in BXML and only use the compiler
> for the performance or compile-time type safety benefits.
>

 I understand your position. But the attribute order, final classes issues
are independent from BXML to Java converter.
The current API will prohibit readable Java code written by hand.
If you check the generated code sample in my github, and move all attributes
after all of inner elements declaration, you will not like to have that
codes.



> Besides, all we're really talking about here is where generated attribute
> setters go. The generated code would still be quite readable - it just may
> not be organized exactly the way you would do it had you written it by hand.
> To me, that's just not a major issue.
>
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> OK, I'm not actually thinking BXML should be abandoned.  There are many type of user and usage scenario which would fit BXML approach.
> But these approach is static, it is not good fit for creating more dynamic library for GUI(for instance the number of table columns are changed based on passed parameter class).
> Since you put low priority for supporting readable Java code generation, I thought you may not be interested in this type of approach.

I don't see the value in trying to generate "readable" Java code from BXML. If you are a developer who prefers to declare your UI in Java (perhaps using your builder approach), then you probably won't be using BXML anyways and won't care what the generated code looks like. If you are a developer who prefers BXML, you most likely will never look at the generated code, since presumably you want to continue developing in BXML and only use the compiler for the performance or compile-time type safety benefits.

Besides, all we're really talking about here is where generated attribute setters go. The generated code would still be quite readable - it just may not be organized exactly the way you would do it had you written it by hand. To me, that's just not a major issue.



Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
On Mon, Jan 3, 2011 at 12:10 PM, Greg Brown <gk...@verizon.net> wrote:

> > Pivot definitely can support Java in similar level as Swing.
> > So at this level, I think there are not much disagreement.
> >
> > Also you would think swing style is not usable, so you introduced BXML.
> > But I want to have an usable Java framework without relying on external
> framework(XML)
> > I wonder why you are not interesting in this type of approach.
>
> What makes you think I am not interested? I have already said repeatedly
> that I like the approach you have suggested. But I think that it should be
> an addition to the existing XML approach, not a replacement for it.
>

OK, I'm not actually thinking BXML should be abandoned.  There are many type
of user and usage scenario which would fit BXML approach.
But these approach is static, it is not good fit for creating more dynamic
library for GUI(for instance the number of table columns are changed based
on passed parameter class).
Since you put low priority for supporting readable Java code generation, I
thought you may not be interested in this type of approach.





-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> Pivot definitely can support Java in similar level as Swing.
> So at this level, I think there are not much disagreement.
> 
> Also you would think swing style is not usable, so you introduced BXML.
> But I want to have an usable Java framework without relying on external framework(XML)
> I wonder why you are not interesting in this type of approach.

What makes you think I am not interested? I have already said repeatedly that I like the approach you have suggested. But I think that it should be an addition to the existing XML approach, not a replacement for it.



Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
On Mon, Jan 3, 2011 at 11:54 AM, Greg Brown <gk...@verizon.net> wrote:

> > Vaadin is quite old project around 10 year old.(they renamed it recently)
>
> Ah, that makes sense. It did seem pretty mature for what seemed like such a
> young product.
>
> > Anyway, it is more costructive to have better model than just following
> old model/style like swing.
> > I personally did not interested in using these Java API before since it
> was so messy.
>
> I agree with you - that's why we created BXML. However, saying that you
> would prefer a better approach is not the same thing as saying that Pivot
> does not support Java.
>

Pivot definitely can support Java in similar level as Swing.
So at this level, I think there are not much disagreement.

Also you would think swing style is not usable, so you introduced BXML.
But I want to have an usable Java framework without relying on external
framework(XML)
I wonder why you are not interesting in this type of approach.



> G
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> Vaadin is quite old project around 10 year old.(they renamed it recently)

Ah, that makes sense. It did seem pretty mature for what seemed like such a young product.

> Anyway, it is more costructive to have better model than just following old model/style like swing.
> I personally did not interested in using these Java API before since it was so messy.

I agree with you - that's why we created BXML. However, saying that you would prefer a better approach is not the same thing as saying that Pivot does not support Java.

G


Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
On Mon, Jan 3, 2011 at 11:16 AM, Greg Brown <gk...@verizon.net> wrote:

> > I think just telling the technological possibility is not good enough to
> claim Java API based approach is supported.(it similar to claim machine
> language can support anything)
>
> Huh? Have you actually looked at the Javadoc? It isn't just a
> "technological possibility" - the entire platform is written in Java! Take
> BXML out of the picture and every feature would still work.
>
> > If it can support readable GUI description in Java, we should claim it
> supports Java API based development.
>
> Here is an example of a readable Pivot GUI description in Java:
>
> PushButton pushButton = new PushButton();
> pushButton.setButtonData("My Button");
>
> The builder syntax you proposed is nice, but it is certainly not a
> requirement for saying that Pivot supports Java development. It is simply a
> design pattern. Would you say that Swing does not support Java development
> because it does not provide a builder syntax? If so, I doubt that you would
> find many who would agree.
>
> > Yes, Vaadin is server based stateful session approach. So it has a
> problem to support cloud based server infrastructure like Google app engine.
> > That was the main reason I was more interested in Pivot.
> > But for GUI developing phase, these difference of deployment approach are
> not much noticeable. In this sense, I thought Pivot and Vaadin is similar.
> And I expected Pivot be  similar to Vaadin when I start evaluating Pivot.
>
> You may want to adjust that expectation. We did not model the design of
> Pivot on Vaadin in any way. In fact, I'm not even sure that Vaadin existed
> when Pivot 1.0 was released. Pivot's architecture was much more heavily
> influenced by the design of Swing, Flex, and WPF.
>

Vaadin is quite old project around 10 year old.(they renamed it recently)
Anyway, it is more costructive to have better model than just following old
model/style like swing.
I personally did not interested in using these Java API before since it was
so messy.



>
> G
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> I think just telling the technological possibility is not good enough to claim Java API based approach is supported.(it similar to claim machine language can support anything)

Huh? Have you actually looked at the Javadoc? It isn't just a "technological possibility" - the entire platform is written in Java! Take BXML out of the picture and every feature would still work. 

> If it can support readable GUI description in Java, we should claim it supports Java API based development.

Here is an example of a readable Pivot GUI description in Java:

PushButton pushButton = new PushButton();
pushButton.setButtonData("My Button");

The builder syntax you proposed is nice, but it is certainly not a requirement for saying that Pivot supports Java development. It is simply a design pattern. Would you say that Swing does not support Java development because it does not provide a builder syntax? If so, I doubt that you would find many who would agree.

> Yes, Vaadin is server based stateful session approach. So it has a problem to support cloud based server infrastructure like Google app engine.
> That was the main reason I was more interested in Pivot.
> But for GUI developing phase, these difference of deployment approach are not much noticeable. In this sense, I thought Pivot and Vaadin is similar. And I expected Pivot be  similar to Vaadin when I start evaluating Pivot.

You may want to adjust that expectation. We did not model the design of Pivot on Vaadin in any way. In fact, I'm not even sure that Vaadin existed when Pivot 1.0 was released. Pivot's architecture was much more heavily influenced by the design of Swing, Flex, and WPF.

G


Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
On Mon, Jan 3, 2011 at 10:08 AM, Greg Brown <gk...@verizon.net> wrote:

> > I think some people would prefer to use BXML style, but the point here is
> Java API based development should be equally well supported.(without
> assuming the use of BXML).
>
> It is. You are not required to use BXML. Anything that can be done in BXML
> can also be done in Java or any other JVM language. BXML is just a shortcut
> to writing such code by hand.
>
I think just telling the technological possibility is not good enough to
claim Java API based approach is supported.(it similar to claim machine
language can support anything)
If it can support readable GUI description in Java, we should claim it
supports Java API based development.


>
> > I think Pivot is, in the basic Java oriented approach, more closer to
> Vaadin than Silverlight etc. Vaadin explicitly avoid using any form of XML
> as basic policy, it emphasizes pure Java based approach. I wonder Pivot
> developers have looked at the project..
>
> I am loosely familiar with Vaadin. However, I believe Pivot and Vaadin
> address different use cases. Pivot (like Flex and Silverlight) runs on the
> client, whereas Vaadin runs on the server. To me, Vaadin seems more closely
> related to something like Canoo than Pivot.
>
> Yes, Vaadin is server based stateful session approach. So it has a problem
to support cloud based server infrastructure like Google app engine.
That was the main reason I was more interested in Pivot.
But for GUI developing phase, these difference of deployment approach are
not much noticeable. In this sense, I thought Pivot and Vaadin is similar.
And I expected Pivot be  similar to Vaadin when I start evaluating Pivot.



-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> I think some people would prefer to use BXML style, but the point here is Java API based development should be equally well supported.(without assuming the use of BXML).

It is. You are not required to use BXML. Anything that can be done in BXML can also be done in Java or any other JVM language. BXML is just a shortcut to writing such code by hand.

> I think Pivot is, in the basic Java oriented approach, more closer to Vaadin than Silverlight etc. Vaadin explicitly avoid using any form of XML as basic policy, it emphasizes pure Java based approach. I wonder Pivot developers have looked at the project..

I am loosely familiar with Vaadin. However, I believe Pivot and Vaadin address different use cases. Pivot (like Flex and Silverlight) runs on the client, whereas Vaadin runs on the server. To me, Vaadin seems more closely related to something like Canoo than Pivot.


Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
On Mon, Jan 3, 2011 at 9:44 AM, Greg Brown <gk...@verizon.net> wrote:

> On Mon, Jan 3, 2011 at 8:38 AM, Greg Brown <gk...@verizon.net> wrote:
>
>> If the attribute was processed in the opening tag, we'd get an
>>> IndexOutOfBoundsException, since the Labels would not have been added yet.
>>>
>>
>> This is the problem I faced. But most of other attribute seems OK to set
>> at the opening tag.
>>
>>
>> Correct - many attributes can be set in the opening tag, but any that have
>> dependencies on child elements cannot. Since there is no harm in setting all
>> attributes in the closing tag, that is what we do.
>>
>> If Pivot is used only through BXML, these order are hidden from user, it
>> may not matter.
>> But if it is directly used in Java codes, this makes code hard to read.
>>
>>
>> Agreed, but if you are hand-coding using your builder style, you can put
>> the setters wherever you like. If you are using a BXML to Java converter, it
>> doesn't really matter where they go because the generated code isn't really
>> meant to be human-readable (that's what BXML is for).
>>
>
> This is quite opposite for my purpose. I would want to have human readable
> Java code. In fact, If we do start using this builder style, we will not
> need BXML file nor this converter.
>
>
> Though you may prefer to use the builder pattern exclusively, others may
> prefer to continue working with BXML. The converter would be a nice way to
> ensure that a BXML source is valid.
>
>
I think some people would prefer to use BXML style, but the point here is
Java API based development should be equally well supported.(without
assuming the use of BXML).
I think Pivot is, in the basic Java oriented approach, more closer to Vaadin
than Silverlight etc. Vaadin explicitly avoid using any form of XML as basic
policy, it emphasizes pure Java based approach. I wonder Pivot developers
have looked at the project..

Also this cases, I wonder why it just can't set the initial index value. The
>> Pivot code may select element after tabs tag is closed if selectedIndex is
>> defined.
>>
>>
>> Not sure what you mean. TabPane has a default value for selectedIndex.
>> However, TabPane doesn't know anything about a closing tag - only
>> BXMLSerializer knows about that.
>>
>
> I have not looked at the current codes for  selectedIndex, but if it
> creates a selectedIndex function and register in a list of post evaluation
> function  associated with the corresponding element, when the tag is closed,
> it can start evaluation these functions.
>
> ...
>
> Essentially it is hard for user to remember which attributes must be set
> after elements declaration,
>
>
> "selectedIndex" simply maps to TabPane#setSelectedIndex(). Obviously, you
> can't call setSelectedIndex() until the tabs have been added. So I don't
> think there should be any confusion on the developer's part.
>
> It would probably help for you to look at the Java APIs themselves rather
> than trying to reverse-engineer them from BXML. I think that may help
> clarify some things for you.
>
> BTW, I believe I understand the issue with the non-struct final classes now
> - since you can't create anonymous inner subclasses of them, it breaks your
> builder pattern. I can see an argument for making those classes non-final -
> however, the struct classes need to stay final for performance reasons (and,
> as I mentioned, aren't really meant to be used in markup anyways).
>
> G
>
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> On Mon, Jan 3, 2011 at 8:38 AM, Greg Brown <gk...@verizon.net> wrote:
>> If the attribute was processed in the opening tag, we'd get an IndexOutOfBoundsException, since the Labels would not have been added yet.
>> 
>> This is the problem I faced. But most of other attribute seems OK to set at the opening tag.
> 
> Correct - many attributes can be set in the opening tag, but any that have dependencies on child elements cannot. Since there is no harm in setting all attributes in the closing tag, that is what we do.
> 
>> If Pivot is used only through BXML, these order are hidden from user, it may not matter.
>> But if it is directly used in Java codes, this makes code hard to read.
> 
> Agreed, but if you are hand-coding using your builder style, you can put the setters wherever you like. If you are using a BXML to Java converter, it doesn't really matter where they go because the generated code isn't really meant to be human-readable (that's what BXML is for).
> 
> This is quite opposite for my purpose. I would want to have human readable Java code. In fact, If we do start using this builder style, we will not need BXML file nor this converter.

Though you may prefer to use the builder pattern exclusively, others may prefer to continue working with BXML. The converter would be a nice way to ensure that a BXML source is valid.

>> Also this cases, I wonder why it just can't set the initial index value. The Pivot code may select element after tabs tag is closed if selectedIndex is defined.
> 
> Not sure what you mean. TabPane has a default value for selectedIndex. However, TabPane doesn't know anything about a closing tag - only BXMLSerializer knows about that.
> 
> I have not looked at the current codes for  selectedIndex, but if it creates a selectedIndex function and register in a list of post evaluation function  associated with the corresponding element, when the tag is closed, it can start evaluation these functions.
...
> Essentially it is hard for user to remember which attributes must be set after elements declaration,

"selectedIndex" simply maps to TabPane#setSelectedIndex(). Obviously, you can't call setSelectedIndex() until the tabs have been added. So I don't think there should be any confusion on the developer's part.

It would probably help for you to look at the Java APIs themselves rather than trying to reverse-engineer them from BXML. I think that may help clarify some things for you.

BTW, I believe I understand the issue with the non-struct final classes now - since you can't create anonymous inner subclasses of them, it breaks your builder pattern. I can see an argument for making those classes non-final - however, the struct classes need to stay final for performance reasons (and, as I mentioned, aren't really meant to be used in markup anyways).

G



Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
On Mon, Jan 3, 2011 at 8:38 AM, Greg Brown <gk...@verizon.net> wrote:

> If the attribute was processed in the opening tag, we'd get an
>> IndexOutOfBoundsException, since the Labels would not have been added yet.
>>
>
> This is the problem I faced. But most of other attribute seems OK to set at
> the opening tag.
>
>
> Correct - many attributes can be set in the opening tag, but any that have
> dependencies on child elements cannot. Since there is no harm in setting all
> attributes in the closing tag, that is what we do.
>
> If Pivot is used only through BXML, these order are hidden from user, it
> may not matter.
> But if it is directly used in Java codes, this makes code hard to read.
>
>
> Agreed, but if you are hand-coding using your builder style, you can put
> the setters wherever you like. If you are using a BXML to Java converter, it
> doesn't really matter where they go because the generated code isn't really
> meant to be human-readable (that's what BXML is for).
>

This is quite opposite for my purpose. I would want to have human readable
Java code. In fact, If we do start using this builder style, we will not
need BXML file nor this converter. This tools is useful for migration or to
understand how to write Java code using existing Pivot sample bxml files.
(Since there are not much such direct Java source codes samples in Pivot
project)

One of my main objective for using Java was to develop generic class library
for basic CRUD feature.
So it is important, these Java code is human readable.
I have already changed the code generation so that it generate attribute
setters at the closing tag. But it is not acceptable for readability point
of view.
 It is equivalent asking to write bxml file with some attribute after
element declaration.




>
> Also this cases, I wonder why it just can't set the initial index value.
> The Pivot code may select element after tabs tag is closed if selectedIndex
> is defined.
>
>
> Not sure what you mean. TabPane has a default value for selectedIndex.
> However, TabPane doesn't know anything about a closing tag - only
> BXMLSerializer knows about that.
>

I have not looked at the current codes for  selectedIndex, but if it creates
a selectedIndex function and register in a list of post evaluation function
 associated with the corresponding element, when the tag is closed, it can
start evaluation these functions. This approach will allow to set
 selectedIndex just after the opening tag.
Essentially it is hard for user to remember which attributes must be set
after elements declaration, and even if it is done so, the code is not easy
to read. So these things should be handled by the Pivot core level.



>
> G
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> If the attribute was processed in the opening tag, we'd get an IndexOutOfBoundsException, since the Labels would not have been added yet.
> 
> This is the problem I faced. But most of other attribute seems OK to set at the opening tag.

Correct - many attributes can be set in the opening tag, but any that have dependencies on child elements cannot. Since there is no harm in setting all attributes in the closing tag, that is what we do.

> If Pivot is used only through BXML, these order are hidden from user, it may not matter.
> But if it is directly used in Java codes, this makes code hard to read.

Agreed, but if you are hand-coding using your builder style, you can put the setters wherever you like. If you are using a BXML to Java converter, it doesn't really matter where they go because the generated code isn't really meant to be human-readable (that's what BXML is for).

> Also this cases, I wonder why it just can't set the initial index value. The Pivot code may select element after tabs tag is closed if selectedIndex is defined.

Not sure what you mean. TabPane has a default value for selectedIndex. However, TabPane doesn't know anything about a closing tag - only BXMLSerializer knows about that.

G


Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
On Mon, Jan 3, 2011 at 5:09 AM, Greg Brown <gk...@verizon.net> wrote:

> > I will report some of the issues I faced later.
> > (e.g, the attribute setting invocation sometimes must be called after all
> elements are added.. but this looks not good API design for Pivot..)
>
> Attributes are always processed in the closing tag. This is so cases such
> as the following are properly handled:
>
> <TabPane selectedIndex="2">
>    <tabs>
>        <Label text="A"/>
>        <Label text="B"/>
>        <Label text="C"/>
>    </tabs>
> </TabPane>
>
> If the attribute was processed in the opening tag, we'd get an
> IndexOutOfBoundsException, since the Labels would not have been added yet.
>

This is the problem I faced. But most of other attribute seems OK to set at
the opening tag.
If Pivot is used only through BXML, these order are hidden from user, it may
not matter.
But if it is directly used in Java codes, this makes code hard to read.
since many case, there are a lot of included elements, and after all these
elements, attributes must be set. these codes are far from the corresponding
 element instantiation code.

Also this cases, I wonder why it just can't set the initial index value. The
Pivot code may select element after tabs tag is closed if selectedIndex is
defined.
In Scala, this may be implemented with lazy select function.




>
> G
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> I will report some of the issues I faced later.
> (e.g, the attribute setting invocation sometimes must be called after all elements are added.. but this looks not good API design for Pivot..)

Attributes are always processed in the closing tag. This is so cases such as the following are properly handled:

<TabPane selectedIndex="2">
    <tabs>
        <Label text="A"/>
        <Label text="B"/>
        <Label text="C"/>
    </tabs>
</TabPane>

If the attribute was processed in the opening tag, we'd get an IndexOutOfBoundsException, since the Labels would not have been added yet.

G


Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
> The current code does not handle listener code in BXML.
> These restriction may be removed if someone who know BXML well.
> But for me, some JS based BXML file translated in Java uisng JS interpreter seems not so appealing situation.
> Why do we want to use JS in Java?

It is sometimes convenient to use JS. Also, it allows us to execute code that is not compiled (for example, in BXML that is generated by a server or an authoring tool). Finally, you are not restricted to JS - you can use any JVM scripting language, such as Groovy or Clojure.

> So I have not tried much for supporting this aspect.

I don't think that will be a problem. If you are converting BXML to Java, you probably don't want to use script anyways. You may however still want to define event/handler mappings in BXML, such that Java methods will be invoked instead of script functions - I have been prototyping a way to make this easier and will be sharing the results soon.

> Also in order to support this style of code generation, some of the final class definition must be changed in Pivot.

These classes are final by design. Making them final allows them to be treated more like "structs" in JVMs that support advanced escape analysis. They are not meant to be instantiated or manipulated in BXML (though you can use them in script).

> and some handling of attribute evaluation order is desirable.

As I mentioned in my previous email, attribute ordering is only relevant if the generated code is meant to be human-readable (which I do not see as a priority).

G


Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
Hi,
The current code does not handle listener code in BXML.
These restriction may be removed if someone who know BXML well.
But for me, some JS based BXML file translated in Java uisng JS interpreter
seems not so appealing situation.
Why do we want to use JS in Java?
So I have not tried much for supporting this aspect.

Also in order to support this style of code generation, some of the final
class definition must be changed in Pivot. and some handling of attribute
evaluation order is desirable.
Followings are the classes using final under wtk. I think some of class
(e.g, sequence) do not have to be none final since they are not used for
this anonymous class style instance creation.

 # grep -R "final class" * | grep java:
src/org/apache/pivot/wtk/text/TextNode.java:public final class TextNode
extends Node {
src/org/apache/pivot/wtk/BrowserApplicationContext.java:public final class
BrowserApplicationContext extends ApplicationContext {
src/org/apache/pivot/wtk/BrowserApplicationContext.java:    public static
final class HostApplet extends Applet {
src/org/apache/pivot/wtk/Accordion.java:    public final class PanelSequence
implements Sequence<Component>, Iterable<Component> {
src/org/apache/pivot/wtk/Display.java:public final class Display extends
Container {
src/org/apache/pivot/wtk/Component.java:    public final class
StyleDictionary implements Dictionary<String, Object>, Iterable<String> {
src/org/apache/pivot/wtk/Component.java:    public final class
UserDataDictionary implements
src/org/apache/pivot/wtk/Component.java:    public final class
DecoratorSequence implements Sequence<Decorator>,
src/org/apache/pivot/wtk/Span.java:public final class Span {
src/org/apache/pivot/wtk/TreeView.java:    public static final class
PathComparator implements Comparator<Path> {
src/org/apache/pivot/wtk/Menu.java:    public final class SectionSequence
implements Sequence<Section>, Iterable<Section> {
src/org/apache/pivot/wtk/DesktopApplicationContext.java://public final class
DesktopApplicationContext extends ApplicationContext {
src/org/apache/pivot/wtk/Point.java:public final class Point implements
Serializable {
src/org/apache/pivot/wtk/TableView.java:    public static final class Column
{
src/org/apache/pivot/wtk/TableView.java:    public final class
ColumnSequence implements Sequence<Column>, Iterable<Column> {
src/org/apache/pivot/wtk/TableView.java:    public final class
SortDictionary implements Dictionary<String, SortDirection>,
Iterable<String> {
src/org/apache/pivot/wtk/Prompt.java:    public final class OptionSequence
implements Sequence<Object>, Iterable<Object> {
src/org/apache/pivot/wtk/Insets.java:public final class Insets implements
Serializable {
src/org/apache/pivot/wtk/ScrollBar.java:    public static final class Scope
{
src/org/apache/pivot/wtk/Dimensions.java:public final class Dimensions
implements Serializable {
src/org/apache/pivot/wtk/Keyboard.java:public final class Keyboard {
src/org/apache/pivot/wtk/Keyboard.java:    public static final class
KeyStroke {
src/org/apache/pivot/wtk/Keyboard.java:    public static final class KeyCode
{
src/org/apache/pivot/wtk/MenuBar.java:    public final class ItemSequence
implements Sequence<Item>, Iterable<Item> {
src/org/apache/pivot/wtk/CornerRadii.java:public final class CornerRadii
implements Serializable {
src/org/apache/pivot/wtk/TabPane.java:    public final class TabSequence
implements Sequence<Component>, Iterable<Component> {
src/org/apache/pivot/wtk/GraphicsUtilities.java:public final class
GraphicsUtilities {
src/org/apache/pivot/wtk/TextArea.java:    public static final class
Paragraph {
src/org/apache/pivot/wtk/TextArea.java:    public final class
ParagraphSequence implements Sequence<Paragraph>, Iterable<Paragraph> {
src/org/apache/pivot/wtk/TablePane.java:    public final class RowSequence
implements Sequence<Row>, Iterable<Row> {
src/org/apache/pivot/wtk/TablePane.java:    public final class
ColumnSequence implements Sequence<Column>, Iterable<Column> {
src/org/apache/pivot/wtk/TablePane.java:    public static final class Filler
extends Component {
src/org/apache/pivot/wtk/Clipboard.java:public final class Clipboard {
src/org/apache/pivot/wtk/Automation.java:public final class Automation {
src/org/apache/pivot/wtk/skin/GridPaneSkin.java:    protected final class
Metadata {
src/org/apache/pivot/wtk/skin/ColorChooserButtonSkin.java:    public final
class ColorChooserPopup extends Window {
src/org/apache/pivot/wtk/skin/ColorChooserButtonSkin.java:    public final
class ColorChooserPopupSkin extends WindowSkin {
src/org/apache/pivot/wtk/Action.java:    public static final class
NamedActionDictionary
src/org/apache/pivot/wtk/Mouse.java:public final class Mouse {
src/org/apache/pivot/wtk/content/TableViewMultiCellRenderer.java:    public
static final class RendererMapping {
src/org/apache/pivot/wtk/Limits.java:public final class Limits implements
Serializable {
src/org/apache/pivot/wtk/Form.java:    public final class SectionSequence
implements Sequence<Section>, Iterable<Section> {
src/org/apache/pivot/wtk/ApplicationContext.java:    public static final
class ResourceCacheDictionary
src/org/apache/pivot/wtk/ApplicationContext.java:    public static final
class ScheduledCallback extends TimerTask {
src/org/apache/pivot/wtk/Alert.java:    public final class OptionSequence
implements Sequence<Object>, Iterable<Object> {
src/org/apache/pivot/wtk/Bounds.java:public final class Bounds implements
Serializable {
src/org/apache/pivot/wtk/GridPane.java:    public static final class Row
implements Sequence<Component>, Iterable<Component> {
src/org/apache/pivot/wtk/GridPane.java:    public final class RowSequence
implements Sequence<Row>, Iterable<Row> {

----------------
I have already changed following classes to none final so that the generated
Java codes for tutorial bxml files can be compiled.

src/org/apache/pivot/wtk/DesktopApplicationContext.java://public final class
DesktopApplicationContext extends ApplicationContext {
src/org/apache/pivot/wtk/TableView.java://    public static final class
Column {
src/org/apache/pivot/wtk/TablePane.java://    public static final class
Filler extends Component {
src/org/apache/pivot/wtk/GridPane.java://    public static final class Row
implements Sequence<Component>, Iterable<Component> {


On Mon, Jan 3, 2011 at 5:38 AM, Sandro Martini <sa...@gmail.com>wrote:

>
> Hi Calatus,
>
> > I fixed a bug(add=>setContent for embedded node), and made a few
> > improvements, now the sample StockTracker is now working. I updated the
> > github site including the READEME file with the new generated Java code:
> Very good, I'll try to take a look as soon as possible :-) ...
>
> I hope for the 2.1 we will be able to merge the required enhancements to
> Pivot with Todd prototype of BXMLCompiler ... so your sample could be
> simplified a lot.
>
> Bye,
> Sandro
>
>
> --
> View this message in context:
> http://apache-pivot-users.399431.n3.nabble.com/pivot-are-there-any-tools-to-convert-bxml-to-Java-tp2118284p2184776.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>



-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Sandro Martini <sa...@gmail.com>.
Hi Calatus,

> I fixed a bug(add=>setContent for embedded node), and made a few
> improvements, now the sample StockTracker is now working. I updated the
> github site including the READEME file with the new generated Java code:
Very good, I'll try to take a look as soon as possible :-) ...

I hope for the 2.1 we will be able to merge the required enhancements to
Pivot with Todd prototype of BXMLCompiler ... so your sample could be
simplified a lot.

Bye,
Sandro


-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/pivot-are-there-any-tools-to-convert-bxml-to-Java-tp2118284p2184776.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
Sandro,

I fixed a bug(add=>setContent for embedded node), and made a few
improvements, now the sample StockTracker is now working.
I updated the github site including the READEME file with the new generated
Java code:

https://github.com/calathus/bxml2Java

Although there are a few more issues, this would be a good starting point.

I will report some of the issues I faced later.
(e.g, the attribute setting invocation sometimes must be called after all
elements are added.. but this looks not good API design for Pivot..)


On Thu, Dec 30, 2010 at 1:32 AM, Sandro Martini <sa...@gmail.com>wrote:

>
> Hi,
> thanks for the new link, but as you I'm too much busy at the moment (and I
> have not so much knowledge on BXML internals at the moment) ... if you do
> not hurry I can try to take a look in next weeks, and tell you.
>
> Greg (and others) what do you think on see what should be changed in
> BXMLSerializer (for the 2.1 release) to enable a subclass of it to do the
> code generation stuff ?
> I can add a jira ticket and put some info there so we can keep track of
> this
> ... tell me.
>
> Bye,
> Sandro
>
> --
> View this message in context:
> http://apache-pivot-users.399431.n3.nabble.com/pivot-are-there-any-tools-to-convert-bxml-to-Java-tp2118284p2166783.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>



-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Sandro Martini <sa...@gmail.com>.
Hi, 
thanks for the new link, but as you I'm too much busy at the moment (and I
have not so much knowledge on BXML internals at the moment) ... if you do
not hurry I can try to take a look in next weeks, and tell you.

Greg (and others) what do you think on see what should be changed in
BXMLSerializer (for the 2.1 release) to enable a subclass of it to do the
code generation stuff ? 
I can add a jira ticket and put some info there so we can keep track of this
... tell me.

Bye,
Sandro

-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/pivot-are-there-any-tools-to-convert-bxml-to-Java-tp2118284p2166783.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
Sandro,

I committed the new version of bxml2java converter in github.

https://github.com/calathus/bxml2Java

Although it has still problems, I think they can be fixed by someone else.
Since I'm going to busy this week, if someone (you?) complete this tool, it
would be nice.

if you have any question for using it, let me know.


On Mon, Dec 27, 2010 at 8:20 AM, Sandro Martini <sa...@gmail.com>wrote:

>
> Hi all,
>
> @calathus:
> great work !!
> Are you interested in sharing with us even the first code you produced
> (maybe adding it in a jira ticket) ?
>
> @all (developers and not only):
> what do you think on have the BXML to Java feature inside a (re-enabled)
> developer-only Tools subproject (or something similar), for the 2.1 release
> ?
>
> Bye,
> Sandro
>
> --
> View this message in context:
> http://apache-pivot-users.399431.n3.nabble.com/pivot-are-there-any-tools-to-convert-bxml-to-Java-tp2118284p2152270.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>



-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Sandro Martini <sa...@gmail.com>.
Hi all,

@calathus: 
great work !! 
Are you interested in sharing with us even the first code you produced
(maybe adding it in a jira ticket) ?

@all (developers and not only):
what do you think on have the BXML to Java feature inside a (re-enabled)
developer-only Tools subproject (or something similar), for the 2.1 release
?

Bye,
Sandro

-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/pivot-are-there-any-tools-to-convert-bxml-to-Java-tp2118284p2152270.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
Great approach! Is that representative of what your BXML->Java compiler generates? I really like how it uses anonymous inner classes as the "builder" mechanism.

On Dec 27, 2010, at 7:41 AM, calathus wrote:

> Greg,
> I considered implementing Pivot builder in Scala following scala-squib, but I found a few issues for this type of approach.
> Basically, it will depend on more runtime binding, so it will reduce the advantage of statically typed language.
> After I implemented bxml to Java converter, it became clear that the translation can be done more directly reflecting the original BXML structure, also without using variable in translated Java codes.
> 
> For example,  detail_pane.bxml can be translated in Java as following. This style may be used instead of BXML.
> Do you have any opinion for this approach?
> 
>     public static Object getComponent() {
>         try {
>             return new BoxPane() {{
>                 setOrientation(Orientation.VERTICAL);
>                 setStyles("{fill:true}");
>                 add(new Label() {{
>                     setTextKey("companyName");
>                     setStyles("{font:{size:12, bold:true}}");
>                 }});
>                 add(new Separator() {{
>                 }});
>                 add(new Form() {{
>                     setStyles("{padding:0, fill:true, showFlagIcons:false, showFlagHighlight:false,         leftAlignLabels:true}");
>                     getSections().add(new Form.Section() {{
>                         final ValueMapping valueMapping_5 = new ValueMapping();
>                         final ChangeMapping changeMapping_6 = new ChangeMapping();
>                         final VolumeMapping volumeMapping_7 = new VolumeMapping();
>                         add(new Label() {{
>                             setTextKey("value");
>                             setTextBindMapping(valueMapping_5);
>                             setStyles("{horizontalAlignment:'right'}");
>                             Form.setLabel(this, "value");
>                         }});
>                         add(new Label() {{
>                             setTextKey("change");
>                             setTextBindMapping(changeMapping_6);
>                             setStyles("{horizontalAlignment:'right'}");
>                             Form.setLabel(this, "change");
>                         }});
>                         add(new Label() {{
>                             setTextKey("openingValue");
>                             setTextBindMapping(valueMapping_5);
>                             setStyles("{horizontalAlignment:'right'}");
>                             Form.setLabel(this, "openingValue");
>                         }});
>                         add(new Label() {{
>                             setTextKey("highValue");
>                             setTextBindMapping(valueMapping_5);
>                             setStyles("{horizontalAlignment:'right'}");
>                             Form.setLabel(this, "highValue");
>                         }});
>                         add(new Label() {{
>                             setTextKey("lowValue");
>                             setTextBindMapping(valueMapping_5);
>                             setStyles("{horizontalAlignment:'right'}");
>                             Form.setLabel(this, "lowValue");
>                         }});
>                         add(new Label() {{
>                             setTextKey("volume");
>                             setTextBindMapping(volumeMapping_7);
>                             setStyles("{horizontalAlignment:'right'}");
>                             Form.setLabel(this, "volume");
>                         }});
>                     }});
>                 }});
>             }};
>         } catch (Exception e) {
>             e.printStackTrace();
>             throw new RuntimeException(e);
>         }
>     }
> 
> -----
> detail_pane.bxml
> 
> <BoxPane orientation="vertical" styles="{fill:true}"
>     xmlns:bxml="http://pivot.apache.org/bxml"
>     xmlns:stocktracker="org.apache.pivot.tutorials.stocktracker"
>     xmlns="org.apache.pivot.wtk">
>     <Label textKey="companyName" styles="{font:{size:12, bold:true}}"/>
> 
>     <Separator/>
> 
>     <Form styles="{padding:0, fill:true, showFlagIcons:false, showFlagHighlight:false,
>         leftAlignLabels:true}">
>         <Form.Section>
>             <bxml:define>
>                 <stocktracker:ValueMapping bxml:id="valueMapping"/>
>                 <stocktracker:ChangeMapping bxml:id="changeMapping"/>
>                 <stocktracker:VolumeMapping bxml:id="volumeMapping"/>
>             </bxml:define>
> 
>             <Label bxml:id="valueLabel" Form.label="%value"
>                 textKey="value" textBindMapping="$valueMapping"
>                 styles="{horizontalAlignment:'right'}"/>
>             <Label bxml:id="changeLabel" Form.label="%change"
>                 textKey="change" textBindMapping="$changeMapping"
>                 styles="{horizontalAlignment:'right'}"/>
>             <Label bxml:id="openingValueLabel" Form.label="%openingValue"
>                 textKey="openingValue" textBindMapping="$valueMapping"
>                 styles="{horizontalAlignment:'right'}"/>
>             <Label bxml:id="highValueLabel" Form.label="%highValue"
>                 textKey="highValue" textBindMapping="$valueMapping"
>                 styles="{horizontalAlignment:'right'}"/>
>             <Label bxml:id="lowValueLabel" Form.label="%lowValue"
>                 textKey="lowValue" textBindMapping="$valueMapping"
>                 styles="{horizontalAlignment:'right'}"/>
>             <Label bxml:id="volumeLabel" Form.label="%volume"
>                 textKey="volume" textBindMapping="$volumeMapping"
>                 styles="{horizontalAlignment:'right'}"/>
>         </Form.Section>
>     </Form>
> </BoxPane>
> 
> On Tue, Dec 21, 2010 at 11:06 AM, calathus <ca...@gmail.com> wrote:
> Greg,
> There were a few questions, and I did not have investigated these lines much, so I searched the similar projects.
> 
> For the CRUD stuff, I will answer later. 
> 
> For the Scala Pivot builder approach, as you and Clint suggested, I was thinking something similar o Gvoovy's SwingBuilder approach.
> Right now, Scala 2.8.1's scala.swing library is not taking this type of builder approach. So I looked for some other library.
> I found squib project:
> http://code.google.com/p/scala-squib/
> 
> 
> Unfortunately, Scala is still evolving language, this squid project could not be compiled in the latest 2.8.1, but with a few code changes, I could resolved these errors. (but somehow how, running demo did not work with ant)
> 
> So If we change Swing API to Pivot API, we will be able to have similar builder.
> Here is a sample code from the squib project:
> 
> import java.awt.GridBagConstraints._
> import java.beans.{PropertyChangeListener, PropertyChangeEvent}
> import java.lang.reflect.Method
> import javax.swing._
> import javax.swing.event._
> 
> import scala.reflect.BeanProperty
> 
> import net.miginfocom.swing.MigLayout
> 
> package tfd.scala.squib.demo {
> 
> import tfd.scala.squib._
> import tfd.scala.squib.event._
> 
>  object RGBSliders extends Application {
>     class RGBCanvasComponent extends JComponent {
>         private var red:Int = 0
>         private var green:Int = 0
>         private var blue:Int = 0
>         
>         def setRed(value:Int) = {
>             if (value != red) {
>                 red = value
>                 repaint()
>             }
>         }
>         
>         def setGreen(value:Int) = {
>             if (value != green) {
>                 green = value
>                 repaint()
>             }
>         }
>         
>         def setBlue(value:Int) = {
>             if (value != blue) {
>                 blue = value
>                 repaint()
>             }
>         }
>            
>         override def paint(g: Graphics):Unit = {
>             g.setColor(new Color(red, green, blue))
>             val d = getSize()
>             g.fillRect(0,0, d.width, d.height)
>         }
>     }
>     
>     object rgbcanvas extends BuiltComponent[RGBCanvasComponent] {
>         def newComponent = new RGBCanvasComponent()
>     }
>     
>     lazy val rgb = rgbcanvas.id("rgbcanvas")
>     
>     frame(
>             'title->"RGB Selector",
>             'visible -> true,
>             'defaultCloseOperation -> JFrame.EXIT_ON_CLOSE,
>             'layout -> new MigLayout("fill, wrap 3", "align right, grow", "align top, grow"),
>             contents(
>                  label("Red:"),
>                  slider("red", 'maximum -> 255, 'minimum-> 0, 'value->0, sliderValueChanged(&rgb.setRed)),
>                  rgbcanvas("rgbcanvas",
>                                'preferredSize -> new Dimension(100,100),
>                                'red -> 0,
>                                'green -> 0,
>                                'blue -> 0
>                  ) -> "spany 3",
>                  label("Green:"),
>                  slider("green", 'maximum -> 255, 'minimum-> 0, 'value->0, sliderValueChanged(&rgb.setGreen)),
>                  label("Blue:"),
>                  slider("blue", 'maximum -> 255, 'minimum-> 0, 'value->0, sliderValueChanged(&rgb.setBlue))                
>             )
>     ).pack
>  }
> }
> 
> 
> On Mon, Dec 20, 2010 at 6:04 AM, Greg Brown <gk...@verizon.net> wrote:
> As Chris mentioned, Pivot does not currently provide a BXML to Java compiler. We actually prototyped one a while back, but it was never completed due to other priorities.
> 
> Generating byte code from BXML might be tough, but converting it to a Java source file would probably be pretty easy. Let me know if you are interested in trying to write something like this - I would be happy to try to help when I can.
> 
> G
> 
> On Dec 19, 2010, at 10:26 PM, calathus wrote:
> 
> > Hi,
> > I'm looking for a tool to convert bxml file to equivalent Java source program.
> > Are there such tools?
> >
> > I just started using pivot, but many of sample is based on bxml.
> > I think in order to develop a UI library with Java generic class, XML file based approach is not appropriate.
> >
> > And xml based approach will reduce static error detection capability.
> > I liked to see  more examples using  Java classes to define GUI without relying on bxml files.
> >
> > --
> > Cheers,
> > calathus
> >
> >
> >
> 
> 
> 
> 
> -- 
> Cheers,
> calathus
> 
> 
> 
> 
> 
> 
> -- 
> Cheers,
> calathus
> 
> 
> 


Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
Greg,
I considered implementing Pivot builder in Scala following scala-squib, but
I found a few issues for this type of approach.
Basically, it will depend on more runtime binding, so it will reduce the
advantage of statically typed language.
After I implemented bxml to Java converter, it became clear that the
translation can be done more directly reflecting the original BXML
structure, also without using variable in translated Java codes.

For example,  detail_pane.bxml can be translated in Java as following. This
style may be used instead of BXML.
Do you have any opinion for this approach?

    public static Object getComponent() {
        try {
            return new BoxPane() {{
                setOrientation(Orientation.VERTICAL);
                setStyles("{fill:true}");
                add(new Label() {{
                    setTextKey("companyName");
                    setStyles("{font:{size:12, bold:true}}");
                }});
                add(new Separator() {{
                }});
                add(new Form() {{
                    setStyles("{padding:0, fill:true, showFlagIcons:false,
showFlagHighlight:false,         leftAlignLabels:true}");
                    getSections().add(new Form.Section() {{
                        final ValueMapping valueMapping_5 = new
ValueMapping();
                        final ChangeMapping changeMapping_6 = new
ChangeMapping();
                        final VolumeMapping volumeMapping_7 = new
VolumeMapping();
                        add(new Label() {{
                            setTextKey("value");
                            setTextBindMapping(valueMapping_5);
                            setStyles("{horizontalAlignment:'right'}");
                            Form.setLabel(this, "value");
                        }});
                        add(new Label() {{
                            setTextKey("change");
                            setTextBindMapping(changeMapping_6);
                            setStyles("{horizontalAlignment:'right'}");
                            Form.setLabel(this, "change");
                        }});
                        add(new Label() {{
                            setTextKey("openingValue");
                            setTextBindMapping(valueMapping_5);
                            setStyles("{horizontalAlignment:'right'}");
                            Form.setLabel(this, "openingValue");
                        }});
                        add(new Label() {{
                            setTextKey("highValue");
                            setTextBindMapping(valueMapping_5);
                            setStyles("{horizontalAlignment:'right'}");
                            Form.setLabel(this, "highValue");
                        }});
                        add(new Label() {{
                            setTextKey("lowValue");
                            setTextBindMapping(valueMapping_5);
                            setStyles("{horizontalAlignment:'right'}");
                            Form.setLabel(this, "lowValue");
                        }});
                        add(new Label() {{
                            setTextKey("volume");
                            setTextBindMapping(volumeMapping_7);
                            setStyles("{horizontalAlignment:'right'}");
                            Form.setLabel(this, "volume");
                        }});
                    }});
                }});
            }};
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

-----
detail_pane.bxml

<BoxPane orientation="vertical" styles="{fill:true}"
    xmlns:bxml="http://pivot.apache.org/bxml"
    xmlns:stocktracker="org.apache.pivot.tutorials.stocktracker"
    xmlns="org.apache.pivot.wtk">
    <Label textKey="companyName" styles="{font:{size:12, bold:true}}"/>

    <Separator/>

    <Form styles="{padding:0, fill:true, showFlagIcons:false,
showFlagHighlight:false,
        leftAlignLabels:true}">
        <Form.Section>
            <bxml:define>
                <stocktracker:ValueMapping bxml:id="valueMapping"/>
                <stocktracker:ChangeMapping bxml:id="changeMapping"/>
                <stocktracker:VolumeMapping bxml:id="volumeMapping"/>
            </bxml:define>

            <Label bxml:id="valueLabel" Form.label="%value"
                textKey="value" textBindMapping="$valueMapping"
                styles="{horizontalAlignment:'right'}"/>
            <Label bxml:id="changeLabel" Form.label="%change"
                textKey="change" textBindMapping="$changeMapping"
                styles="{horizontalAlignment:'right'}"/>
            <Label bxml:id="openingValueLabel" Form.label="%openingValue"
                textKey="openingValue" textBindMapping="$valueMapping"
                styles="{horizontalAlignment:'right'}"/>
            <Label bxml:id="highValueLabel" Form.label="%highValue"
                textKey="highValue" textBindMapping="$valueMapping"
                styles="{horizontalAlignment:'right'}"/>
            <Label bxml:id="lowValueLabel" Form.label="%lowValue"
                textKey="lowValue" textBindMapping="$valueMapping"
                styles="{horizontalAlignment:'right'}"/>
            <Label bxml:id="volumeLabel" Form.label="%volume"
                textKey="volume" textBindMapping="$volumeMapping"
                styles="{horizontalAlignment:'right'}"/>
        </Form.Section>
    </Form>
</BoxPane>

On Tue, Dec 21, 2010 at 11:06 AM, calathus <ca...@gmail.com> wrote:

> Greg,
> There were a few questions, and I did not have investigated these lines
> much, so I searched the similar projects.
>
> For the CRUD stuff, I will answer later.
>
> For the Scala Pivot builder approach, as you and Clint suggested, I was
> thinking something similar o Gvoovy's SwingBuilder approach.
> Right now, Scala 2.8.1's scala.swing library is not taking this type of
> builder approach. So I looked for some other library.
> I found squib project:
> http://code.google.com/p/scala-squib/
>
>
> Unfortunately, Scala is still evolving language, this squid project could
> not be compiled in the latest 2.8.1, but with a few code changes, I could
> resolved these errors. (but somehow how, running demo did not work with ant)
>
> So If we change Swing API to Pivot API, we will be able to have similar
> builder.
> Here is a sample code from the squib project:
>
> import java.awt.GridBagConstraints._
> import java.beans.{PropertyChangeListener, PropertyChangeEvent}
> import java.lang.reflect.Method
> import javax.swing._
> import javax.swing.event._
>
> import scala.reflect.BeanProperty
>
> import net.miginfocom.swing.MigLayout
>
> package tfd.scala.squib.demo {
>
> import tfd.scala.squib._
> import tfd.scala.squib.event._
>
>  object RGBSliders extends Application {
>     class RGBCanvasComponent extends JComponent {
>         private var red:Int = 0
>         private var green:Int = 0
>         private var blue:Int = 0
>
>         def setRed(value:Int) = {
>             if (value != red) {
>                 red = value
>                 repaint()
>             }
>         }
>
>         def setGreen(value:Int) = {
>             if (value != green) {
>                 green = value
>                 repaint()
>             }
>         }
>
>         def setBlue(value:Int) = {
>             if (value != blue) {
>                 blue = value
>                 repaint()
>             }
>         }
>
>         override def paint(g: Graphics):Unit = {
>             g.setColor(new Color(red, green, blue))
>             val d = getSize()
>             g.fillRect(0,0, d.width, d.height)
>         }
>     }
>
>     object rgbcanvas extends BuiltComponent[RGBCanvasComponent] {
>         def newComponent = new RGBCanvasComponent()
>     }
>
>     lazy val rgb = rgbcanvas.id("rgbcanvas")
>
>     frame(
>             'title->"RGB Selector",
>             'visible -> true,
>             'defaultCloseOperation -> JFrame.EXIT_ON_CLOSE,
>             'layout -> new MigLayout("fill, wrap 3", "align right, grow",
> "align top, grow"),
>             contents(
>                  label("Red:"),
>                  slider("red", 'maximum -> 255, 'minimum-> 0, 'value->0,
> sliderValueChanged(&rgb.setRed)),
>                  rgbcanvas("rgbcanvas",
>                                'preferredSize -> new Dimension(100,100),
>                                'red -> 0,
>                                'green -> 0,
>                                'blue -> 0
>                  ) -> "spany 3",
>                  label("Green:"),
>                  slider("green", 'maximum -> 255, 'minimum-> 0, 'value->0,
> sliderValueChanged(&rgb.setGreen)),
>                  label("Blue:"),
>                  slider("blue", 'maximum -> 255, 'minimum-> 0, 'value->0,
> sliderValueChanged(&rgb.setBlue))
>             )
>     ).pack
>  }
> }
>
>
> On Mon, Dec 20, 2010 at 6:04 AM, Greg Brown <gk...@verizon.net> wrote:
>
>> As Chris mentioned, Pivot does not currently provide a BXML to Java
>> compiler. We actually prototyped one a while back, but it was never
>> completed due to other priorities.
>>
>> Generating byte code from BXML might be tough, but converting it to a Java
>> source file would probably be pretty easy. Let me know if you are interested
>> in trying to write something like this - I would be happy to try to help
>> when I can.
>>
>> G
>>
>> On Dec 19, 2010, at 10:26 PM, calathus wrote:
>>
>> > Hi,
>> > I'm looking for a tool to convert bxml file to equivalent Java source
>> program.
>> > Are there such tools?
>> >
>> > I just started using pivot, but many of sample is based on bxml.
>> > I think in order to develop a UI library with Java generic class, XML
>> file based approach is not appropriate.
>> >
>> > And xml based approach will reduce static error detection capability.
>> > I liked to see  more examples using  Java classes to define GUI without
>> relying on bxml files.
>> >
>> > --
>> > Cheers,
>> > calathus
>> >
>> >
>> >
>>
>>
>
>
> --
> Cheers,
> calathus
>
>
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by calathus <ca...@gmail.com>.
Greg,
There were a few questions, and I did not have investigated these lines
much, so I searched the similar projects.

For the CRUD stuff, I will answer later.

For the Scala Pivot builder approach, as you and Clint suggested, I was
thinking something similar o Gvoovy's SwingBuilder approach.
Right now, Scala 2.8.1's scala.swing library is not taking this type of
builder approach. So I looked for some other library.
I found squib project:
http://code.google.com/p/scala-squib/


Unfortunately, Scala is still evolving language, this squid project could
not be compiled in the latest 2.8.1, but with a few code changes, I could
resolved these errors. (but somehow how, running demo did not work with ant)

So If we change Swing API to Pivot API, we will be able to have similar
builder.
Here is a sample code from the squib project:

import java.awt.GridBagConstraints._
import java.beans.{PropertyChangeListener, PropertyChangeEvent}
import java.lang.reflect.Method
import javax.swing._
import javax.swing.event._

import scala.reflect.BeanProperty

import net.miginfocom.swing.MigLayout

package tfd.scala.squib.demo {

import tfd.scala.squib._
import tfd.scala.squib.event._

 object RGBSliders extends Application {
    class RGBCanvasComponent extends JComponent {
        private var red:Int = 0
        private var green:Int = 0
        private var blue:Int = 0

        def setRed(value:Int) = {
            if (value != red) {
                red = value
                repaint()
            }
        }

        def setGreen(value:Int) = {
            if (value != green) {
                green = value
                repaint()
            }
        }

        def setBlue(value:Int) = {
            if (value != blue) {
                blue = value
                repaint()
            }
        }

        override def paint(g: Graphics):Unit = {
            g.setColor(new Color(red, green, blue))
            val d = getSize()
            g.fillRect(0,0, d.width, d.height)
        }
    }

    object rgbcanvas extends BuiltComponent[RGBCanvasComponent] {
        def newComponent = new RGBCanvasComponent()
    }

    lazy val rgb = rgbcanvas.id("rgbcanvas")

    frame(
            'title->"RGB Selector",
            'visible -> true,
            'defaultCloseOperation -> JFrame.EXIT_ON_CLOSE,
            'layout -> new MigLayout("fill, wrap 3", "align right, grow",
"align top, grow"),
            contents(
                 label("Red:"),
                 slider("red", 'maximum -> 255, 'minimum-> 0, 'value->0,
sliderValueChanged(&rgb.setRed)),
                 rgbcanvas("rgbcanvas",
                               'preferredSize -> new Dimension(100,100),
                               'red -> 0,
                               'green -> 0,
                               'blue -> 0
                 ) -> "spany 3",
                 label("Green:"),
                 slider("green", 'maximum -> 255, 'minimum-> 0, 'value->0,
sliderValueChanged(&rgb.setGreen)),
                 label("Blue:"),
                 slider("blue", 'maximum -> 255, 'minimum-> 0, 'value->0,
sliderValueChanged(&rgb.setBlue))
            )
    ).pack
 }
}


On Mon, Dec 20, 2010 at 6:04 AM, Greg Brown <gk...@verizon.net> wrote:

> As Chris mentioned, Pivot does not currently provide a BXML to Java
> compiler. We actually prototyped one a while back, but it was never
> completed due to other priorities.
>
> Generating byte code from BXML might be tough, but converting it to a Java
> source file would probably be pretty easy. Let me know if you are interested
> in trying to write something like this - I would be happy to try to help
> when I can.
>
> G
>
> On Dec 19, 2010, at 10:26 PM, calathus wrote:
>
> > Hi,
> > I'm looking for a tool to convert bxml file to equivalent Java source
> program.
> > Are there such tools?
> >
> > I just started using pivot, but many of sample is based on bxml.
> > I think in order to develop a UI library with Java generic class, XML
> file based approach is not appropriate.
> >
> > And xml based approach will reduce static error detection capability.
> > I liked to see  more examples using  Java classes to define GUI without
> relying on bxml files.
> >
> > --
> > Cheers,
> > calathus
> >
> >
> >
>
>


-- 
Cheers,
calathus

Re: [pivot] are there any tools to convert bxml to Java?

Posted by Greg Brown <gk...@verizon.net>.
As Chris mentioned, Pivot does not currently provide a BXML to Java compiler. We actually prototyped one a while back, but it was never completed due to other priorities. 

Generating byte code from BXML might be tough, but converting it to a Java source file would probably be pretty easy. Let me know if you are interested in trying to write something like this - I would be happy to try to help when I can.

G

On Dec 19, 2010, at 10:26 PM, calathus wrote:

> Hi,
> I'm looking for a tool to convert bxml file to equivalent Java source program.
> Are there such tools?
> 
> I just started using pivot, but many of sample is based on bxml.
> I think in order to develop a UI library with Java generic class, XML file based approach is not appropriate.
> 
> And xml based approach will reduce static error detection capability. 
> I liked to see  more examples using  Java classes to define GUI without relying on bxml files.
> 
> -- 
> Cheers,
> calathus
> 
> 
>