Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Issue with Tree grid
Issue with Tree grid [message #1241379] Fri, 07 February 2014 22:20 Go to next message
tony hedoux is currently offline tony hedouxFriend
Messages: 19
Registered: May 2012
Junior Member
Hi,

From the tree grid example, I try to use natTable to show a tree.
I have a full tree data structure, where compare between Item are based on an unique ID.

My data structure is an EMF one.

Issue is some items appears many times at the same level of my tree.

Where I expected :

A - B
- C
- D

I obtained :

A - B
- C
A - D

My formatter is the same than the example one, minor the EMF differences :


    /**
     * Construct path from root to current element.
     * 
     * @param pPath The list which will contain path
     * @param pElement The element for which path will be constructed
     */
    @Override
    public void getPath(final List<EObject> pPath, final EObject pElement) {
        pPath.add(pElement);
        EObject vParent = pElement.eContainer();
        while (vParent != null) {
            pPath.add(vParent);
            vParent = vParent.eContainer();
        }
        Collections.reverse(pPath);
    }



This is the results of the pretty printer in example

 - Model@7d94be61 (UUID: 13f6a062-e007-40a6-aa3f-7cc7d25603e2)
	  SystemEvent@5d6ddc5 (UUID: _1u2cCPmxEeKDk4RlwuVRlA) 
	- Container@305f12b0 (UUID: 4e4ae8d1-9259-40a3-905c-91cedd5bd786)
		- Block@59ce4e28 (UUID: 051b33e8-0d76-43e9-bb7a-1f822cec7a41)
			  LocalEvent@5a22c38f (UUID: _1u2cAvmxEeKDk4RlwuVRlA) 
		- Block@59ce4e28 (UUID: 051b33e8-0d76-43e9-bb7a-1f822cec7a41) 
			- Port@776d5227 (UUID: _1u10_vmxEeKDk4RlwuVRlA) 
				  FailureMode@2a2cbbb2 (UUID: _1u10__mxEeKDk4RlwuVRlA) 
				  FailureMode@62fb343d (UUID: _1u2cAfmxEeKDk4RlwuVRlA)
			- Port@776d5227 (UUID: _1u10_vmxEeKDk4RlwuVRlA)
				  FailureMode@5ed6b8bf (UUID: _1u2cAPmxEeKDk4RlwuVRlA)
		- Block@2078afe (UUID: 0c3b5384-7ad0-416c-a32d-24336394d139)
			  LocalEvent@2ef8eeee (UUID: _1u10_PmxEeKDk4RlwuVRlA)
			- Port@7fe2f29e (UUID: _1u10-PmxEeKDk4RlwuVRlA)
				  FailureMode@ca6a4aa (UUID: _1u10-fmxEeKDk4RlwuVRlA)
				  FailureMode@71f5890d (UUID: _1u10-_mxEeKDk4RlwuVRlA)
				  FailureMode@10849b63 (UUID: _1u10-vmxEeKDk4RlwuVRlA) 
			  Port@7fe2f29e (UUID: _1u10-PmxEeKDk4RlwuVRlA)
			- Port@3d362abc (UUID: _1u109PmxEeKDk4RlwuVRlA) 
				  FailureMode@2f2fbc09 (UUID: _1u109fmxEeKDk4RlwuVRlA)
			- Port@3d362abc (UUID: _1u109PmxEeKDk4RlwuVRlA)
				  FailureMode@66e20b12 (UUID: _1u109vmxEeKDk4RlwuVRlA)
				  FailureMode@244ff83 (UUID: _1u109_mxEeKDk4RlwuVRlA)
		- Block@31c3f99f (UUID: 3bf54ab6-ebe3-46c8-815a-9c90f51af189)
			  LocalEvent@7ed9bdbf (UUID: _1u1N5PmxEeKDk4RlwuVRlA)
		- Block@31c3f99f (UUID: 3bf54ab6-ebe3-46c8-815a-9c90f51af189)
			- Port@39394f3f (UUID: _1u0m1PmxEeKDk4RlwuVRlA)
				  FailureMode@1118d061 (UUID: _1u0m1vmxEeKDk4RlwuVRlA) 
			- Port@39394f3f (UUID: _1u0m1PmxEeKDk4RlwuVRlA)
				  FailureMode@7418990b (UUID: _1u0m1_mxEeKDk4RlwuVRlA) 
				  FailureMode@6181ce72 (UUID: _1u0m1fmxEeKDk4RlwuVRlA)
			- Port@7ae7dcb8 (UUID: _1u1N4PmxEeKDk4RlwuVRlA) 
				  FailureMode@4e43290c (UUID: _1u1N4vmxEeKDk4RlwuVRlA)
			- Port@7ae7dcb8 (UUID: _1u1N4PmxEeKDk4RlwuVRlA)
				  FailureMode@c4bf312 (UUID: _1u1N4fmxEeKDk4RlwuVRlA)
				  FailureMode@1b3bfaf8 (UUID: _1u1N4_mxEeKDk4RlwuVRlA)
		- Block@93887a9 (UUID: b577ad36-0dc7-48e1-a46e-5925ec030e7f) 
			  LocalEvent@4e82972c (UUID: _1u108vmxEeKDk4RlwuVRlA)
		- Block@93887a9 (UUID: b577ad36-0dc7-48e1-a46e-5925ec030e7f)
			- Port@5e526cf9 (UUID: _1u1N5vmxEeKDk4RlwuVRlA)
				  FailureMode@6259d602 (UUID: _1u1N6fmxEeKDk4RlwuVRlA)
			- Port@5e526cf9 (UUID: _1u1N5vmxEeKDk4RlwuVRlA)
				  FailureMode@2cd72b45 (UUID: _1u1N6PmxEeKDk4RlwuVRlA)
				  FailureMode@75707fcf (UUID: _1u1N5_mxEeKDk4RlwuVRlA)
			- Port@77f14fbf (UUID: _1u1N6vmxEeKDk4RlwuVRlA) 
				  FailureMode@494b05ae (UUID: _1u1N7fmxEeKDk4RlwuVRlA) 
				  FailureMode@3fae4173 (UUID: _1u1N7PmxEeKDk4RlwuVRlA) 
				  FailureMode@3aac21e (UUID: _1u1N6_mxEeKDk4RlwuVRlA) 
			- Port@5c620819 (UUID: _1u1N7vmxEeKDk4RlwuVRlA) 
				  FailureMode@2801d0b1 (UUID: _1u1N7_mxEeKDk4RlwuVRlA) 
				  FailureMode@1c36c02c (UUID: _1u108fmxEeKDk4RlwuVRlA) 
				  FailureMode@f2c28fc (UUID: _1u108PmxEeKDk4RlwuVRlA)
			- Barrier@5f92f1f8 (UUID: _bUNrQPnoEeKfcKMjO25DyQ)
				  FailureMode@7ea115d7 (UUID: _bUf_IvnoEeKfcKMjO25DyQ) 
				  FailureMode@284c01cd (UUID: _bUf_IPnoEeKfcKMjO25DyQ) 
				  FailureMode@160a4e66 (UUID: _bUf_IfnoEeKfcKMjO25DyQ)
			  Barrier@5f92f1f8 (UUID: _bUNrQPnoEeKfcKMjO25DyQ) 




Line 4 & 6 should be only "one line" for me.

Any clue about what is wrong?

Thx for help,

Tony
Re: Issue with Tree grid [message #1241385 is a reply to message #1241379] Fri, 07 February 2014 22:27 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2704
Registered: July 2012
Senior Member
If the same value is shown several times in a tree, your comparator is not sorting correctly.
Re: Issue with Tree grid [message #1241691 is a reply to message #1241385] Sat, 08 February 2014 10:44 Go to previous messageGo to next message
tony hedoux is currently offline tony hedouxFriend
Messages: 19
Registered: May 2012
Junior Member
Hi Dirk,

I take a look to my Comparator (the one return by TreeList.Format implementation) , it is a basic UUID comparator, relying on string comparator :

    @Override
    public Comparator<? super EObject> getComparator(final int pDepth) {
        Comparator vComparator = null;

        vComparator = new Comparator<EObject>() {

            @Override
            public int compare(final EObject pO1, final EObject pO2) {
                int vReturnValue = 0;

                String vUUID1 = ((IAbstractIdentifiedObject) pO1).getUUID();
                String vUUID2 = ((IAbstractIdentifiedObject) pO2).getUUID();

                vReturnValue = vUUID1.compareTo(vUUID2);

                return vReturnValue;
            }
        };

        return vComparator;
    }


I have done some tests, and (still for example) line 4 UUID & line 6 UUID return the result 0, as expected.
There is another comparator i should take care of?

Tony
Re: Issue with Tree grid [message #1241775 is a reply to message #1241691] Sat, 08 February 2014 13:53 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2704
Registered: July 2012
Senior Member
Well that comparison seems to be correct. But you don't not ensure that the elements are in the correct order regarding the parent. You need to extend the comparator for the check of the parent.
Re: Issue with Tree grid [message #1241958 is a reply to message #1241775] Sat, 08 February 2014 20:39 Go to previous messageGo to next message
tony hedoux is currently offline tony hedouxFriend
Messages: 19
Registered: May 2012
Junior Member
Can you develop a little? What do you mean by " are in the correct order regarding the parent" ?

Thx for your time,

Tony
Re: Issue with Tree grid [message #1242312 is a reply to message #1241958] Sun, 09 February 2014 10:24 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2704
Registered: July 2012
Senior Member
I thought in the examples we have something like that. I'm writing from my tablet, so coding is hard now. Let me try to explain.

Re: Issue with Tree grid [message #1242318 is a reply to message #1242312] Sun, 09 February 2014 10:34 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2704
Registered: July 2012
Senior Member
The comparator is used to bring the elements in the correct order. For the tree it is necessary that all children are ordered directly after the parent. Your comparator does not respect that.

So you first need to check if both elements have a parent, and compare the parents. If the parents are equal perform the second check for the items themselves. If they have no parent, compare the elements directly.

This way the elements are sorted taking the parents into account. By the way, IMHO sorting by uuid is strange, because a user that looks at the table will never understand how the elements are ordered as the uuid has no logical meaning other than being a unique id.
Re: Issue with Tree grid [message #1242350 is a reply to message #1242318] Sun, 09 February 2014 11:44 Go to previous messageGo to next message
tony hedoux is currently offline tony hedouxFriend
Messages: 19
Registered: May 2012
Junior Member
Re,

Thx for your explanation.

For the order by UUID, it is because I do not need my tree to be ordered. I just need to have a correct tree (aka no doublon, and the tree hierarchy should be correct).

I will go ahead with this and get feedback asap.

Tony
Re: Issue with Tree grid [message #1243056 is a reply to message #1242350] Mon, 10 February 2014 13:06 Go to previous message
tony hedoux is currently offline tony hedouxFriend
Messages: 19
Registered: May 2012
Junior Member
Hi,

I finally solve my problem with this kind of comparator :

  @Override
    public int compare(final EObject pO1, final EObject pO2) {
        int vReturnValue = 0;

        if (pO1 != null && pO2 != null) {
            // First compare parent
            EObject vParent1 = pO1.eContainer();
            EObject vParent2 = pO2.eContainer();

            vReturnValue = compare(vParent1, vParent2);

            // If the parent is the same, compare UUID
            if (vReturnValue == 0) {
                String vUUID1 = ((IAbstractIdentifiedObject) pO1).getUUID();
                String vUUID2 = ((IAbstractIdentifiedObject) pO2).getUUID();

                vReturnValue = vUUID1.compareTo(vUUID2);
            }

        } else if (pO1 == null && pO2 == null) {
            vReturnValue = 0;
        } else if (pO1 == null && pO2 != null) {
            vReturnValue = -1;
        } else if (pO1 != null && pO2 == null) {
            vReturnValue = 1;
        }

        return vReturnValue;
    }



I have to set this comparator in my SortedList constructor, too.

Tony
Previous Topic:Summary Row numbers appear to change 'randomly'
Next Topic:Nattable refresh problem
Goto Forum:
  


Current Time: Fri Aug 23 22:13:33 GMT 2019

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

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

Back to the top