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 <[email protected]> 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