BeeSoft®
Since 1992
 

Content

 Welcome
 Products
       Abeona
       Gaia
       Hephaistos
       JavaGantt
             Features
             News
             Documentation
                   Programming domain objects
                   About JavaGantt model
                   Undo / Redo support
                   Localization support
                   Building a treetable
                   Painting a chart
                   Working with the time scale
                   JavaGantt actions
             License
             Download
             Purchase
 Services
       Promote your software
 Contact Us
 Links
      
  JavaGanttI®
© 2012 BeeSoft ®
 

Building a treetable

Well, we have our domain object's hierarchy in our demo application. It consists of class Task instances. We created also class Project. It is derived from Task and contains a list of resources (workers, they can be assigned to the tasks). Project is the root object of our hierarchy.

Now we want to display this hierarchy in gantt chart treetable. To make the things easy, we will not create a deep tree of tree nodes. Instead of this, we override one method in GanttModel:

	@Override
	public void explore (GanttNode node) {
		Task task = (Task) node.getUserObject ();
		for (Task t : task.getSubtask ()) {
			GanttNode child = new GanttNode (this, t);
			if (t.getSubtask ().isEmpty ()) {
				child.setExplorable (false);
			}
			node.add (child);
		}
	}

Method explore() is invoked when the treetable expandes node for the first time and this node does not know its content. We use this method just to create GanttNode and to add it to the tree hierarchy. Of course, you can use this method to obtain domain objects from a database or network, if your domain objects hierarchy is too large. This is the place where you can implement the lazy loading very easily.

And now we can tell to our model about its root:


	Project project = new Project ();
	project.setName ("Project");
	project.addSubtask (task_1);
	...
	project.addSubtask (task_N);
	project.addResource (worker_1);
	...
	project.addResource (worker_N);

	model.setRootObject (project);

And to create columns for treetable:


	JavaGantt gantt = ....
	GanttColumn column = new GanttColumn ();
	column.setHeaderValue ("Task name");
	gantt.addColumn (column);

	column = new GanttColumn ();
	column.setHeaderValue ("Task ID");
	gantt.addColumn (column);


Data binding

How to display data in treetable columns? There are two ways:

  1. override method public Object getValueAt (TreeTableNode node, int column) in GanttModel. In this method you have to get an user object from TreeTable (it is a Task) and return value for given column from it.
  2. don't override this method and use data binding.

Data binding works very simply (from the programmer's point of view). It uses class eu.beesoft.gaia.util.Miner to get (and also set) the value from (to) object. Value is defined by the property or field name. Miner tries to find getter for property, and if this was not successful, it uses field access.

So all you need to do is to tell the column about property (field) to display:


	column.setBinding ("startDate");

You can use dot-convention for property name, if your property is not in given object, but in referenced object. In our demo application has class Task the field assignee. So if you want to display a task assignee's name in column, you can set binding this way:


	column.setBinding ("assignee.name");


Localization

A few lines above we set the column name with method column.setHeaderValue (). This is the usual way, known from JTable and its components.

But JavaGantt treetable has built-in facility to use data from resource bundle. There is a method setResourceBundleKey (String) on GanttColumn class. With this method you can set a key for column name in resource bundle:


	column.setResourceBundleKey ("columnStartDate");

and in your JavaGantt resource bundle to define something like:

	columnStartDate=Start date

When you or user changes the application language environment, you have to take a care only of localized resource bundle.


Mouse support

Class JavaGantt has two methods to support mouse operations on treetable:

  • doubleClicked(GanttNode)
  • getPopupActions (List<GanttNode>)

The first is invoked when user double clicked on some tree node. Method gets this tree node as argument - and that is all. The implementation in JavaGantt is empty, so you have to override this method to give it some meaning. In our demo application we construct and display task properties form in this method.

The second method is invoked when user right clicked on some tree node (or more nodes). Its implementation is also empty. If you will override it and return a list of actions, JavaGantt constructs popup menu and displays it.