Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [rap-dev] Re: PropertySheetEntries Sorting Order?

Hi Benjamin,

Thank you for your response.

Ok, let me show you this problem with more details.

When cell editor is activated we need to calculate its absolute position inside window and tree.
This method below does calculation and positioning of cell editor's control:

private void applyBoundsToCellEditorControl(TreeItem item, Control control,
            IPropertySheetEntry activeEntry) {

        int x = tree.getBounds().x;
        int y = tree.getBounds().y;
       
        Composite parent = tree.getParent();

        x += parent.getBounds().x;
        y += parent.getBounds().y;

        while (parent.getParent() != null) {

            parent = parent.getParent ();

            x += parent.getBounds().x;
            y += parent.getBounds().y;
        }

        y += tree.getHeaderHeight();

        int i;
        List children = getChildren(rootEntry);
        for (i = 0; i < children.size(); i++) {
            IPropertySheetEntry entry = (IPropertySheetEntry) children.get(i);
            if (entry == activeEntry) {
                break;
            }
        }

        control.setBounds(x + item.getBounds(0).width, y + (i * TABLE_ROW_HEIGHT), item
                .getBounds(1).width, CELLEDITOR_HEIGHT);
 }

The problem surface when we need to get index of selected item. Tree doesn't allow to know index of selected visible item. I need this index to know the factor of multiplication to calculate cell editor's y coordinate.

And due to the fact I can't ask Tree about selected item index - I get the selected item itself and check it on Java back-end side with my List of items which I suppose is displayed within this tree on UI. And my problem is that my list of items on Java side differs for some reason from how this list is displayed on RAP UI side. And this brings problem of incorrect appearance of cell editor.

I temporary solved this problem by adding sorting to TreeItems so I can be sure in which order tree items listed on RAP UI. Here is the piece of code I use to sort TreeItems (from TreeItems.js):

setTexts : function( texts ) {
   
      this._texts = texts;
      if( this.isCreated() ) {
        this.updateItem();
      }
     
      /* Sorting goes here (after all texts are set to consider them while sorting)*/
        var items = this.getParent().getChildren().concat();
   
        function sortFunc(a,b) {
               
            if (a._texts[0] > b._texts[0]) {
                return 1;         
            } else if (a._texts[0] < b._texts[0]) {
                return -1;
            } else {
                return 0;
            }
        }
       
        items.sort(sortFunc);

        for (var i = 0; i < items.length; i++) {
            this.getParent().addAt(items[i], i);
        }
    }

In above piece of code I do extend setTexts method to sort all siblings of current TreeItems after its labels changed. This is required because in TreeItem's constructor labels are not set yet. It happens only after TreeItem object is created.
Maybe this is not very optimized solution - but it is a quick fix to my problem.
And I'd like to make it more general so that we can set sorting to a tree or somehow predict the order of items in which they appear on UI.

Thanks, Alex.

On Jan 12, 2008 7:25 PM, Benjamin Muskalla < bmuskalla@xxxxxxxxxxxxxx> wrote:
Hi Alexey,

really nice to hear what you're doing here. Sounds very promising. What
I don't understand is your "sorting problem". The tree itself does not
have any sorting mechanism (neither in SWT nor in RWT). So I really
wonder what's the problem here. I imagine you're using the getBounds
method of the TreeItem to determinate the location where you place your
celleditors. One known issue there is that the y coordinate is relative
to the tree widget itself and not it's client area. In turn this means
that you need to add the header spacing to the y coordinate
(Tree#getHeaderHeight). If you can show us some sample code to reproduce
the error I'm very interested to help!

Just a sentence about the tree itself: The java fascade which provides
the API is org.eclipse.swt.widgets.Tree. This manages the treeitems and
stuff. In the rendering phase, the TreeLCA class helps to synchronize
the server and client state and the same applies to TreeItemLCA. On the
client side, the Tree.js / TreeItem.js are only wrappers around the
original qooxdoo implementations to enhance them with stuff like tree
headers and proper column handling.

I'm looking forward to see some of your stuff regarding cell editors!

Greets
 Benny

Alexey Litvinuke wrote:
> Hi Everyone!
>
> I've finally introduced sorting of TreeItems in Tree's in order to
> temporary resolve this problem as I asked about in my previous message.
> To get TreeItems sorted by label (text) you need to add code for
> sorting inside TreeItem.js in setTexts() function. This is because you
> need texts set before sorting by them. Hence I do sorting of this
> newly created TreeItem and all its siblings and then apply sorted
> array of items to their parent.
>
> This is kind of hack to get done what I need here. And what would be
> great is to have some mechanism of sorting tree items inside of Tree
> itself as part of API. Thus we can predict in which order items are
> placed in tree and work with it.
>
> I am very concerned to help with tree items sorting and celleditors
> (especially for trees) and can contribute some of the code I have here
> to RAP project. Its very imprortant to me (and to others too, I am
> sure) to have those things included in very close future releases of
> RAP. And this way I don't need to re-merge my changes with new
> releases of RAP anymore ;)
>
> Thank you,
> Alex.
>
>
> On Dec 26, 2007 1:23 PM, Alexey wrote:
>
>     Hi!
>
>     I've faced with a problem of sorting order of PropertySheetEntries
>     in PropertySheet (EMF implementation with Tree object as a Viewer
>     control).
>
>     I am implementing CellEditors and they work fine for me in whole.
>     The ploblem is that I can't control and get the correct order of
>     entries which will occure in PropertySheet.
>     I need the order of entries to get index of selected element in
>     tree (2 column tree) to know where to place my cell editor.
>     Because of my PropertySheetViewer control is Tree - I can't just
>     get selected index but only selected object.
>
>     In most cases order of how entries are displayed by RAP in HTML is
>     equal to what we have in Java in
>     "selectedPropertySheetEntry.getChildEntries ()".
>     But in some cases they don't and only for some elements - and this
>     finaly result with incorrect cell editor placement when I am
>     activating it for selected item.
>
>     Here is an screenshot of what I am talking about:
>
>     http://img205.imageshack.us/my.php?image=propertysheetexamplebz1.gif
>     <http://img205.imageshack.us/my.php?image=propertysheetexamplebz1.gif>
>
>     You can see that in this particular case when I try to edit one
>     property - it opens correct celleditor but in not correct location
>     - because of the differences in order of element I have in Java
>     code (selectedPropertySheetEntry.getChildEntries ()) and the way
>     RAP renders them in HTML.
>
>     Can you suggest something how to avoid this problem?
>     Any links to source code where and how RAP makes this sorting and
>     why it is different from what I see in Java?
>
>     Thank you in advance.
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> rap-dev mailing list
> rap-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/rap-dev
>

_______________________________________________
rap-dev mailing list
rap-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/rap-dev


Back to the top