Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Issue with tree grid in 1.0.0
Issue with tree grid in 1.0.0 [message #1061243] Thu, 30 May 2013 17:53 Go to next message
Testr t is currently offline Testr tFriend
Messages: 93
Registered: April 2013
Member
Hi,

I have a tree grid with child rows which worked perfectly in 0.9.0 but with 1.0.0 I am able to see the grid but there is no plus sign.

Here is my expansion model the TreeGridFormat which used to work perfectly

	public class DataRow
	{
		final static int Cols = 3;
		DataRow parent;
		String Name;
		// list of data for each column
		List<BigInteger> data = new ArrayList<>();
		
		public DataRow( DataRow parent, String name )
		{
			this.parent = parent;
			Name = name;
		}
		
		/*
		 * Initialize the data for the containers.
		 */
		public void AddColData( int count )
		{
			for (int cont = 0; cont < count; cont++)
			{
				BigInteger colData = new BigInteger( 32, new Random() );
				data.add( colData );
			}
		}

		/* 
		 * Adds child rows for the row
		 */
		public List<DataRow> AddChildren()
		{
			List<DataRow> childRows = new ArrayList<>();
			for (int c = 0; c <= 5; c++)
			{
				DataRow childRow = new DataRow( this, "Child" + c );
				childRow.AddColData( Cols );
				childRows.add( childRow );
			}
			return childRows;
		}
		
		public DataRow getParent()
		{
			return parent;
		}
		
		public String getName()
		{
			return Name;
		}
		
		public int Count()
		{
			return data.size();
		}
		
		public String getData( int colIndex )
		{
			String hexValue = "";
			hexValue = Integer.toHexString( colIndex );
			return hexValue;
		}
		
		public void setData(int col, String value)
		{
			
		}
	}
	/*
	 * Class that defines the tree structure of a node by expressing the path from the element itself to the tree's root.
	 */
	private static class TreeFormat implements TreeList.Format<DataRow>
	{
		public TreeFormat( ISortModel sortModel )
		{
		}

		/*
		 * Populate path with a list describing the path from a root node to this element. 
		 * Upon returning, the list must have size >= 1, where the provided element identical to the list's last element.
		 * @param path  //a list that the implementor shall add their path elements to via path.add(). This may be a non-empty List and it is an error to call any method other than add().
		 */
		public void getPath( List<DataRow> path, DataRow row )
		{
			path.add( row );
			DataRow parent = row.getParent();
			while( parent != null )
			{
				path.add(0, parent );
				parent = parent.getParent();
			}
			//Collections.reverse( path );
		}

		/*
		 * Indicate whether an element can have children
		 */
		public boolean allowsChildren( DataRow row )
		{
			return true;
		}

		/*
		 * Returns the comparator used to order path elements of the specified depth. 
		 * If enforcing order at this level is not intended, this method should return null.
		 */
		public Comparator<DataRow> getComparator( int depth )
		{
			return null;
		}
	}

	/*
	 * Tree grid expansion model. Need to be implemented to set the initial expand/collapse state
	 */
	private class TreeExpansionModel implements ExpansionModel<DataRow>
	{
		/*
		 * Determines the specified element's initial expand/collapse state.
		 */
		public boolean isExpanded( DataRow element, List<DataRow> path )
		{
			//initial state of the grid would be collapsed
			return false;
		}

		/*
		 * Handler method when a row expand/collapse state is changed
		 */
		public void setExpanded( DataRow element, List<DataRow> path, boolean expanded )
		{
			//currently we don't have to track expand or collapsed state of a row
		}
	}


And I used the tree grid example to create the lists

		// Underlying data source
		EventList<DataRow> eventList = GlazedLists.eventList( rows );
		SortedList<DataRow> sortedList = new SortedList<>( eventList, null );
		
		int columns = eventList.get( 0 ).Count();
		NumCols = FirstValueCol + columns;
		//Column accessor
		IColumnPropertyAccessor<DataRow> columnPropertyAccessor = new ColumnPropertyAccessor();

		// Column header layer
	
			List<String> colNames = new ArrayList<>();
			colNames.add( "Name" );
			for (int col = 0; col < columns; col++)
				colNames.add("Col " + " " + col );
			String[] colLabels = (String[]) colNames.toArray( new String[0] );
	
		IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider( colLabels );
		DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer( columnHeaderDataProvider );

		ISortModel sortModel = new GlazedListsSortModel<DataRow>( sortedList, columnPropertyAccessor, configRegistry, columnHeaderDataLayer );

		
		final TreeList<DataRow> treeList = new TreeList<DataRow>( sortedList, new TreeFormat( sortModel ), new TreeExpansionModel() );
		
		GlazedListTreeData<DataRow> treeData = new GlazedListTreeData<>( treeList );
		bodyDataProvider = new GlazedListsDataProvider<>( treeList, columnPropertyAccessor );
		DataLayer bodyDataLayer = new DataLayer( bodyDataProvider );
		bodyDataLayer.setDefaultColumnWidthByPosition( 1, 60 );
		// Body layer
		ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer( bodyDataLayer );
		ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer( columnReorderLayer );
		SelectionLayer selectionLayer = new SelectionLayer( columnHideShowLayer );

		// Switch the ITreeRowModel implementation between using native grid
		// Hide/Show or GlazedList TreeList Hide/Show
		// TreeLayer treeLayer = new TreeLayer(selectionLayer, new TreeRowModel(treeData), true);
		TreeLayer treeLayer = new TreeLayer( selectionLayer, new GlazedListTreeRowModel<DataRow>( treeData ), false );
		treeLayer.setConfigLabelAccumulator( new CellStateAccumulator() );
		ViewportLayer viewportLayer = new ViewportLayer( treeLayer );

		ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer( columnHeaderDataLayer, viewportLayer, selectionLayer );
		// Note: The column header layer is wrapped in a filter row composite.
		// This plugs in the filter row functionality
		ColumnOverrideLabelAccumulator labelAccumulator = new ColumnOverrideLabelAccumulator( columnHeaderDataLayer );
		columnHeaderDataLayer.setConfigLabelAccumulator( labelAccumulator );

		SortHeaderLayer<DataRow> sortHeaderLayer = new SortHeaderLayer<>( columnHeaderLayer, sortModel, false );

		// Row header layer
		DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider( bodyDataProvider );
		DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer( rowHeaderDataProvider );
		RowHeaderLayer rowHeaderLayer = new RowHeaderLayer( rowHeaderDataLayer, viewportLayer, selectionLayer );

		// Corner layer
		DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider( columnHeaderDataProvider, rowHeaderDataProvider );
		DataLayer cornerDataLayer = new DataLayer( cornerDataProvider );
		CornerLayer cornerLayer = new CornerLayer( cornerDataLayer, rowHeaderLayer, sortHeaderLayer );
Re: Issue with tree grid in 1.0.0 [message #1061247 is a reply to message #1061243] Thu, 30 May 2013 18:38 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
First I usually suggest to set the SelectionLayer on top of the TreeLayer and not vice versa.

The other thing might be that the sorting does not match. The tree is only able to build up correctly if the sorting of the elements is correct. So I assume you have to implement a Comparator instead of returning null.

That might be related to updating to GlazedLists 1.9, but I have to admit that I don't know exactly what the issue might be.
Re: Issue with tree grid in 1.0.0 [message #1061259 is a reply to message #1061247] Thu, 30 May 2013 20:16 Go to previous messageGo to next message
Testr t is currently offline Testr tFriend
Messages: 93
Registered: April 2013
Member
I modified the SelectionLayer to be on top of the TreeLayer and also implemented the SortableTreeComparator and I still dont see the + sign in the parent rows that has child rows.
Re: Issue with tree grid in 1.0.0 [message #1061269 is a reply to message #1061259] Thu, 30 May 2013 21:18 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Maybe it's because you don't use the default configuration in your TreeLayer?
Re: Issue with tree grid in 1.0.0 [message #1061277 is a reply to message #1061269] Thu, 30 May 2013 22:03 Go to previous messageGo to next message
Testr t is currently offline Testr tFriend
Messages: 93
Registered: April 2013
Member
Ok, I changed to use default configuration (changed parementer in TreeLayer constructor to true) and still in 1.0.0 version I don't see the + sign. I have taken most of the code from Example code and I modified it to have the columnpropertyaccessor to provide different data for columns and not from the property.
Re: Issue with tree grid in 1.0.0 [message #1061293 is a reply to message #1061277] Fri, 31 May 2013 04:42 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Well the only thing that I see in your code above then is the ColumnPropertyAccessor that is registered to the TreeLayer. Have you checked which labels are in the LabelStack of cells is the first column?
Re: Issue with tree grid in 1.0.0 [message #1061466 is a reply to message #1061293] Fri, 31 May 2013 19:18 Go to previous messageGo to next message
Testr t is currently offline Testr tFriend
Messages: 93
Registered: April 2013
Member
I have added the ColumnPropertyAccessor to the GlazedListDataProvider and it shouldnt be? Could you please let me know where it should be registered?

Here is the class
	/*
	 * Class that provides the grid column values
	 */
	private class ColumnPropertyAccessor implements IColumnPropertyAccessor<DataRow>
	{

		@Override
		public int getColumnCount()
		{
			return NumCols;
		}

		@Override
		public Object getDataValue( DataRow row, int col )
		{
			//System.out.println("col accessor for Row: " + row.getAddress() + "Col: " + col );
			String value;
			if( col == 0 )
				value = row.getName();
			else
				value = row.getData( col - FirstValueCol );
			return value;
		}

		@Override
		public void setDataValue( DataRow row, int col, Object newValue )
		{
			if( col >= FirstValueCol )
				row.setData(  col - FirstValueCol, (String)newValue );
		}

		@Override
		public int getColumnIndex( String arg0 )
		{
			return 0;
		}

		@Override
		public String getColumnProperty( int arg0 )
		{
			return null;
		}

	}


And I have the CellStateAccumulator which defines the lables

/*
	 * Class that provides the label configuration
	 */
	public class CellStateAccumulator implements IConfigLabelAccumulator
	{
		public CellStateAccumulator()
		{	
		}
		
		@Override
        public void accumulateConfigLabels( LabelStack stack, int col, int row )
		{
		   if( col >= FirstValueCol )
			{
				stack.addLabel( GridConfiguration.RightAllignLabel );
				//for all container columns set hex label
				stack.addLabel( GridConfiguration.HexCellLabel ); 
			}
			else;
				stack.addLabel( GridConfiguration.LeftAllignLabel );
			//System.out.println("accumulate for Row: " + row + " Col: " + col );
		}
	}


It just adds the left allign label to the first column
Re: Issue with tree grid in 1.0.0 [message #1061467 is a reply to message #1061466] Fri, 31 May 2013 19:24 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Sorry, of course I meant the accumulator.

What happens if you don't set that label to the first column?
Re: Issue with tree grid in 1.0.0 [message #1061469 is a reply to message #1061467] Fri, 31 May 2013 19:30 Go to previous messageGo to next message
Testr t is currently offline Testr tFriend
Messages: 93
Registered: April 2013
Member
Even if I remove the LeftAllignLabel for the first column the result is the same.
Re: Issue with tree grid in 1.0.0 [message #1061470 is a reply to message #1061469] Fri, 31 May 2013 19:36 Go to previous messageGo to next message
Testr t is currently offline Testr tFriend
Messages: 93
Registered: April 2013
Member
Is there anything that changed on the way how the first column with + sign is rendered in the new version? would it help if I upload the entire code that you can directly run?
Re: Issue with tree grid in 1.0.0 [message #1061472 is a reply to message #1061469] Fri, 31 May 2013 19:51 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Puh, hard to tell then without debugging.

Do you know about the debug menu item? Try to add a menu that contains that menu item to check if the tree label is there.

Try to don't add the accumulator to the treeline but to the DataLayer instead.

Check the API docs of the constructors to get some hints.

Check the ordering of your items. Are all items shown or do you only see the parents?

Double check our examples, as there still the icons are shown.
Re: Issue with tree grid in 1.0.0 [message #1061476 is a reply to message #1061472] Fri, 31 May 2013 20:10 Go to previous messageGo to next message
Testr t is currently offline Testr tFriend
Messages: 93
Registered: April 2013
Member
I only see the parents. What is a debug menu item? You mean to find out if TreeLabel is set on the first column? Is this something that Nattable does internally?
Re: Issue with tree grid in 1.0.0 [message #1061477 is a reply to message #1061476] Fri, 31 May 2013 20:15 Go to previous messageGo to next message
Testr t is currently offline Testr tFriend
Messages: 93
Registered: April 2013
Member
Okay, If I add the Tree label manually in my CellLabelAccumulator it works. Instead of the LeftAllignLabel I add the TreeLayer.TREE_COLUMN_CELL and it works now. So is it somewhere the label is being overwritten? I guess something in the layer configuration changed on 1.0.0?

else
stack.addLabelOnTop( TreeLayer.TREE_COLUMN_CELL );
Re: Issue with tree grid in 1.0.0 [message #1061480 is a reply to message #1061477] Fri, 31 May 2013 20:34 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Ah, now I think I remember.

Before the TreeLayer added the necessary label hard coded in the layer itself. And the change was to move that into an accumulator. As only one accumulator can be set per layer and you set an accumulator to the TreeLayer yourself you override the default.
Re: Issue with tree grid in 1.0.0 [message #1061484 is a reply to message #1061480] Fri, 31 May 2013 21:01 Go to previous message
Testr t is currently offline Testr tFriend
Messages: 93
Registered: April 2013
Member
Thanks Dirk for the hint on Tree Label. If i dont register my label accumulator on the TreeLayer I dont have to add the Tree label myself and it works on both 0.9.0 and 1.0.0
Previous Topic:Hex cell editor
Next Topic:Applying CSS to NatTable
Goto Forum:
  


Current Time: Tue Apr 23 06:48:18 GMT 2024

Powered by FUDForum. Page generated in 0.04472 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top