Hi Robert

The events from the table tree on the right are lost because the JTableTree 
still listens to its original ListSelectionModel. At creation time of a 
JTableTree, the table tree registers itself as a ListSelectionListener to the 
current ListSelectionModel of the underlying table. When a list selection event 
occurs on the underlying table, the event is translated into a 
TreeSelectionEvent and fired.

Maybe the following approach can solve your problems. This approach leaves the 
original ListSelectionModels in place and also uses listeners to synchronize 
the two table tree. Because this is done on the level of the underlying tables, 
however, the visual appearance seems to be fine.

I took the community contribution and adapted it a little.

a) In UIFixedColumnTableTree.restoreState() replace the lines 
        rowHeader.addTreeSelectionListener(new MySelectionListener(viewPort, 
rowHeader));
        viewPort.addTreeSelectionListener(new MySelectionListener(rowHeader, 
viewPort));
   with
        
rowHeader.getBasicTable().getSelectionModel().addListSelectionListener(new 
MyRowSelectionListener(viewPort, rowHeader));
        
viewPort.getBasicTable().getSelectionModel().addListSelectionListener(new 
MyRowSelectionListener(rowHeader, viewPort));

b) Introduce a field on UIFixedColumnTableTree:

    private boolean fSynchronizingSelection = false;

c) Define the synchronizing listeners class as an inner class of 
UIFixedColumnTableTree (instances of this class share the synchronizing flag):

    private class MyRowSelectionListener implements ListSelectionListener {
        private JTableTree fTarget;
        private JTableTree fSource;

        public MyRowSelectionListener(JTableTree target, JTableTree source) {
            fTarget = target;
            fSource = source;
        }

        public void valueChanged(ListSelectionEvent e) {
            if (fSynchronizingSelection) {
                return;
            }

            fSynchronizingSelection = true;
            fTarget.clearSelection();

            int[] selectedRows = fSource.getSelectedRows();
            for (int i = 0; i < selectedRows.length; i++) {
                fTarget.addRowSelectionInterval(selectedRows[i], 
selectedRows[i]);
            }
            fSynchronizingSelection = false;
        }
    }

I did not test this approach thoroughly but it seems to work fine. Let me know 
if this helps!

Cheerio
Rolf


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of ulc rbeeger
Sent: Mittwoch, 28. Juni 2006 16:28
To: [EMAIL PROTECTED]
Subject: [ULC-developer] Problem with selection events in two synchronized 
table trees


Hi!

We have a component that is similar to the fixed column table tree on the code 
community - two table trees side by side with sychronized expansion and 
selection.
We originally synchronized the selections in the two table trees like this:
right.getBasicTableTree().getBasicTable().setSelectionModel(left.getBasicTableTree().getBasicTable().getSelectionModel());

Visually it all works wonderful. The selection spans both table trees and a 
change in the selection is processed in both table trees seamlessly.
The only problem: selections in the right table tree don't trigger any 
selection events on the server side ULCTableTree - neither on the right nor the 
left one.

The code from the code community adds two listeners to the two table trees and 
synchronizes the selection after it happens. While we now get the events for 
selections in both table trees on the server, this solution has an ugly effect: 
The synchronization of the selection is clearly visible. You see that for 
example the selection changes from the first to the third row in the left table 
tree and then you see how it changes in the right table tree. This effect tears 
the two table trees visually apart.
Does anyone have any idea how to ensure events are fired for selections in both 
table trees without the ugly effect.

Thanks in advance,
  RobertP°z÷¥¢—«™¨¥Šx%ŠËT,'^½éh¥êåŠËlq©è¡Ê&†Ûiÿùb²Ûjz(r‰¿™¨¥™©ÿ–+-Šwèþé\uëޖŠ^

Reply via email to