selection support in GL

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

selection support in GL

Ted Zlatanov
It would be very nice if the GL had some knowledge of what's been
selected in a list or table generated from it.  Obviously that's not
always possible, but at least a Matcher should be possible that glues
together the selection control piece of the GUI view with the underlying
model.  Any suggestions?

Ted




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: selection support in GL

James Lemieux
EventSelectionModel does precisely this. If you start using it in place of the traditional selection model you can ask it to furnish you with the selected/unselected elements. Just make sure you pass the same EventList into both your data model and selection model.

James

2009/8/27 Ted Zlatanov <[hidden email]>
It would be very nice if the GL had some knowledge of what's been
selected in a list or table generated from it.  Obviously that's not
always possible, but at least a Matcher should be possible that glues
together the selection control piece of the GUI view with the underlying
model.  Any suggestions?

Ted




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: selection support in GL

Ted Zlatanov
On Thu, 27 Aug 2009 09:38:35 -0700 James Lemieux <[hidden email]> wrote:

JL> 2009/8/27 Ted Zlatanov <[hidden email]>

>> It would be very nice if the GL had some knowledge of what's been
>> selected in a list or table generated from it.  Obviously that's not
>> always possible, but at least a Matcher should be possible that glues
>> together the selection control piece of the GUI view with the underlying
>> model.  Any suggestions?

JL> EventSelectionModel does precisely this. If you start using it in place of
JL> the traditional selection model you can ask it to furnish you with the
JL> selected/unselected elements. Just make sure you pass the same EventList
JL> into both your data model and selection model.

Thanks, I have no idea how I missed this in the code.

Ted


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: selection support in GL

Ted Zlatanov
In reply to this post by James Lemieux
On Thu, 27 Aug 2009 09:38:35 -0700 James Lemieux <[hidden email]> wrote:

JL> 2009/8/27 Ted Zlatanov <[hidden email]>

>> It would be very nice if the GL had some knowledge of what's been
>> selected in a list or table generated from it.  Obviously that's not
>> always possible, but at least a Matcher should be possible that glues
>> together the selection control piece of the GUI view with the underlying
>> model.  Any suggestions?

JL> EventSelectionModel does precisely this. If you start using it in place of
JL> the traditional selection model you can ask it to furnish you with the
JL> selected/unselected elements. Just make sure you pass the same EventList
JL> into both your data model and selection model.

I tried it with a JXTable/JXList and it doesn't work correctly.  I'm
guessing the model to view mappings are confusing it.
JXTable.getSelectionMapper().setEnabled(false) locks up the EDT thread,
so there's some strange interaction there.

Ted


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: selection support in GL

Holger
In reply to this post by Ted Zlatanov
Hi Ted,

there is some info about SwingX and GL here:
http://sites.google.com/site/glazedlists/documentation/swingx

I think there are some users combining SwingX with GL without problems,
so to help you with your problem we need to know:

Which versions of SwingX and GL do you use?

How did you setup your JXTable?

A test program that demonstrates your issue would be ideal.

Thanks,
Holger

> On Thu, 27 Aug 2009 09:38:35 -0700 James Lemieux <[hidden email]> wrote:
>
> JL> 2009/8/27 Ted Zlatanov <[hidden email]>
>
> >> It would be very nice if the GL had some knowledge of what's been
> >> selected in a list or table generated from it.  Obviously that's not
> >> always possible, but at least a Matcher should be possible that glues
> >> together the selection control piece of the GUI view with the underlying
> >> model.  Any suggestions?
>
> JL> EventSelectionModel does precisely this. If you start using it in place of
> JL> the traditional selection model you can ask it to furnish you with the
> JL> selected/unselected elements. Just make sure you pass the same EventList
> JL> into both your data model and selection model.
>
> I tried it with a JXTable/JXList and it doesn't work correctly.  I'm
> guessing the model to view mappings are confusing it.
> JXTable.getSelectionMapper().setEnabled(false) locks up the EDT thread,
> so there's some strange interaction there.
>
> Ted
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: selection support in GL

Ted Zlatanov
On Sat, 29 Aug 2009 12:28:50 +0200 Holger Brands <[hidden email]> wrote:

HB> there is some info about SwingX and GL here:
HB> http://sites.google.com/site/glazedlists/documentation/swingx

First of all, GL is great.  This is just one case where it's been hard
to use.  I would not go back to non-GL programming, it would be painful.

I tried the suggested

                    EventListJXTableSorting sorting = EventListJXTableSorting.install(t, beans);
                    sorting.setMultipleColumnSort(true);

but got many illegal state and null pointer errors, e.g. below.  I also
don't like all the caveats and limitations of the suggested approaches.

java.lang.IllegalStateException: Cannot combine reorder with other change events
        at ca.odell.glazedlists.event.ListEventAssembler.reorder(ListEventAssembler.java:246)
        at ca.odell.glazedlists.ListSelection.addSelectedReorder(ListSelection.java:852)
        at ca.odell.glazedlists.ListSelection.listChanged(ListSelection.java:172)
        at ca.odell.glazedlists.event.ListEventAssembler$ListEventFormat.fire(ListEventAssembler.java:412)
        at ca.odell.glazedlists.event.ListEventAssembler$ListEventFormat.fire(ListEventAssembler.java:409)
        at ca.odell.glazedlists.event.SequenceDependenciesEventPublisher$SubjectAndListener.firePendingEvent(SequenceDependenciesEventPublisher.java:445)
        at ca.odell.glazedlists.event.SequenceDependenciesEventPublisher.fireEvent(SequenceDependenciesEventPublisher.java:344)
        at ca.odell.glazedlists.event.ListEventAssembler.commitEvent(ListEventAssembler.java:316)
        at ca.odell.glazedlists.SortedList.setComparator(SortedList.java:481)
        at ca.odell.glazedlists.swing.EventListJXTableSorting$EventListSortController.setSortKeys(EventListJXTableSorting.java:228)
        at ca.odell.glazedlists.swing.EventListJXTableSorting$EventListSortController.toggleSortOrder(EventListJXTableSorting.java:192)
        at org.jdesktop.swingx.JXTable.toggleSortOrder(JXTable.java:2046)
        at org.jdesktop.swingx.JXTableHeader$HeaderListener.doSort(JXTableHeader.java:608)
        at org.jdesktop.swingx.JXTableHeader$HeaderListener.mouseClicked(JXTableHeader.java:589)
        at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
        at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:252)
        at java.awt.Component.processMouseEvent(Component.java:6266)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
        at java.awt.Component.processEvent(Component.java:6028)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4630)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2475)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
        at java.awt.Dialog$1.run(Dialog.java:1045)
        at java.awt.Dialog$3.run(Dialog.java:1097)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.awt.Dialog.show(Dialog.java:1095)
        at java.awt.Component.show(Component.java:1563)
        at java.awt.Component.setVisible(Component.java:1515)
        at java.awt.Window.setVisible(Window.java:841)
        at java.awt.Dialog.setVisible(Dialog.java:985)
        at com.jump.simple.Out.show(Out.java:851)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

This is the code I tried (see below for version without the EventListJXTableSorting):

        try
        {
            SwingUtilities.invokeAndWait(new Runnable()
            {
                public void run()
                {
                    EventList<JLabel> labels = GlazedLists.eventListOf(new JLabel("a"), new JLabel("b"), new JLabel("c"), new JLabel("d"));
                    ObservableElementList.Connector<JLabel> labelConnector = GlazedLists.beanConnector(JLabel.class);
                    SortedList<JLabel> beans = new SortedList<JLabel>(new ObservableElementList<JLabel>(labels, labelConnector), new Comparator<JLabel>()
                    {
                        public int compare(JLabel o1, JLabel o2)
                        {
                            return o1.getText().compareTo(o2.getText());
                        }
                    });
                    // build a JTable
                    String[] propertyNames = { "text", };
                    TableFormat<JLabel> ltf = GlazedLists.tableFormat(JLabel.class, propertyNames, propertyNames);
                    final JXTable t = new JXTable(new DefaultEventTableModel<JLabel>(beans, ltf));
                    final JLabel view_selected = new JLabel("wrong");
                    final JLabel real_selected = new JLabel("right");
                    DefaultEventSelectionModel<JLabel> selModel = new DefaultEventSelectionModel<JLabel>(beans);
                    t.setSelectionModel(selModel);

                    EventListJXTableSorting sorting = EventListJXTableSorting.install(t, beans);
                    sorting.setMultipleColumnSort(true);

                    t.getSelectionModel().addListSelectionListener(new ListSelectionListener()
                    {
                        public void valueChanged(ListSelectionEvent e)
                        {
                            int[] rows = t.getSelectedRows();
                            int sel = rows.length < 1 ? -1 : rows[0];

                            view_selected.setText("" + sel);
                            real_selected.setText("" + t.convertRowIndexToModel(sel));
                        }
                    });
                    JPanel show = new JPanel(new GridLayout(0, 1));
                    JList selList = new JList(new DefaultEventListModel<JLabel>(selModel.getSelected()));
                    selList.setCellRenderer(new DefaultListCellRenderer()
                    {
                        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
                        {
                            JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                            label.setText(((JLabel) value).getText());
                            return label;
                        }
                    });

                    show.add(new JScrollPane(t));
                    show.add(new JScrollPane(selList));
                    show.add(view_selected);
                    show.add(real_selected);
                    Out.show(800, 600, show);
                }
            });
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }



HB> I think there are some users combining SwingX with GL without problems,
HB> so to help you with your problem we need to know:

HB> Which versions of SwingX and GL do you use?

HB> How did you setup your JXTable?

HB> A test program that demonstrates your issue would be ideal.

Here's a simple example using JLabel lists.  I'm using the latest dev
snapshot of glazed lists and the 1.0 SwingX release.

        EventList<JLabel> labels = GlazedLists.eventListOf(new JLabel("a"), new JLabel("b"), new JLabel("c"), new JLabel("d"));
        ObservableElementList.Connector<JLabel> labelConnector = GlazedLists.beanConnector(JLabel.class);
        ObservableElementList<JLabel> beans = new ObservableElementList<JLabel>(labels, labelConnector);
        // build a JTable
        String[] propertyNames = {"text",};
        TableFormat<JLabel> ltf = GlazedLists.tableFormat(JLabel.class, propertyNames, propertyNames);
        final JXTable t = new JXTable(new DefaultEventTableModel<JLabel>(beans, ltf));
        final JLabel view_selected = new JLabel("wrong");
        final JLabel real_selected = new JLabel("right");
        DefaultEventSelectionModel<JLabel> selModel = new DefaultEventSelectionModel<JLabel>(beans);
        t.setSelectionModel(selModel);

        t.getSelectionModel().addListSelectionListener(new ListSelectionListener()
        {
            public void valueChanged(ListSelectionEvent e)
            {
                int[] rows = t.getSelectedRows();
                int sel = rows.length < 1 ? -1 : rows[0];
               
                view_selected.setText(""+sel);
                real_selected.setText(""+t.convertRowIndexToModel(sel));
            }
        });
        JPanel show = new JPanel(new GridLayout(0, 1));
        JList selList = new JList(new DefaultEventListModel<JLabel>(selModel.getSelected()));
        selList.setCellRenderer(new DefaultListCellRenderer()
        {
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
            {
                JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                label.setText(((JLabel)value).getText());
                return label;
            }
        });

        show.add(new JScrollPane(t));
        show.add(new JScrollPane(selList));
        show.add(view_selected);
        show.add(real_selected);
        // show the JPanel now

When unsorted, everything works.  If you reverse-sort, though, selecting
elements 0 and 1 ("d" and "c") results in the selected list being "a"
and "b" (the view coordinates).  The selection model needs to ask the
table to convert view rows to model rows, basically.  I show this in the
real_selected vs. view_selected labels.  The code has an exception for
-1 (nothing selected) but I didn't want to spend time polishing
irrelevant cases.

My question, then, is: why not modify the DefaultEventSelectionModel to
ask the JXTable for the model coordinates of the selected data?  At the
leat, mention that possibility in the SwingX compatiblity docs.  I think
EventListJXTableSorting is too complicated and limiting for users who
like the JXTable sorting and filtering, plus as I showed it had some
issues (perhaps due to my inexperience using it).

I would also suggest the docs for DefaultEventSelectionModel should
mention the SwingX issues clearly.  If those issues are in the bug list,
point that out next to the bug URL.

Thanks!
Ted


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: selection support in GL

Holger
In reply to this post by Ted Zlatanov
Hi Ted,

in both examples you posted, you use DefaultEventSelectionModel with JXTable,
but I don't see where you disable the selection mapper.
The link I quoted states under section "Maintaining selection":

"It is necessary to disable the SelectionMapper to use JXTable with Glazed Lists.
Otherwise, the SelectionMapper competes with Glazed Lists' own selection management,
and selection is left in an inconsistent state."

Please try that first.
If any problem remains, please let us know.

Thanks,
Holger

> On Sat, 29 Aug 2009 12:28:50 +0200 Holger Brands <[hidden email]> wrote:
>
> HB> there is some info about SwingX and GL here:
> HB> http://sites.google.com/site/glazedlists/documentation/swingx
>
> First of all, GL is great.  This is just one case where it's been hard
> to use.  I would not go back to non-GL programming, it would be painful.
>
> I tried the suggested
>
>                     EventListJXTableSorting sorting = EventListJXTableSorting.install(t, beans);
>                     sorting.setMultipleColumnSort(true);
>
> but got many illegal state and null pointer errors, e.g. below.  I also
> don't like all the caveats and limitations of the suggested approaches.
>
> java.lang.IllegalStateException: Cannot combine reorder with other change events
> at ca.odell.glazedlists.event.ListEventAssembler.reorder(ListEventAssembler.java:246)
> at ca.odell.glazedlists.ListSelection.addSelectedReorder(ListSelection.java:852)
> at ca.odell.glazedlists.ListSelection.listChanged(ListSelection.java:172)
> at ca.odell.glazedlists.event.ListEventAssembler$ListEventFormat.fire(ListEventAssembler.java:412)
> at ca.odell.glazedlists.event.ListEventAssembler$ListEventFormat.fire(ListEventAssembler.java:409)
> at ca.odell.glazedlists.event.SequenceDependenciesEventPublisher$SubjectAndListener.firePendingEvent(SequenceDependenciesEventPublisher.java:445)
> at ca.odell.glazedlists.event.SequenceDependenciesEventPublisher.fireEvent(SequenceDependenciesEventPublisher.java:344)
> at ca.odell.glazedlists.event.ListEventAssembler.commitEvent(ListEventAssembler.java:316)
> at ca.odell.glazedlists.SortedList.setComparator(SortedList.java:481)
> at ca.odell.glazedlists.swing.EventListJXTableSorting$EventListSortController.setSortKeys(EventListJXTableSorting.java:228)
> at ca.odell.glazedlists.swing.EventListJXTableSorting$EventListSortController.toggleSortOrder(EventListJXTableSorting.java:192)
> at org.jdesktop.swingx.JXTable.toggleSortOrder(JXTable.java:2046)
> at org.jdesktop.swingx.JXTableHeader$HeaderListener.doSort(JXTableHeader.java:608)
> at org.jdesktop.swingx.JXTableHeader$HeaderListener.mouseClicked(JXTableHeader.java:589)
> at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
> at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:252)
> at java.awt.Component.processMouseEvent(Component.java:6266)
> at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
> at java.awt.Component.processEvent(Component.java:6028)
> at java.awt.Container.processEvent(Container.java:2041)
> at java.awt.Component.dispatchEventImpl(Component.java:4630)
> at java.awt.Container.dispatchEventImpl(Container.java:2099)
> at java.awt.Component.dispatchEvent(Component.java:4460)
> at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
> at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
> at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
> at java.awt.Container.dispatchEventImpl(Container.java:2085)
> at java.awt.Window.dispatchEventImpl(Window.java:2475)
> at java.awt.Component.dispatchEvent(Component.java:4460)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
> at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
> at java.awt.Dialog$1.run(Dialog.java:1045)
> at java.awt.Dialog$3.run(Dialog.java:1097)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.awt.Dialog.show(Dialog.java:1095)
> at java.awt.Component.show(Component.java:1563)
> at java.awt.Component.setVisible(Component.java:1515)
> at java.awt.Window.setVisible(Window.java:841)
> at java.awt.Dialog.setVisible(Dialog.java:985)
> at com.jump.simple.Out.show(Out.java:851)
> at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
> at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
>
> This is the code I tried (see below for version without the EventListJXTableSorting):
>
>         try
>         {
>             SwingUtilities.invokeAndWait(new Runnable()
>             {
>                 public void run()
>                 {
>                     EventList<JLabel> labels = GlazedLists.eventListOf(new JLabel("a"), new JLabel("b"), new JLabel("c"), new JLabel("d"));
>                     ObservableElementList.Connector<JLabel> labelConnector = GlazedLists.beanConnector(JLabel.class);
>                     SortedList<JLabel> beans = new SortedList<JLabel>(new ObservableElementList<JLabel>(labels, labelConnector), new Comparator<JLabel>()
>                     {
>                         public int compare(JLabel o1, JLabel o2)
>                         {
>                             return o1.getText().compareTo(o2.getText());
>                         }
>                     });
>                     // build a JTable
>                     String[] propertyNames = { "text", };
>                     TableFormat<JLabel> ltf = GlazedLists.tableFormat(JLabel.class, propertyNames, propertyNames);
>                     final JXTable t = new JXTable(new DefaultEventTableModel<JLabel>(beans, ltf));
>                     final JLabel view_selected = new JLabel("wrong");
>                     final JLabel real_selected = new JLabel("right");
>                     DefaultEventSelectionModel<JLabel> selModel = new DefaultEventSelectionModel<JLabel>(beans);
>                     t.setSelectionModel(selModel);
>
>                     EventListJXTableSorting sorting = EventListJXTableSorting.install(t, beans);
>                     sorting.setMultipleColumnSort(true);
>
>                     t.getSelectionModel().addListSelectionListener(new ListSelectionListener()
>                     {
>                         public void valueChanged(ListSelectionEvent e)
>                         {
>                             int[] rows = t.getSelectedRows();
>                             int sel = rows.length < 1 ? -1 : rows[0];
>
>                             view_selected.setText("" + sel);
>                             real_selected.setText("" + t.convertRowIndexToModel(sel));
>                         }
>                     });
>                     JPanel show = new JPanel(new GridLayout(0, 1));
>                     JList selList = new JList(new DefaultEventListModel<JLabel>(selModel.getSelected()));
>                     selList.setCellRenderer(new DefaultListCellRenderer()
>                     {
>                         public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
>                         {
>                             JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
>                             label.setText(((JLabel) value).getText());
>                             return label;
>                         }
>                     });
>
>                     show.add(new JScrollPane(t));
>                     show.add(new JScrollPane(selList));
>                     show.add(view_selected);
>                     show.add(real_selected);
>                     Out.show(800, 600, show);
>                 }
>             });
>         }
>         catch (Exception e)
>         {
>             e.printStackTrace();
>         }
>
>
>
> HB> I think there are some users combining SwingX with GL without problems,
> HB> so to help you with your problem we need to know:
>
> HB> Which versions of SwingX and GL do you use?
>
> HB> How did you setup your JXTable?
>
> HB> A test program that demonstrates your issue would be ideal.
>
> Here's a simple example using JLabel lists.  I'm using the latest dev
> snapshot of glazed lists and the 1.0 SwingX release.
>
>         EventList<JLabel> labels = GlazedLists.eventListOf(new JLabel("a"), new JLabel("b"), new JLabel("c"), new JLabel("d"));
>         ObservableElementList.Connector<JLabel> labelConnector = GlazedLists.beanConnector(JLabel.class);
>         ObservableElementList<JLabel> beans = new ObservableElementList<JLabel>(labels, labelConnector);
>         // build a JTable
>         String[] propertyNames = {"text",};
>         TableFormat<JLabel> ltf = GlazedLists.tableFormat(JLabel.class, propertyNames, propertyNames);
>         final JXTable t = new JXTable(new DefaultEventTableModel<JLabel>(beans, ltf));
>         final JLabel view_selected = new JLabel("wrong");
>         final JLabel real_selected = new JLabel("right");
>         DefaultEventSelectionModel<JLabel> selModel = new DefaultEventSelectionModel<JLabel>(beans);
>         t.setSelectionModel(selModel);
>
>         t.getSelectionModel().addListSelectionListener(new ListSelectionListener()
>         {
>             public void valueChanged(ListSelectionEvent e)
>             {
>                 int[] rows = t.getSelectedRows();
>                 int sel = rows.length < 1 ? -1 : rows[0];
>                
>                 view_selected.setText(""+sel);
>                 real_selected.setText(""+t.convertRowIndexToModel(sel));
>             }
>         });
>         JPanel show = new JPanel(new GridLayout(0, 1));
>         JList selList = new JList(new DefaultEventListModel<JLabel>(selModel.getSelected()));
>         selList.setCellRenderer(new DefaultListCellRenderer()
>         {
>             public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
>             {
>                 JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
>                 label.setText(((JLabel)value).getText());
>                 return label;
>             }
>         });
>
>         show.add(new JScrollPane(t));
>         show.add(new JScrollPane(selList));
>         show.add(view_selected);
>         show.add(real_selected);
>         // show the JPanel now
>
> When unsorted, everything works.  If you reverse-sort, though, selecting
> elements 0 and 1 ("d" and "c") results in the selected list being "a"
> and "b" (the view coordinates).  The selection model needs to ask the
> table to convert view rows to model rows, basically.  I show this in the
> real_selected vs. view_selected labels.  The code has an exception for
> -1 (nothing selected) but I didn't want to spend time polishing
> irrelevant cases.
>
> My question, then, is: why not modify the DefaultEventSelectionModel to
> ask the JXTable for the model coordinates of the selected data?  At the
> leat, mention that possibility in the SwingX compatiblity docs.  I think
> EventListJXTableSorting is too complicated and limiting for users who
> like the JXTable sorting and filtering, plus as I showed it had some
> issues (perhaps due to my inexperience using it).
>
> I would also suggest the docs for DefaultEventSelectionModel should
> mention the SwingX issues clearly.  If those issues are in the bug list,
> point that out next to the bug URL.
>
> Thanks!
> Ted
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: selection support in GL

Ted Zlatanov
On Tue, 01 Sep 2009 21:34:18 +0200 Holger Brands <[hidden email]> wrote:

HB> Hi Ted,
HB> in both examples you posted, you use DefaultEventSelectionModel with JXTable,
HB> but I don't see where you disable the selection mapper.
HB> The link I quoted states under section "Maintaining selection":

HB> "It is necessary to disable the SelectionMapper to use JXTable with Glazed Lists.
HB> Otherwise, the SelectionMapper competes with Glazed Lists' own selection management,
HB> and selection is left in an inconsistent state."

As I mentioned in my earlier post, disabling the selection mapper locks
the EDT.  I can research further if you need me to--does it work for
you?

Also I don't see why the selection mapper has to be disabled--my whole
point below the example was that I'd like to use the JXTable facilities
to sort and filter, instead of layering SortedList and FilterList
adapters.  There should be a simple way to do that with the stock
DefaultEventSelectionModel, converting every index to the model index.
If not I can write my own version I guess, but I was hoping to avoid
that.

Ted

>> On Sat, 29 Aug 2009 12:28:50 +0200 Holger Brands <[hidden email]> wrote:
>>
HB> there is some info about SwingX and GL here:
HB> http://sites.google.com/site/glazedlists/documentation/swingx

>>
>> First of all, GL is great.  This is just one case where it's been hard
>> to use.  I would not go back to non-GL programming, it would be painful.
>>
>> I tried the suggested
>>
>> EventListJXTableSorting sorting = EventListJXTableSorting.install(t, beans);
>> sorting.setMultipleColumnSort(true);
>>
>> but got many illegal state and null pointer errors, e.g. below.  I also
>> don't like all the caveats and limitations of the suggested approaches.
>>
>> java.lang.IllegalStateException: Cannot combine reorder with other change events
>> at ca.odell.glazedlists.event.ListEventAssembler.reorder(ListEventAssembler.java:246)
>> at ca.odell.glazedlists.ListSelection.addSelectedReorder(ListSelection.java:852)
>> at ca.odell.glazedlists.ListSelection.listChanged(ListSelection.java:172)
>> at ca.odell.glazedlists.event.ListEventAssembler$ListEventFormat.fire(ListEventAssembler.java:412)
>> at ca.odell.glazedlists.event.ListEventAssembler$ListEventFormat.fire(ListEventAssembler.java:409)
>> at ca.odell.glazedlists.event.SequenceDependenciesEventPublisher$SubjectAndListener.firePendingEvent(SequenceDependenciesEventPublisher.java:445)
>> at ca.odell.glazedlists.event.SequenceDependenciesEventPublisher.fireEvent(SequenceDependenciesEventPublisher.java:344)
>> at ca.odell.glazedlists.event.ListEventAssembler.commitEvent(ListEventAssembler.java:316)
>> at ca.odell.glazedlists.SortedList.setComparator(SortedList.java:481)
>> at ca.odell.glazedlists.swing.EventListJXTableSorting$EventListSortController.setSortKeys(EventListJXTableSorting.java:228)
>> at ca.odell.glazedlists.swing.EventListJXTableSorting$EventListSortController.toggleSortOrder(EventListJXTableSorting.java:192)
>> at org.jdesktop.swingx.JXTable.toggleSortOrder(JXTable.java:2046)
>> at org.jdesktop.swingx.JXTableHeader$HeaderListener.doSort(JXTableHeader.java:608)
>> at org.jdesktop.swingx.JXTableHeader$HeaderListener.mouseClicked(JXTableHeader.java:589)
>> at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
>> at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:252)
>> at java.awt.Component.processMouseEvent(Component.java:6266)
>> at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
>> at java.awt.Component.processEvent(Component.java:6028)
>> at java.awt.Container.processEvent(Container.java:2041)
>> at java.awt.Component.dispatchEventImpl(Component.java:4630)
>> at java.awt.Container.dispatchEventImpl(Container.java:2099)
>> at java.awt.Component.dispatchEvent(Component.java:4460)
>> at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
>> at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
>> at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
>> at java.awt.Container.dispatchEventImpl(Container.java:2085)
>> at java.awt.Window.dispatchEventImpl(Window.java:2475)
>> at java.awt.Component.dispatchEvent(Component.java:4460)
>> at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
>> at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
>> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
>> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
>> at java.awt.Dialog$1.run(Dialog.java:1045)
>> at java.awt.Dialog$3.run(Dialog.java:1097)
>> at java.security.AccessController.doPrivileged(Native Method)
>> at java.awt.Dialog.show(Dialog.java:1095)
>> at java.awt.Component.show(Component.java:1563)
>> at java.awt.Component.setVisible(Component.java:1515)
>> at java.awt.Window.setVisible(Window.java:841)
>> at java.awt.Dialog.setVisible(Dialog.java:985)
>> at com.jump.simple.Out.show(Out.java:851)
>> at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
>> at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
>> at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
>> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
>> at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
>> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
>> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
>> at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
>>
>> This is the code I tried (see below for version without the EventListJXTableSorting):
>>
>> try
>> {
>> SwingUtilities.invokeAndWait(new Runnable()
>> {
>> public void run()
>> {
>> EventList<JLabel> labels = GlazedLists.eventListOf(new JLabel("a"), new JLabel("b"), new JLabel("c"), new JLabel("d"));
>> ObservableElementList.Connector<JLabel> labelConnector = GlazedLists.beanConnector(JLabel.class);
>> SortedList<JLabel> beans = new SortedList<JLabel>(new ObservableElementList<JLabel>(labels, labelConnector), new Comparator<JLabel>()
>> {
>> public int compare(JLabel o1, JLabel o2)
>> {
>> return o1.getText().compareTo(o2.getText());
>> }
>> });
>> // build a JTable
>> String[] propertyNames = { "text", };
>> TableFormat<JLabel> ltf = GlazedLists.tableFormat(JLabel.class, propertyNames, propertyNames);
>> final JXTable t = new JXTable(new DefaultEventTableModel<JLabel>(beans, ltf));
>> final JLabel view_selected = new JLabel("wrong");
>> final JLabel real_selected = new JLabel("right");
>> DefaultEventSelectionModel<JLabel> selModel = new DefaultEventSelectionModel<JLabel>(beans);
>> t.setSelectionModel(selModel);
>>
>> EventListJXTableSorting sorting = EventListJXTableSorting.install(t, beans);
>> sorting.setMultipleColumnSort(true);
>>
>> t.getSelectionModel().addListSelectionListener(new ListSelectionListener()
>> {
>> public void valueChanged(ListSelectionEvent e)
>> {
>> int[] rows = t.getSelectedRows();
>> int sel = rows.length < 1 ? -1 : rows[0];
>>
>> view_selected.setText("" + sel);
>> real_selected.setText("" + t.convertRowIndexToModel(sel));
>> }
>> });
>> JPanel show = new JPanel(new GridLayout(0, 1));
>> JList selList = new JList(new DefaultEventListModel<JLabel>(selModel.getSelected()));
>> selList.setCellRenderer(new DefaultListCellRenderer()
>> {
>> public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
>> {
>> JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
>> label.setText(((JLabel) value).getText());
>> return label;
>> }
>> });
>>
>> show.add(new JScrollPane(t));
>> show.add(new JScrollPane(selList));
>> show.add(view_selected);
>> show.add(real_selected);
>> Out.show(800, 600, show);
>> }
>> });
>> }
>> catch (Exception e)
>> {
>> e.printStackTrace();
>> }
>>
>>
>>
HB> I think there are some users combining SwingX with GL without problems,
HB> so to help you with your problem we need to know:
>>
HB> Which versions of SwingX and GL do you use?
>>
HB> How did you setup your JXTable?
>>
HB> A test program that demonstrates your issue would be ideal.

>>
>> Here's a simple example using JLabel lists.  I'm using the latest dev
>> snapshot of glazed lists and the 1.0 SwingX release.
>>
>> EventList<JLabel> labels = GlazedLists.eventListOf(new JLabel("a"), new JLabel("b"), new JLabel("c"), new JLabel("d"));
>> ObservableElementList.Connector<JLabel> labelConnector = GlazedLists.beanConnector(JLabel.class);
>> ObservableElementList<JLabel> beans = new ObservableElementList<JLabel>(labels, labelConnector);
>> // build a JTable
>> String[] propertyNames = {"text",};
>> TableFormat<JLabel> ltf = GlazedLists.tableFormat(JLabel.class, propertyNames, propertyNames);
>> final JXTable t = new JXTable(new DefaultEventTableModel<JLabel>(beans, ltf));
>> final JLabel view_selected = new JLabel("wrong");
>> final JLabel real_selected = new JLabel("right");
>> DefaultEventSelectionModel<JLabel> selModel = new DefaultEventSelectionModel<JLabel>(beans);
>> t.setSelectionModel(selModel);
>>
>> t.getSelectionModel().addListSelectionListener(new ListSelectionListener()
>> {
>> public void valueChanged(ListSelectionEvent e)
>> {
>> int[] rows = t.getSelectedRows();
>> int sel = rows.length < 1 ? -1 : rows[0];
>>
>> view_selected.setText(""+sel);
>> real_selected.setText(""+t.convertRowIndexToModel(sel));
>> }
>> });
>> JPanel show = new JPanel(new GridLayout(0, 1));
>> JList selList = new JList(new DefaultEventListModel<JLabel>(selModel.getSelected()));
>> selList.setCellRenderer(new DefaultListCellRenderer()
>> {
>> public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
>> {
>> JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
>> label.setText(((JLabel)value).getText());
>> return label;
>> }
>> });
>>
>> show.add(new JScrollPane(t));
>> show.add(new JScrollPane(selList));
>> show.add(view_selected);
>> show.add(real_selected);
>> // show the JPanel now
>>
>> When unsorted, everything works.  If you reverse-sort, though, selecting
>> elements 0 and 1 ("d" and "c") results in the selected list being "a"
>> and "b" (the view coordinates).  The selection model needs to ask the
>> table to convert view rows to model rows, basically.  I show this in the
>> real_selected vs. view_selected labels.  The code has an exception for
>> -1 (nothing selected) but I didn't want to spend time polishing
>> irrelevant cases.
>>
>> My question, then, is: why not modify the DefaultEventSelectionModel to
>> ask the JXTable for the model coordinates of the selected data?  At the
>> leat, mention that possibility in the SwingX compatiblity docs.  I think
>> EventListJXTableSorting is too complicated and limiting for users who
>> like the JXTable sorting and filtering, plus as I showed it had some
>> issues (perhaps due to my inexperience using it).
>>
>> I would also suggest the docs for DefaultEventSelectionModel should
>> mention the SwingX issues clearly.  If those issues are in the bug list,
>> point that out next to the bug URL.
>>
>> Thanks!
>> Ted
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>


HB> ______________________________________________________
HB> GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
HB> Jetzt freischalten unter http://movieflat.web.de

--


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: selection support in GL

Endre Stølsvik-8
Just a quick note on JXTable: I thought they currently were in the process of completely ripping out all their sorting and filtering, and building it up again with JDK 6 stuff for the next version (and possible inclusion in Java 7 or how that was again..)? Just a heads-up if you weren't aware of it - and if I'm right.

Endre.

2009/9/1 Ted Zlatanov <[hidden email]>
On Tue, 01 Sep 2009 21:34:18 +0200 Holger Brands <[hidden email]> wrote:

HB> Hi Ted,
HB> in both examples you posted, you use DefaultEventSelectionModel with JXTable,
HB> but I don't see where you disable the selection mapper.
HB> The link I quoted states under section "Maintaining selection":

HB> "It is necessary to disable the SelectionMapper to use JXTable with Glazed Lists.
HB> Otherwise, the SelectionMapper competes with Glazed Lists' own selection management,
HB> and selection is left in an inconsistent state."

As I mentioned in my earlier post, disabling the selection mapper locks
the EDT.  I can research further if you need me to--does it work for
you?

Also I don't see why the selection mapper has to be disabled--my whole
point below the example was that I'd like to use the JXTable facilities
to sort and filter, instead of layering SortedList and FilterList
adapters.  There should be a simple way to do that with the stock
DefaultEventSelectionModel, converting every index to the model index.
If not I can write my own version I guess, but I was hoping to avoid
that.

Ted

>> On Sat, 29 Aug 2009 12:28:50 +0200 Holger Brands <[hidden email]> wrote:
>>
HB> there is some info about SwingX and GL here:
HB> http://sites.google.com/site/glazedlists/documentation/swingx
>>
>> First of all, GL is great.  This is just one case where it's been hard
>> to use.  I would not go back to non-GL programming, it would be painful.
>>
>> I tried the suggested
>>
>> EventListJXTableSorting sorting = EventListJXTableSorting.install(t, beans);
>> sorting.setMultipleColumnSort(true);
>>
>> but got many illegal state and null pointer errors, e.g. below.  I also
>> don't like all the caveats and limitations of the suggested approaches.
>>
>> java.lang.IllegalStateException: Cannot combine reorder with other change events
>> at ca.odell.glazedlists.event.ListEventAssembler.reorder(ListEventAssembler.java:246)
>> at ca.odell.glazedlists.ListSelection.addSelectedReorder(ListSelection.java:852)
>> at ca.odell.glazedlists.ListSelection.listChanged(ListSelection.java:172)
>> at ca.odell.glazedlists.event.ListEventAssembler$ListEventFormat.fire(ListEventAssembler.java:412)
>> at ca.odell.glazedlists.event.ListEventAssembler$ListEventFormat.fire(ListEventAssembler.java:409)
>> at ca.odell.glazedlists.event.SequenceDependenciesEventPublisher$SubjectAndListener.firePendingEvent(SequenceDependenciesEventPublisher.java:445)
>> at ca.odell.glazedlists.event.SequenceDependenciesEventPublisher.fireEvent(SequenceDependenciesEventPublisher.java:344)
>> at ca.odell.glazedlists.event.ListEventAssembler.commitEvent(ListEventAssembler.java:316)
>> at ca.odell.glazedlists.SortedList.setComparator(SortedList.java:481)
>> at ca.odell.glazedlists.swing.EventListJXTableSorting$EventListSortController.setSortKeys(EventListJXTableSorting.java:228)
>> at ca.odell.glazedlists.swing.EventListJXTableSorting$EventListSortController.toggleSortOrder(EventListJXTableSorting.java:192)
>> at org.jdesktop.swingx.JXTable.toggleSortOrder(JXTable.java:2046)
>> at org.jdesktop.swingx.JXTableHeader$HeaderListener.doSort(JXTableHeader.java:608)
>> at org.jdesktop.swingx.JXTableHeader$HeaderListener.mouseClicked(JXTableHeader.java:589)
>> at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
>> at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:252)
>> at java.awt.Component.processMouseEvent(Component.java:6266)
>> at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
>> at java.awt.Component.processEvent(Component.java:6028)
>> at java.awt.Container.processEvent(Container.java:2041)
>> at java.awt.Component.dispatchEventImpl(Component.java:4630)
>> at java.awt.Container.dispatchEventImpl(Container.java:2099)
>> at java.awt.Component.dispatchEvent(Component.java:4460)
>> at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
>> at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
>> at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
>> at java.awt.Container.dispatchEventImpl(Container.java:2085)
>> at java.awt.Window.dispatchEventImpl(Window.java:2475)
>> at java.awt.Component.dispatchEvent(Component.java:4460)
>> at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
>> at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
>> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
>> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
>> at java.awt.Dialog$1.run(Dialog.java:1045)
>> at java.awt.Dialog$3.run(Dialog.java:1097)
>> at java.security.AccessController.doPrivileged(Native Method)
>> at java.awt.Dialog.show(Dialog.java:1095)
>> at java.awt.Component.show(Component.java:1563)
>> at java.awt.Component.setVisible(Component.java:1515)
>> at java.awt.Window.setVisible(Window.java:841)
>> at java.awt.Dialog.setVisible(Dialog.java:985)
>> at com.jump.simple.Out.show(Out.java:851)
>> at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
>> at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
>> at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
>> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
>> at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
>> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
>> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
>> at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
>>
>> This is the code I tried (see below for version without the EventListJXTableSorting):
>>
>> try
>> {
>> SwingUtilities.invokeAndWait(new Runnable()
>> {
>> public void run()
>> {
>> EventList<JLabel> labels = GlazedLists.eventListOf(new JLabel("a"), new JLabel("b"), new JLabel("c"), new JLabel("d"));
>> ObservableElementList.Connector<JLabel> labelConnector = GlazedLists.beanConnector(JLabel.class);
>> SortedList<JLabel> beans = new SortedList<JLabel>(new ObservableElementList<JLabel>(labels, labelConnector), new Comparator<JLabel>()
>> {
>> public int compare(JLabel o1, JLabel o2)
>> {
>> return o1.getText().compareTo(o2.getText());
>> }
>> });
>> // build a JTable
>> String[] propertyNames = { "text", };
>> TableFormat<JLabel> ltf = GlazedLists.tableFormat(JLabel.class, propertyNames, propertyNames);
>> final JXTable t = new JXTable(new DefaultEventTableModel<JLabel>(beans, ltf));
>> final JLabel view_selected = new JLabel("wrong");
>> final JLabel real_selected = new JLabel("right");
>> DefaultEventSelectionModel<JLabel> selModel = new DefaultEventSelectionModel<JLabel>(beans);
>> t.setSelectionModel(selModel);
>>
>> EventListJXTableSorting sorting = EventListJXTableSorting.install(t, beans);
>> sorting.setMultipleColumnSort(true);
>>
>> t.getSelectionModel().addListSelectionListener(new ListSelectionListener()
>> {
>> public void valueChanged(ListSelectionEvent e)
>> {
>> int[] rows = t.getSelectedRows();
>> int sel = rows.length < 1 ? -1 : rows[0];
>>
>> view_selected.setText("" + sel);
>> real_selected.setText("" + t.convertRowIndexToModel(sel));
>> }
>> });
>> JPanel show = new JPanel(new GridLayout(0, 1));
>> JList selList = new JList(new DefaultEventListModel<JLabel>(selModel.getSelected()));
>> selList.setCellRenderer(new DefaultListCellRenderer()
>> {
>> public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
>> {
>> JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
>> label.setText(((JLabel) value).getText());
>> return label;
>> }
>> });
>>
>> show.add(new JScrollPane(t));
>> show.add(new JScrollPane(selList));
>> show.add(view_selected);
>> show.add(real_selected);
>> Out.show(800, 600, show);
>> }
>> });
>> }
>> catch (Exception e)
>> {
>> e.printStackTrace();
>> }
>>
>>
>>
HB> I think there are some users combining SwingX with GL without problems,
HB> so to help you with your problem we need to know:
>>
HB> Which versions of SwingX and GL do you use?
>>
HB> How did you setup your JXTable?
>>
HB> A test program that demonstrates your issue would be ideal.
>>
>> Here's a simple example using JLabel lists.  I'm using the latest dev
>> snapshot of glazed lists and the 1.0 SwingX release.
>>
>> EventList<JLabel> labels = GlazedLists.eventListOf(new JLabel("a"), new JLabel("b"), new JLabel("c"), new JLabel("d"));
>> ObservableElementList.Connector<JLabel> labelConnector = GlazedLists.beanConnector(JLabel.class);
>> ObservableElementList<JLabel> beans = new ObservableElementList<JLabel>(labels, labelConnector);
>> // build a JTable
>> String[] propertyNames = {"text",};
>> TableFormat<JLabel> ltf = GlazedLists.tableFormat(JLabel.class, propertyNames, propertyNames);
>> final JXTable t = new JXTable(new DefaultEventTableModel<JLabel>(beans, ltf));
>> final JLabel view_selected = new JLabel("wrong");
>> final JLabel real_selected = new JLabel("right");
>> DefaultEventSelectionModel<JLabel> selModel = new DefaultEventSelectionModel<JLabel>(beans);
>> t.setSelectionModel(selModel);
>>
>> t.getSelectionModel().addListSelectionListener(new ListSelectionListener()
>> {
>> public void valueChanged(ListSelectionEvent e)
>> {
>> int[] rows = t.getSelectedRows();
>> int sel = rows.length < 1 ? -1 : rows[0];
>>
>> view_selected.setText(""+sel);
>> real_selected.setText(""+t.convertRowIndexToModel(sel));
>> }
>> });
>> JPanel show = new JPanel(new GridLayout(0, 1));
>> JList selList = new JList(new DefaultEventListModel<JLabel>(selModel.getSelected()));
>> selList.setCellRenderer(new DefaultListCellRenderer()
>> {
>> public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
>> {
>> JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
>> label.setText(((JLabel)value).getText());
>> return label;
>> }
>> });
>>
>> show.add(new JScrollPane(t));
>> show.add(new JScrollPane(selList));
>> show.add(view_selected);
>> show.add(real_selected);
>> // show the JPanel now
>>
>> When unsorted, everything works.  If you reverse-sort, though, selecting
>> elements 0 and 1 ("d" and "c") results in the selected list being "a"
>> and "b" (the view coordinates).  The selection model needs to ask the
>> table to convert view rows to model rows, basically.  I show this in the
>> real_selected vs. view_selected labels.  The code has an exception for
>> -1 (nothing selected) but I didn't want to spend time polishing
>> irrelevant cases.
>>
>> My question, then, is: why not modify the DefaultEventSelectionModel to
>> ask the JXTable for the model coordinates of the selected data?  At the
>> leat, mention that possibility in the SwingX compatiblity docs.  I think
>> EventListJXTableSorting is too complicated and limiting for users who
>> like the JXTable sorting and filtering, plus as I showed it had some
>> issues (perhaps due to my inexperience using it).
>>
>> I would also suggest the docs for DefaultEventSelectionModel should
>> mention the SwingX issues clearly.  If those issues are in the bug list,
>> point that out next to the bug URL.
>>
>> Thanks!
>> Ted
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>


HB> ______________________________________________________
HB> GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
HB> Jetzt freischalten unter http://movieflat.web.de

--


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: selection support in GL

Ted Zlatanov
On Wed, 2 Sep 2009 13:15:17 +0200 Endre Stølsvik <[hidden email]> wrote:

ES> Just a quick note on JXTable: I thought they currently were in the process
ES> of completely ripping out all their sorting and filtering, and building it
ES> up again with JDK 6 stuff for the next version (and possible inclusion in
ES> Java 7 or how that was again..)? Just a heads-up if you weren't aware of it
ES> - and if I'm right.

Yeah, all of SwingX is in limbo after the 1.0 release and they are
planning to synchronize with JDK 6.  I had a few exchanges with the
SwingX developers
(e.g. http://forums.java.net/jive/thread.jspa?messageID=352381) and it
looks like these rewrites are far in the future.

I think all of Java is going to be in a transition for a bit with the
Oracle purchase and the Java team may discover new priorities, so for
now the best direction seems to be to work with the existing libraries.

Ted


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: selection support in GL

Holger
In reply to this post by Ted Zlatanov
Hey Ted,

what I was trying to say was, that the only supported approaches
for integrating GL with SwingX are the ones listed on the wiki page.

You're free to try something different, but you can't expect it to work
out of the box ;-)

>
> As I mentioned in my earlier post, disabling the selection mapper locks
> the EDT.  I can research further if you need me to--does it work for
> you?

What do you mean by "disabling the selection mapper locks the EDT"?
Does the call to table.getSelectionMapper().setEnabled(false) block
or what behaviour do you see?

I tried your (modified) two examples on Windows XP with JDK 1.5u7 and 1.6u11
with SwingX 1.0 and the latest GL build without problems.

In the first example, I only added the call to
table.getSelectionMapper().setEnabled(false)
I modified the second example to use the TableComparatorChooser approach.

If you could provide an executable example with instructions on how to
reproduce the issue, we'd be happy to have a look at it.
(But I have access to a Windows box only)

> Also I don't see why the selection mapper has to be disabled--my whole
> point below the example was that I'd like to use the JXTable facilities
> to sort and filter, instead of layering SortedList and FilterList
> adapters.  There should be a simple way to do that with the stock
> DefaultEventSelectionModel, converting every index to the model index.
> If not I can write my own version I guess, but I was hoping to avoid
> that.

Jesse is the author of the SwingX extension.
I think he knows best why things work this way currently.
But if you find a more elegant solution, we'd of course be interested ;-)

Holger

________________________________________________________________
Neu: WEB.DE Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://produkte.web.de/go/02/


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: selection support in GL

Ted Zlatanov
On Wed, 02 Sep 2009 20:22:57 +0200 Holger Brands <[hidden email]> wrote:

HB> What do you mean by "disabling the selection mapper locks the EDT"?
HB> Does the call to table.getSelectionMapper().setEnabled(false) block
HB> or what behaviour do you see?

It blocked the EDT, application never comes up.  I can't replicate it
anymore; I tried several times, hence the delay in responding.  I'll
write back if I see the EDT block again.

Ted

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]