pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From calathus <calat...@gmail.com>
Subject Re: [pivot] are there any tools to convert bxml to Java?
Date Mon, 03 Jan 2011 21:54:34 GMT
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_brown@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

Mime
View raw message