Skip to main content

JSR295 v.0.5 and JXTreeTable

110 replies [Last post]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Shai Almog

> It is a little akward to do something like this: t.childNodes.get(0).address1.

Why would you need to do that?
I'm looking at your current code and it runs perfectly fine with the
patch I sent without changing your data model.

--
Shai Almog
vPrise
http://www.vprise.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

mveksler
Offline
Joined: 2007-01-26
Points: 0

This is your patch:

tree.setTreeTableModel(new TreeTableAdapterModel(t,
new PropertyContext[] {t.childrenNodes.getContext()},
new
PropertyContext[]{t.childrenNodes.get(0).address1.getContext()},
// this is the line of consern
null) {
public boolean isCellEditable(Object node, int column) {
try {
return super.isCellEditable(node, column);
} catch(BeanBindException err) {
return false;
}
}

public Object getValueAt(Object node, int column) {
try {
return super.getValueAt(node, column);
} catch(BeanBindException err) {
return null;
}
}
});

PropertyContext[]{t.childrenNodes.get(0).address1.getContext()},
// this is the line of consern where I would have expected address1 to be exposed by t and not by t.childrenNodes.get(0).address1.
So what I would expect is t.address1.getContext(). Where address1 in t would be exposed as indexedobservable so that it maps to the appropriate index in the childeNodes. What do you think?

Shai Almog

;-)
I was wondering where we missed each other.
This is a copy and paste of your code:
SwingXBind.get().bindContent(t,
new PropertyContext[] {t.childrenNodes.getContext()},
new
PropertyContext[]{t.childrenNodes.get(0).address1.getContext()},
//this is where my question stands. The the PersonBean does not have a
way to expose children properties so that I can bind them to the
columns.
tree);

The address1 is your argument to the bind content, so all you need to
do is create your own bindContent method that can be as generic as you
want. I gave you an example with your specific arguments.

--
Shai Almog
vPrise
http://www.vprise.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

mveksler
Offline
Joined: 2007-01-26
Points: 0

I am confused now ;-)

Where is the example that shows how to create custom bindContent?

Are you refering to the one where instead of using SwingX.bind you set tree table model using tree table model adapter?

Shai Almog

> Where is the example that shows how to create custom bindContent?

I'll try to release a new version tomorrow so if you can't figure this
out then just wait ;-)

This is your current code:
SwingXBind.get ().bindContent(t,
new PropertyContext[] {t.childrenNodes.getContext()},
new
PropertyContext[]{t.childrenNodes.get(0).address1.getContext()},
tree);

This exact code can be written like this:
tree.setTreeTableModel(new TreeTableAdapterModel(t,
new PropertyContext[] {t.childrenNodes.getContext()},
new PropertyContext[]{t.childrenNodes.get
(0).address1.getContext()},
null));

In order to workaround the problem you can just derive
TreeTableAdapterModel and catch the exceptions (and return null) like
this:
tree.setTreeTableModel(new TreeTableAdapterModel(t,
new PropertyContext[] {t.childrenNodes.getContext()},
new PropertyContext[]{t.childrenNodes.get
(0).address1.getContext()},
null) {
public boolean isCellEditable(Object node, int column) {
try {
return super.isCellEditable(node, column);
} catch(BeanBindException err) {
return false;
}
}

public Object getValueAt(Object node, int column) {
try {
return super.getValueAt(node, column);
} catch(BeanBindException err) {
return null;
}
}
});

--
Shai Almog
vPrise
http://www.vprise.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

mveksler
Offline
Joined: 2007-01-26
Points: 0

I got it. You simply catch the exception as a workaround the problem.
The disconet happane whene I was throwing some ideas about having parent bean expose childrens properties in a way of indexed observable like this: root.address1 and I want your openion on that. However, you where still clerifying the workaround to me ;-)
Did not mean to confuse you ;-)

Shai Almog

> Did not mean to confuse you ;-)

I am confused ;-)
Can you create something that you think "should" work, or ideally just
give me lines to replace in your code so I can understand it as part
of the whole picture?

--
Shai Almog
vPrise
http://www.vprise.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

Shai Almog

FYI a new code drop is available in the folder.

--
Shai Almog
vPrise
http://www.vprise.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

mveksler
Offline
Joined: 2007-01-26
Points: 0

I tried the new drop and I still get the same exception.
Did you include some type of fix in the new drop?

Shai Almog

Can you post the stack trace? There shouldn't be an exception anymore.

--
Shai Almog
vPrise
http://www.vprise.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

mveksler
Offline
Joined: 2007-01-26
Points: 0

Here it is:

Exception in thread "AWT-EventQueue-0" net.java.dev.properties.container.BeanBindException: Trying to access a property of a bean on an instance of a bean of a different type field: address1 on bean of: PatientBean
at net.java.dev.properties.container.PropertyContext.getValue(PropertyContext.java:185)
at net.java.dev.properties.container.PropertyContext.getInternalValue(PropertyContext.java:168)
at net.java.dev.properties.binding.swingx.adapters.TreeTableAdapterModel.getValueAt(TreeTableAdapterModel.java:379)
at org.jdesktop.swingx.JXTreeTable$TreeTableModelAdapter.getValueAt(JXTreeTable.java:1770)
at org.jdesktop.swingx.JXTable.getValueAt(JXTable.java:1290)
at org.jdesktop.swingx.table.ColumnFactory.packColumn(ColumnFactory.java:275)
at org.jdesktop.swingx.JXTable.packColumn(JXTable.java:2390)
at org.jdesktop.swingx.JXTable.packTable(JXTable.java:2360)
at org.jdesktop.swingx.JXTable.packAll(JXTable.java:964)
at MixedBeanProperties.createUI(MixedBeanProperties.java:34)
at MixedBeanProperties$1.run(MixedBeanProperties.java:15)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Process finished with exit code 0

mveksler
Offline
Joined: 2007-01-26
Points: 0

I think I used wrong jar files.
I have compared the dates and the jar I have has the wrong date.

mveksler
Offline
Joined: 2007-01-26
Points: 0

You are right.
No more exception.

Shai Almog

Good to hear, I was starting to wonder about my drop package build ;-)

--
Shai Almog
vPrise
http://www.vprise.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

mveksler
Offline
Joined: 2007-01-26
Points: 0

Something is not working right.
I have create simple tree structure like this:

RootBean that containes indexed property of PersonBean which containes indexed property of AddressBean. when the tree is rendered, I only see PersonBean however i dont see children under PersonBean?

Here is example code:

import net.java.dev.properties.container.BeanContainer;
import net.java.dev.properties.container.ObservableIndexed;
import net.java.dev.properties.container.ObservableProperty;
import net.java.dev.properties.IndexedProperty;
import net.java.dev.properties.Property;

public class RootBean
{
public final Property name = new ObservableProperty("");
public final IndexedProperty childrenNodes = new ObservableIndexed();

public RootBean() {
BeanContainer.bind(this);
}

public RootBean(String abbrev) {
this();
name.set(abbrev);
}

public String toString() {
return name.get();
}
}

import net.java.dev.properties.Property;
import net.java.dev.properties.container.ObservableProperty;
import net.java.dev.properties.container.BeanContainer;

public class AddressBean {
public final Property name = new ObservableProperty("");
public final Property address1 = new ObservableProperty("");
public final Property address2 = new ObservableProperty("");
public final Property city = new ObservableProperty("");
public final Property sate = new ObservableProperty(new State(""));
public final Property zip = new ObservableProperty("");

public AddressBean()
{
BeanContainer.bind(this);
}

public AddressBean(String str)
{
this();
name.set(str);
}

public String toString()
{
return name.get();
}
}

public class State {
private String name;
public State() {
}

public State(String name)
{
this.name = name;
}

public String toString() {
return name;
}
}

import net.java.dev.properties.Property;
import net.java.dev.properties.IndexedProperty;
import net.java.dev.properties.container.ObservableProperty;
import net.java.dev.properties.container.BeanContainer;
import net.java.dev.properties.container.ObservableIndexed;

import java.util.Date;

public class PersonBean {
public final Property name = new ObservableProperty("");
public final Property lastName = new ObservableProperty("");
public final Property firstName = new ObservableProperty("");
public final Property dob = new ObservableProperty(new Date());
public final IndexedProperty childrenNodes = new ObservableIndexed();

public PersonBean() {
BeanContainer.bind(this);
}

public PersonBean(String abbrev) {
this();
name.set(abbrev);
}

public String toString() {
return name.get();
}

public static RootBean createTree()
{
RootBean root = new RootBean("root");
PersonBean person = new PersonBean("PERSON1");
person.lastName.set("LAST1");
person.firstName.set("FIRST1");
person.dob.set(new Date(System.currentTimeMillis()));
AddressBean address = new AddressBean("HOME");
address.address1.set("1234 Test Drv");
address.address2.set("PO BOX 123");
address.city.set("San Diego");
address.sate.set(new State("CA"));
person.childrenNodes.add(address);
address = new AddressBean("WORK");
address.address1.set("4321 Test Drv");
address.address2.set("PO BOX 321");
address.city.set("New Yourk");
address.sate.set(new State("NY"));
person.childrenNodes.add(address);
root.childrenNodes.add(person);
person = new PersonBean("PERSON2");
person.lastName.set("LAST2");
person.firstName.set("FIRST2");
person.dob.set(new Date(System.currentTimeMillis()));
address = new AddressBean("HOME");
address.address1.set("1234 Test Drv");
address.address2.set("PO BOX 123");
address.city.set("San Diego");
address.sate.set(new State("CA"));
person.childrenNodes.add(address);
address = new AddressBean("WORK");
address.address1.set("4321 Test Drv");
address.address2.set("PO BOX 321");
address.city.set("New Yourk");
address.sate.set(new State("NY"));
person.childrenNodes.add(address);
root. childrenNodes.add(person);
return root;
}
}

import org.jdesktop.swingx.JXTreeTable;
import org.jdesktop.swingx.JXDatePicker;
import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor;
import org.jdesktop.swingx.renderer.*;

import javax.swing.*;
import javax.swing.table.TableCellEditor;

import net.java.dev.properties.binding.swingx.adapters.SwingXBind;
import net.java.dev.properties.container.PropertyContext;

import java.awt.*;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.util.Date;
import java.util.Vector;
import java.text.DateFormat;

public class TrretableUI {

public RootBean t;
public static JComboBox combo;
public static Vector pos = new Vector();
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
TrretableUI bean = new TrretableUI();
public void run() {
bean.createUI();
}
});
}

public void createUI()
{
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.out.println(e);
}

pos.add(new State(""));
pos.add(new State("FAC1"));
pos.add(new State("FAC2"));
pos.add(new State("FAC3"));

combo = new JComboBox(new DefaultComboBoxModel(pos));

JFrame frm = new JFrame("Tree Test");
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JXTreeTable tree = new JXTreeTable();
tree.setRootVisible(true);
//tree.setShowGrid(true, true);
tree.setDefaultRenderer(Date.class, new DefaultTableRenderer(new DatePickerProvider()));
//tree.setDefaultRenderer(State.class, new DefaultTableRenderer(new ComboBoxProvider()));
tree.setDefaultEditor(Date.class, new DateCellEditor());
tree.setDefaultEditor(State.class, new ComboBoxCellEditor(combo));

tree.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}

public void keyPressed(KeyEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}

public void keyReleased(KeyEvent e) {
// System.out.println(t.childrenNodes.get(0).dob.get());
// System.out.println(t.childrenNodes.get(0).state.get());
}
});
bindTree(tree);
tree.packAll();
frm.add(new JScrollPane(tree), BorderLayout.CENTER);
frm.pack();
frm.setLocationByPlatform(true);
frm.setVisible(true);

}

private void bindTree(JXTreeTable tree) {
t = PersonBean.createTree();
SwingXBind.get().bindContent(t,
new PropertyContext[] {t.childrenNodes.getContext()},
new PropertyContext[]{t.childrenNodes.get(0).lastName.getContext(), t.childrenNodes.get(0).firstName.getContext(),
t.childrenNodes.get(0).dob.getContext(),t.childrenNodes.get(0).childrenNodes.get(0).address1.getContext(),
t.childrenNodes.get(0).childrenNodes.get(0).address2.getContext(), t.childrenNodes.get(0).childrenNodes.get(0).city.getContext(),
t.childrenNodes.get(0).childrenNodes.get(0).sate.getContext()},
tree);
}

public static class DatePickerProvider extends ComponentProvider
{

protected void format(CellContext cellContext) {
//To change body of implemented methods use File | Settings | File Templates.
}

protected void configureState(CellContext cellContext) {

}

protected JXDatePicker createRendererComponent() {
return new JXDatePicker(); //To change body of implemented methods use File | Settings | File Templates.
}
}

public static class ComboBoxProvider extends ComponentProvider
{
protected void format(CellContext cellContext) {
rendererComponent.setSelectedItem(cellContext.getValue());
rendererComponent.revalidate();
}

protected void configureState(CellContext cellContext) {

}

protected JComboBox createRendererComponent() {
return new JComboBox(new DefaultComboBoxModel(pos)); //To change body of implemented methods use File | Settings | File Templates.
}
}

public class DateCellEditor extends AbstractCellEditor implements TableCellEditor {
public DateCellEditor() {
datePicker = new JXDatePicker();
datePicker.setFormats(DateFormat.getDateInstance(DateFormat.SHORT));
}

public Object getCellEditorValue() {
return datePicker.getDate();
}

public Component getTableCellEditorComponent(
JTable table, Object value, boolean isSelected, int row, int column) {
if (value != null && value instanceof Date) {
datePicker.setDate((Date) value);
}
return datePicker;
}

private JXDatePicker datePicker;
}
}

Shai Almog

Root bean must be a person.
The system currently can only support leaf elements of different types
not root or even node elements of a different types.
Otherwise the API would become remarkably complicated and you might as
well write your own tree table model (unless you have an idea on how
to express this properly and implement this efficiently).

--
Shai Almog
vPrise
http://www.vprise.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

mveksler
Offline
Joined: 2007-01-26
Points: 0

Are you saying that it is not posible to represent a tree in this way using bean-property binding?

Person
|----Person1
|----Address1
|----Address2
|---Person2
|---Address1
|---Address2

Is it posible to do somethinf like this?

PersonBean t = PersonBean.createTree();
SwingXBind.get().bindContent(t,
new PropertyContext[] {t.treeNodes.getContext(),t.addressNodes.getContext()},
new PropertyContext[]{t.treeNodes.get(0).lastName.getContext(), t.treeNodes.get(0).firstName.getContext(),
t.treeNodes.get(0).dob.getContext(),t.addressNodes.get(0).address1.getContext(),
t.addressNodes.get(0).address2.getContext(), t.addressNodes.get(0).city.getContext(),
t.addressNodes.get(0).sate.getContext()},
tree);

mveksler
Offline
Joined: 2007-01-26
Points: 0

The tree came out akward:

Person0 or some type of RootElement
_________|---Person1
____________________|--Address1
____________________|--Address2
_________|---Person2
____________________|--Address1
____________________|--Address2

Message was edited by: mveksler

vprise
Offline
Joined: 2003-11-07
Points: 0

Rereading your post, I'd like to be clear that binding to a treetable isn't working properly yet and when it will it would probably require a far more elaborate object to bind.
The treetable is a hierarchic structure and it needs to express that so the binding functionality to something like that would be rather hairy similar in part to the binding for a tree (see the tree binding demo in the repository to get my drift).

vprise
Offline
Joined: 2003-11-07
Points: 0

> I have question regarding this approach.
> I am still unclear about one aspect of this
> approach.
> Sepouse I have custom object that I want to bind to
> in the tree tabel which has getters and setters. The
> question is; do I have to create variables of type
> Property<> for each variable in my custom object that
> I want to bind to?
>
> The previouse approach was to name methods set and
> get and when binding specify the property name (i.e.
> varibale that is used in get and set methods)

There are quite a few ways you can solve a binding issue which is possibly part of your confusion... First there is the obvious way of creating a property object (instantiating it as an ObservableProperty for binding to work), this would remove the need to write getters/setters but you could theoretically add them for compatibility.

If you have a preexisting POJO (get/set) which you don't wish to rewrite then you can just use the mirror approach (read the mirrors documentation in the website) which wraps a POJO with a mirror object that you can pass on to the binding (sample code in the article).

So ideally you wouldn't need to write getters and setters or fire property change listeners ever again once you write beans this way (just don't forget to call BeanContainer.bind(this) in the constructor).

Does that help?

mveksler
Offline
Joined: 2007-01-26
Points: 0

I will have to try it out.
The problem is that I have existing Objects like for example:

public static class TestItem
{
private String name;
private String seqId;

public TestItem(String name, String seqId)
{
this.name= name;
this.seqId = seqId;
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

public String getSeqId()
{
return seqId;
}

public void setSeqId(String seqId)
{
this.seqId = seqId;
}

public String toString()
{
return name;
}
}

I need to bind my TreeTable to this kind of objects where each column will be representing different varibale from this object. That is why I was asking if I need to do the Compatebility approach or as you mentioned the mirror approach.

vprise
Offline
Joined: 2003-11-07
Points: 0

JSR 295 would require that you add property change support for such beans which would mean you would need to change them anyway.
The best solution would be to make such an object into:

public static class TestItem {
public final Propery name = new ObservableProperty();
public final Propery seqId = new ObservableProperty();

public TestItem() {
BeanContainer.bind(this);
}
}

In the long run this might be better since you would need to maintain less code.

The alternative is to build mirror objects as explained here:
https://bean-properties.dev.java.net/mirrors.html

This would mean 0 changes to your existing bean (no need to even add property change support) just do (once for the whole application):
MirrorContext testItemContext = MirrorContext.create(TestItem.class);

And from now on whenever you want to bind a test item to the GUI you can just do:
TestItem item = new TestItem();
Mirror itemMirror = testItemContext.create(item);

"itemMirror" can be treated as a new bean and bound as you would any other new bean e.g.:
SwingBind.get().bind(itemMirror.getProperty("name").getContext(), textField);

Notice that I use getProperty("name") since name is not a standard property.

Every change to item mirror will be reflected into TestItem immediately, the other way around won't occur sine there is no way for the mirror to tell a change occurred in TestItem (unless you choose to implement property change support in which case this can work but you need to create the mirror differently).
To update the mirror just call:
itemMirror.update();

It remembers the parent bean and will update the mirror immediately.

Hope that clears up the confusion a bit.

Shai.

mveksler
Offline
Joined: 2007-01-26
Points: 0

Thank you for clerification.
I understand thaat Mirror will read all the get and set methods and will create Properties internaly however it has the limitation you have pointed out that does not update UI when chnage to the MIrror occures.

What if I use compatebility approach? Will that work?

vprise
Offline
Joined: 2003-11-07
Points: 0

Yes the compatibility approach will work, you can use the exact code I listed above and have getName/setName etc... methods generated as well as the appropriate add/removePropertyChangeListener methods. Rather than generate them into the code they are statically added to your compiled class (see the first tutorial for instructions on how to use this feature).
The ideal way to use this would be to keep your beans in a separate project and use this ant task to build the code. Then you can just use them everywhere even in GUI builders seamlessly since an implementation of getName would just be:
public String getName() {
return name.get();
}

mveksler
Offline
Joined: 2007-01-26
Points: 0

So If i understand the terminalogy here.
The Compatebility Bean is simple a wrapper around original bean?
It will contain a reference to the original bean and will provide sunchtonization mechanizm.

vprise
Offline
Joined: 2003-11-07
Points: 0

A compatibility bean is:
public static class TestItem {
public final Propery name = new ObservableProperty();
public final Propery seqId = new ObservableProperty();

public TestItem() {
BeanContainer.bind(this);
}

public String getName() {
return name.get();
}

public void setName(String name) {
this.name.set(name);
}

// same for seqId.

public void addPropertyChangeListener(String property, PropertyChangeListener l) {
BeanContainer.get().addPropertyChangeListener(this, property, l);
}

// same for the one other add method and 2 other remove methods
}

This way the bean looks to every JavaBean compliant tool (e.g. GUI builders etc.) as a standard JavaBean, they can't tell the difference...
The compatibility methods can be generated at compile time with a tool thats a part of the distribution. You can also write this manually which will still be less than writing all the fire property changed code (with all the related logic)...
You need compatibility beans if you work with a tool that accepts generic JavaBeans and expects get/set methods to exist in said beans. For normal usage of the bean-properties where you write your own code and don't rely on a special tool that works with the JavaBeans API/Convention (such as a GUI builder or ORM) you can just write the properties and ignore the fact that there is no typical getter/setter.

mveksler
Offline
Joined: 2007-01-26
Points: 0

I have question regarding this approach.
I am still unclear about one aspect of this approach.
Sepouse I have custom object that I want to bind to in the tree tabel which has getters and setters. The question is; do I have to create variables of type Property<> for each variable in my custom object that I want to bind to?

The previouse approach was to name methods set and get and when binding specify the property name (i.e. varibale that is used in get and set methods)

mveksler
Offline
Joined: 2007-01-26
Points: 0

Do I have to create a compatebility bean for each of my custom objects?

vprise
Offline
Joined: 2003-11-07
Points: 0

> Do I have to create a compatebility bean for each of
> my custom objects?

You can change your existing beans to use properties rather than fields and do something similar to the compatibility bean example, although if you go that route then the getters and setters can be generated for you by the ant script (using bytecode manipulation described in the first tutorial).
The question is: Do you need getters/setters in your beans and for what?

If I can understand your binding target better I think I could help you more.

vprise
Offline
Joined: 2003-11-07
Points: 0

Karl,
I could really use some help here :-(
I just can't get this to work properly, I looked at your code and I don't see a difference at all yet rather than get a treetable I get a table whose nodes can't be expanded... I have "no idea"?

Thanks,
Shai.

vprise
Offline
Joined: 2003-11-07
Points: 0

I'm already really tired of this whole TreeTable mess I tried running Karl's code to see whether it works and it doesn't provide the hierarchy either:
public static void main(String[] argv) throws Exception {
JFrame frm = new JFrame("Tree Test");
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JXTreeTable tree = new JXTreeTable();
frm.add(new JScrollPane(new JXTreeTable(new SimpleFileSystemModel())), BorderLayout.CENTER);
frm.pack();
frm.setLocationByPlatform(true);
frm.setVisible(true);
}

What am I doing wrong here?

Anyone?

The code from Karl is here:
https://jdnc-incubator.dev.java.net/source/browse/jdnc-incubator/src/ksc...

Thanks.

kschaefe
Offline
Joined: 2006-06-08
Points: 0

Shai,

You've stepped into the middle of my 218/219 fixes. To get the expansion that you're looking for set one of the columns class types to hierarchicalColumnClass. I expect this to be deprecated shortly, as soon as I can muster enough time to finish my tweeks and have Jeanette sign off on them.

Until then any model in that area will only work if you add the hierarchicalColumnClass. Those models will work without modification if you use the versions of the SwingX classes in that area.

Sorry about the confusion, I've been in my own little tree table world for a while now and sometimes forget that the rest of you are not on the same page. ;)

Karl

vprise
Offline
Joined: 2003-11-07
Points: 0

Finally!!! ;-)

Binding of a tree table works just added the fixes to CVS, I will try to build a release bundle and hopefully a minor document explaining how to use everything.

Thanks,
Shai.

kschaefe
Offline
Joined: 2006-06-08
Points: 0

Awesome. Is there a demo for the tree table bindings?

vprise
Offline
Joined: 2003-11-07
Points: 0

Right now its only in CVS:
https://bean-properties.dev.java.net/source/browse/bean-properties/Swing...

I will try to build an engine to enable live demos/tutorials since I think its a great tool to facilitate understanding... but thats bluesky... Here is a screenshot for those of you who don't have the energy to run the demo itself:
https://bean-properties.dev.java.net/treetable.png

vprise
Offline
Joined: 2003-11-07
Points: 0

Added a small tutorial to https://bean-properties.dev.java.net/swingx.html let me know what you think...

mveksler
Offline
Joined: 2007-01-26
Points: 0

Finally got my self together to tryout new bean-properties.
Let me tell you it is very good.
I have started out with the SwingX tutorial and ran into a problem.
I have created my treenodes and used the same example however after updating tree data property the change did not get updated. Only after I hovered mouse over the tree the values got updated. What am I doing wrong? Here is the code.

import net.java.dev.properties.container.ObservableProperty;
import net.java.dev.properties.container.ObservableIndexed;
import net.java.dev.properties.container.BeanContainer;
import net.java.dev.properties.container.PropertyContext;
import net.java.dev.properties.Property;
import net.java.dev.properties.IndexedProperty;
import net.java.dev.properties.binding.swingx.adapters.SwingXBind;

import javax.swing.*;
import java.util.Date;
import java.util.Iterator;
import java.awt.*;

import org.jdesktop.swingx.JXTreeTable;

public class TreeTableNode {
/**
* This observable property will be used in the toString which will be used by TreeTable Renderer to display in the table.
*/
public final Property data = new ObservableProperty("");

/**
* This indexed propery will track changes to the chield tree nodes
*/
public final IndexedProperty childrenNodes = new ObservableIndexed();

/**
* This property will map to a column
*/
public final Property dateColumn = new ObservableProperty();

/**
* This propery will map to another column
*/
public final Property stringColumn = new ObservableProperty();

/** Creates a new instance of TreeBinding */
public TreeTableNode() {
BeanContainer.bind(this);
}

public TreeTableNode(String data) {
this();
this.data.set(data);
}

public String toString() {
return data.get();
}

private static TreeTableNode createTree() {
TreeTableNode t = new TreeTableNode("Data Node");
t.childrenNodes.add(new TreeTableNode("First"));
t.childrenNodes.add(new TreeTableNode("Second"));
t.childrenNodes.add(new TreeTableNode("Third"));
t.childrenNodes.add(new TreeTableNode("Forth"));
TreeTableNode t2 = new TreeTableNode("Has childrenNodes");
t2.stringColumn.set("Simple String");
t2.dateColumn.set(new Date());
t2.childrenNodes.add(new TreeTableNode("Inner Child 1"));
t2.childrenNodes.add(new TreeTableNode("Inner Child 2"));
t.childrenNodes.add(t2);
return t;
}

public static void main(String[] argv) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFrame frm = new JFrame("Tree Test");
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JXTreeTable tree = new JXTreeTable();
tree.setRootVisible(true);
TreeTableNode t = createTree();
SwingXBind.get().bindContent(t,
new PropertyContext[] {t.childrenNodes.getContext()},
new PropertyContext[]{t.dateColumn.getContext(), t.stringColumn.getContext()},
tree);
frm.add(new JScrollPane(tree), BorderLayout.CENTER);
frm.pack();
frm.setLocationByPlatform(true);
frm.setVisible(true);

//After updating data the value does not get updated in the three.
//Only after I hover mouse over the tree elements the value gets updated.
Thread.sleep(10000);
int index=0;
for(Iterator treeNodeIter = t.childrenNodes.iterator();treeNodeIter.hasNext();)
{
TreeTableNode node = (TreeTableNode) treeNodeIter.next();
node.data.set(String.valueOf(index++));
System.out.println(node);
}

}
}

vprise
Offline
Joined: 2003-11-07
Points: 0

Can you try this with the latest code from CVS of the bean-properties?
(no need to update SwingX bindings or anything else).

I recently (less than a week ago) found a bug in event firing for changes of properties that might be the cause of this problem. I will try to check out your code too and confirm that this is the case.

Thanks.

mveksler
Offline
Joined: 2007-01-26
Points: 0

Sure, I am on it. I am really itching to create prototype and roll this baby out.

kschaefe
Offline
Joined: 2006-06-08
Points: 0

> I don't want to use the sources though, just browse
> them and maybe extract ideas. While I would be happy
> to give credit both in the source and the FAQ I don't
> want to force the users of the library to give credit
> so I hope thats OK too (BSD with no advertising
> clause).
Great, use it for your own ideas all you want.

> Right now I have some model working but it looks more
> like a table than a tree, need to refresh my memory
> on how the logic should work... I think I'll just get
> a build going and post it to the java.net CVS so I
> can post a URL here for review. That seems like the
> easiest approach.
It is a tree. The only real difference is the addition of the getValueAt, which allows you to display differing values in differing columns. Think of each column in the tree table as mapping to a property of the node used for that row. In the tree table your not going to be editing the node directly (like a JTree would), but you can edit it's properties (assuming the model is editable).

Karl

mveksler
Offline
Joined: 2007-01-26
Points: 0

The development of this thread took off very fast :-) Actualy much faster then I could read ;-) lol Anyways, here is what I have done so far.
I have played with JTreeTable and was able to succesefuly create table with custom TreetableModel extending DefaultTreetableModel and also with custom MutableTreeTableNode which I was able to decifer from SwingX source.
I got my custom object to show up in the tree and was able to manage delet inser update events.

Here is the thing ;-)
The SwingX early binding version was awesom ;-) All I had to do is create a bean with getters and setters for my custom objects that TreeTable will use and the pass it to the BeanBindingHelper or whatever the name was (cent recall right now) and that was all she wrote ;-) The helper read all the information from the bean and all the property chnage events were working like a charm ;-)
Now, JSR295 looks very much dounting with all the ELs that it has no clear description off. I only spent one day looking through the JSR295 source and will take me some more time to decifer the code and expected behavior.
As for the Bean-Properties, I have glanced at the code and it was even more scary then JSR295. Anyone who will comeup with something using throuse will be my hero ;-) lol

vprise
Offline
Joined: 2003-11-07
Points: 0

> As for the Bean-Properties, I have glanced at the
> code and it was even more scary then JSR295. Anyone
> who will comeup with something using throuse will be
> my hero ;-) lol

It is much bigger than 295 ;-)
However, it also has better documentation so check out the tutorials and let me know if something is unclear.
If there is a sample you need or an explanation you think I can give I will try my best.

Shai Almog

> We created JXTreeTable bindings for Oracle ADF. The easiest thing would
> be to start with the Tree binding from Bean-properties, or JSR-295, and then
> start adding in functionality from the Table binding. Well.... the easiest
> thing would be for someone else to do it, but you get the idea. ;)

I'll try mocking something up tomorrow (past midnight here), I already got
the JXDatePicker to work so hopefully over the weekend all SwingX components
with a proper demo will be in the source control ;-)

Thanks.

--
Shai Almog
vPrise
http://www.vprise.com/
[att1.html]

Shai Almog

> JXTreeTable's TreeTableModel works with whatever objects you'd like it to
> work with. Akin to the JTree/JXTree, you can use TreeNodes to create
> tree-based models for non-tree-based data. However, I would avoid such
> adaptations for objects that are already part of a hierarchical/tree-like
> structure. File systems, HTML documents, Swing hierarchies are all
> inerently tree-based and should be modeled directly. My incubator has a
> version of the FileSystemModel that does exactly that. Such hierarchies
> seem to be the best way to get to understand the TreeTableModel. Using the
> DefaultTreeTableModel, which is designed for TreeNodes, is more difficult,
> since you have to make decisions regarding how the tree should be structured
> from non-tree-based data. So start with an inherently tree-based object
> scheme and you should get the hang of it.

When working with a tree table I tried both approaches, in the past well
before JDNC was even conceived (JDK 1.3 era) I used the old TreeTable in a
project and got something working but I was just never able to get the
JXTreeTable model to work as I expected for anything elaborate with my own
models. Didn't bother me much since I never "really" needed it, I don't
recall all the issues I had but nodes appeared that shouldn't have shown and
getting the exact behavior I wanted was a bit hard.

As for the bindings, I have not tried to use 295 (or Bean-Properties) yet,
> though I have looked at them. There doesn't seem to be anything that a SMOP
> couldn't take care of. However, without digging too deeply (ie completely
> making a wild guess), it may be easier to bind JXTreeTable as a tree, using
> JTree-style bindings. Remember that the TreeTableModel extends the
> TreeModel, so binding to the nodes may be the route to go.
>

If you want to help me build a tree table model by reviewing my code and
telling me what I got wrong I would be happy to build something within the
bean properties project. I'd like to look at your code but I can only use it
if you give me the OK to own derived work, I want the code to be under a no
advertising clause BSD so it can be easily used in an RI for future
standardization (e.g. through the JCP) and I'd rather not mix in GPL/LGPL
code.
If thats OK then I assume you mean this file?
https://jdnc-incubator.dev.java.net/source/browse/jdnc-incubator/src/ksc...

I still need to do bindings for the date picker (any other SwingX components
that have their own model?) so it might be nice to add something like that
to the bean properties project so SwingX guys can get started right away.

Thanks.

--
Shai Almog
vPrise
http://www.vprise.com/
[att1.html]

mveksler
Offline
Joined: 2007-01-26
Points: 0

This looks very good. At least I could follow the code ;-)
I am building more and more understanding of Bean-Properties.
Has anyone tried JSR295?

vprise
Offline
Joined: 2003-11-07
Points: 0

> This looks very good. At least I could follow the
> code ;-)
> I am building more and more understanding of
> Bean-Properties.
> Has anyone tried JSR295?

I did, but as the author of bean properties I am really not objective ;-)
There is some correspondence in the mailing list for 295 which you can look at but most people are playing around with it and it seems further away from production. If you don't like the mentality of bean properties then I think JGoodies or BeanView are both far more mature and don't have all of the complex mess of EL on them.

mveksler
Offline
Joined: 2007-01-26
Points: 0

I do like Beans Properties approach a lot.
I will try to build my own tests to see if I got it.
I will post code samples here so we can share some ideas.
I really need to use TreeTables a lot and I want to get this going for my project.
I have been patiently waiting for binding framework.
Thank you very much.

vprise
Offline
Joined: 2003-11-07
Points: 0

Good thing I checked the forum... I sent two responses last night that just didn't get into the forum, ugh... Pasted bellow are my responses from last night.

> JXTreeTable's TreeTableModel works with whatever
> objects you'd like it to work with. Akin to the
> JTree/JXTree, you can use TreeNodes to create
> tree-based models for non-tree-based data. However,
> I would avoid such adaptations for objects that are
> already part of a hierarchical/tree-like structure.
> File systems, HTML documents, Swing hierarchies are
> all inerently tree-based and should be modeled
> directly. My incubator has a version of the
> FileSystemModel that does exactly that. Such
> hierarchies seem to be the best way to get to
> understand the TreeTableModel. Using the
> DefaultTreeTableModel, which is designed for
> TreeNodes, is more difficult, since you have to make
> decisions regarding how the tree should be
> structured from non-tree-based data. So start with
> an inherently tree-based object scheme and you
> should get the hang of it.

When working with a tree table I tried both approaches, in the past well before JDNC was even conceived (JDK 1.3 era) I used the old TreeTable in a project and got something working but I was just never able to get the JXTreeTable model to work as I expected for anything elaborate with my own models. Didn't bother me much since I never "really" needed it, I don't recall all the issues I had but nodes appeared that shouldn't have shown and getting the exact behavior I wanted was a bit hard.

> As for the bindings, I have not tried to use 295 (or
> Bean-Properties) yet, though I have looked at them.
> There doesn't seem to be anything that a SMOP
> couldn't take care of. However, without digging too
> deeply (ie completely making a wild guess), it may
> be easier to bind JXTreeTable as a tree, using
> JTree-style bindings. Remember that the
> TreeTableModel extends the TreeModel, so binding to
> the nodes may be the route to go.

If you want to help me build a tree table model by reviewing my code and telling me what I got wrong I would be happy to build something within the bean properties project. I'd like to look at your code but I can only use it if you give me the OK to own derived work, I want the code to be under a no advertising clause BSD so it can be easily used in an RI for future standardization ( e.g. through the JCP) and I'd rather not mix in GPL/LGPL code.
If thats OK then I assume you mean this file?
https://jdnc-incubator.dev.java.net/source/browse/jdnc-incubator/src/ksc...

I still need to do bindings for the date picker (any other SwingX components that have their own model?) so it might be nice to add something like that to the bean properties project so SwingX guys can get started right away.

kschaefe
Offline
Joined: 2006-06-08
Points: 0

> If you want to help me build a tree table model by
> reviewing my code and telling me what I got wrong I
> would be happy to build something within the bean
> properties project. I'd like to look at your code but
> I can only use it if you give me the OK to own
> derived work, I want the code to be under a no
> advertising clause BSD so it can be easily used in an
> RI for future standardization ( e.g. through the JCP)
> and I'd rather not mix in GPL/LGPL code.
> If thats OK then I assume you mean this file?
> https://jdnc-incubator.dev.java.net/source/browse/jdnc
> -incubator/src/kschaefe/218/java/org/jdesktop/swingx/t
> reetable/FileSystemModel.java?rev=1.3&view=markup
Not a problem. If you post your models here, you should get all the advice you need. I believe that I still have rights to everything that I write. I based my model on Ramesh's original model, but it's almost completely rewritten to remove the TreeNode stuff that he used, so I guess that means that I can allow you to use it. Richard, is there any issue here? If not, you can use it, just give credit.

Karl

vprise
Offline
Joined: 2003-11-07
Points: 0

> Not a problem. If you post your models here, you
> should get all the advice you need. I believe that I
> still have rights to everything that I write. I
> based my model on Ramesh's original model, but it's
> almost completely rewritten to remove the TreeNode
> stuff that he used, so I guess that means that I can
> allow you to use it. Richard, is there any issue
> here? If not, you can use it, just give credit.

Thanks,
I don't want to use the sources though, just browse them and maybe extract ideas. While I would be happy to give credit both in the source and the FAQ I don't want to force the users of the library to give credit so I hope thats OK too (BSD with no advertising clause).
Also I hope its OK if I choose to relicense/assign copyright in the future, the main reason being that I would like to make an RI out of the code.

Right now I have some model working but it looks more like a table than a tree, need to refresh my memory on how the logic should work... I think I'll just get a build going and post it to the java.net CVS so I can post a URL here for review. That seems like the easiest approach.

Thanks,
Shai.