X

Geertjan's Blog

  • October 8, 2007

Marilyn in a J2SE TreeTableView

Geertjan Wielenga
Product Manager
At the end of yesterday's blog entry, hilz asked about multiple nodes in a TreeTableView. Well, here's the start of something along those lines:

It is the old NetBeans Nodes, Explorer Manager, and Component Palette Tutorial tutorial, but this time with a TreeTableView, and Marilyn isn't on the NetBeans Platform anymore. I just put the NetBeans API JARs into my J2SE application. Here's the source structure:

I put the sample in the Plugin Portal. When you install it, you'll get the info you need about the required JARs (probably the actions JAR isn't needed, actually):

And this is where you can find the sample in the New Project wizard:

I'll be extending the sample when/if I can find some time to do so. For example, in response to the question by Balazs, also at the end of yesterday's blog entry, I have made the first Tree column sortable (as well as adding various colors):

You need to use the TreeColumnTTV property, in order to identify the first column (as described here). Here's the bit of relevant code:

Node[] nodes = categories().getChildren().getNodes();
firstColumnprops = nodes[0].getPropertySets()[0].getProperties();
firstColumnprops[0].setValue("TreeColumnTTV", Boolean.TRUE); //NOI18N
firstColumnprops[0].setValue("SortingColumnTTV", Boolean.TRUE);
firstColumnprops[0].setValue("ComparableColumnTTV", Boolean.TRUE); //NOI18N
marilynTTV.setProperties(firstColumnprops);
secondColumnProps = nodes[1].getPropertySets()[0].getProperties();
secondColumnProps[0].setValue("ComparableColumnTTV", Boolean.TRUE);
marilynTTV.setProperties(secondColumnProps);
marilynTTV.setRootVisible(false);

For me, not only does the sort arrow appear in the column, but it works as expected when I click it. Hope this helps, Balazs!

Join the discussion

Comments ( 12 )
  • Balazs Tuesday, October 9, 2007

    The way I work is that I setup the content of the data model (and thus the nodes) asynchronously (from a remote data source for example). So the first time there is an attempt to ask for the children, it will start a background thread that will update the model with the arriving data.

    The other thing why I don't get the properties directly from the children nodes (like categories().getChildren().getNodes()) is that I want to setup the columns for example from a configuration, so any component can "assemble" it as it wants. For this I do the following:

    TreeTableView treeTableView = new TreeTableView();

    treeTableView.setRootVisible( false );

    // Set the columns for the view:

    Node.Property mainDescriptionProperty = new MainDescriptionProperty( null ); // put whatever parameter here

    Node.Property levelProperty = new LevelProperty( 0 ); // put whatever parameter here

    treeTableView.setProperties( new Node.Property[] { mainDescriptionProperty, levelProperty } );

    The code of MainDescriptionProperty is exactly as I sent yesterday. So I get the arrow, but no sorting is done :-(


  • Geertjan Tuesday, October 9, 2007

    Instead of this:

    this.setValue( "SortingColumnTTV", Boolean.FALSE );

    Put this:

    this.setValue( "SortingColumnTTV", Boolean.TRUE); //

    I understand that you initially do not want it to be sorted by that column, but try it and see if doing this will enable the arrow to work. Also, you need to click the arrow a few times, first time is neutral, second time ascending, third time descending, or something like that.


  • Geertjan Tuesday, October 9, 2007

    Also, the order in which you set things is important. Here is my TopComponent's constructor:

    public MyFirstFrame() {

    manager = new ExplorerManager();

    manager.setRootContext(new AbstractNode(new CategoryChildren()));

    manager.getRootContext().setDisplayName("Categories");

    nodeTableModel = new NodeTableModel();

    nodeTableModel.setNodes(new Node[]{categories()});

    initComponents();

    Node[] nodes = categories().getChildren().getNodes();

    firstColumnprops = nodes[0].getPropertySets()[0].getProperties();

    firstColumnprops[0].setValue("TreeColumnTTV", Boolean.TRUE); //NOI18N

    firstColumnprops[0].setValue("SortingColumnTTV", Boolean.TRUE);

    firstColumnprops[0].setValue("ComparableColumnTTV", Boolean.TRUE); //NOI18N

    marilynTTV.setProperties(firstColumnprops);

    secondColumnProps = nodes[1].getPropertySets()[0].getProperties();

    secondColumnProps[0].setValue("ComparableColumnTTV", Boolean.TRUE);

    marilynTTV.setProperties(secondColumnProps);

    marilynTTV.setRootVisible(false);

    }


  • Geertjan Tuesday, October 9, 2007

    Also, what happens when you right-click in the TTV? You should see the popup that you see in the last pic above. If so, does sorting work there? It should, even for the first column, which in my case, above in the final pic, is called "Categories".


  • Balazs Tuesday, October 9, 2007

    Everything works like as you described, except that the content is not sorted (the arrows appear, when I click they change, sorting popup is correct). The first column is probably something very special, because sorting works on all the other columns.

    Also tried setting SortingColumnTTV to true: same effect, sorting doesn't work either.

    Now will try to create a dummy node and get the properties from its children to see if it fixes the problem...


  • Geertjan Tuesday, October 9, 2007

    OK, interested to know what happens.


  • Balazs Tuesday, October 9, 2007

    I've got the same effect creating a dummy object and dummy node: sorting is not working still for the first column... :-(

    At least your sample works (tried it), so probably there is something wrong with the nodes I create (at least I hope so) ;-)

    Will come back if I find the problem (and solution).


  • Balazs Tuesday, October 9, 2007

    Ok, I found why did not work.

    I thought it is enough for the system to call getDisplayedName() to be able to identify what to sort.

    No, it's not enough. It is very important (and I would say then mandatory :-) ) to call setDisplayName() in each node's constructor to be able to sort it (at least for the first column)!

    Again thanks for the sample, without that probably it took me years to find what was wrong ;-)


  • Geertjan Tuesday, October 9, 2007

    Hi Balazs! Congratulations. Yes, the TreeTableView is tricky. I've heard (for years already) that we want to replace it with something easier. However, in the meantime, as you have experienced, once you have it working, it is very cool. However, sometimes, getting it working exactly as you want is difficult.


  • Pg Friday, January 4, 2008

    Hi! It is possible to intenationalize "List Option", "Sort", "Ascending", "Descending"?


  • Ruwan Sunday, January 20, 2008

    Hi, it seems cool. How can I use this in visual web?


  • petia Monday, January 12, 2009

    Hi. Is it possible to hide root nodes here and to live only values in columns?


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.