Bug 183943 - Different events in table if the items are added before open() is invoked and after
Summary: Different events in table if the items are added before open() is invoked and...
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-25 04:48 EDT by Dominik Riedweg CLA
Modified: 2019-09-06 15:33 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dominik Riedweg CLA 2007-04-25 04:48:17 EDT
I need a listener for the horizontal scrollbar of a table. This listener does not receive the selection events if the scrolling is done by the arrow key (Bug?). Instead the table receives a selection event.

But the table does not receive this event if the items are added after the table is opened and none of the items is selected. 

Example: Run the Snippet and press the arrow-right key. The table will scroll but no selection event is fired. Insert the item before the table is openend and the event is fired.

public class Snippet
{

   public static void main (String[] args)
   {
      Display display = new Display();
      Shell shell = new Shell(display);
      shell.setLayout(new GridLayout());
      Table table = new Table(shell, SWT.BORDER | SWT.MULTI);

      table.setLinesVisible(true);
      TableColumn col = new TableColumn(table, SWT.NONE);
      col.setWidth(250);
      TableColumn col2 = new TableColumn(table, SWT.NONE);
      col2.setWidth(250);
      table.setHeaderVisible(true);
      table.setLayoutData(new GridData(100, 100));

      // Selection, DefaultSelection, SetData, MeasureItem, EraseItem, PaintItem 
      table.addListener(SWT.Selection, new ListenerImpl("Selection", "table"));
      table.addListener(SWT.DefaultSelection, new ListenerImpl("DefaultSelection", "table"));
      table.addListener(SWT.SetData, new ListenerImpl("SetData", "table"));
      table.addListener(SWT.MeasureItem, new ListenerImpl("Measure", "table"));
      table.addListener(SWT.EraseItem, new ListenerImpl("Erase", "table"));
      table.addListener(SWT.PaintItem, new ListenerImpl("Paint", "table"));
      table.getHorizontalBar().addListener(SWT.Selection, new ListenerImpl("Selection", "scrollbar"));
      shell.pack();
      shell.open(); // Bug
      for (int i = 0; i < 128; i++)
      {
         TableItem item = new TableItem(table, SWT.NONE);
         item.setText("Item                           " + i);
      }
      //      shell.open(); // NO-Bug
      while (!shell.isDisposed())
      {
         if (!display.readAndDispatch())
            display.sleep();
      }
      display.dispose();
   }

   private static class ListenerImpl
      implements Listener
   {

      private final String event;

      private final String widget;

      ListenerImpl (String event, String widget)
      {
         this.event = event;
         this.widget = widget;

      }
      public void handleEvent (Event event)
      {

         System.out.println(widget + " " + this.event + " " + event);
      }
   };
}
Comment 1 Steve Northover CLA 2007-05-16 19:48:12 EDT
I'm afraid I don't see the problem/understand.  Can you give me steps and show me the output of the bad case and the output of the good case?  Thanks.

NOTE: Please try this against Eclipse 3.3 HEAD first to see whether the bug has already been fixed.
Comment 2 Dominik Riedweg CLA 2008-03-11 07:58:25 EDT
I still have this problem with 3.3.1.1 and 3.4M5. Windows XP

More precisely, I try to layout a widget on top of the columns. The layout is triggered by the selection event of the table and the selection event of the scrollbar. 

But if the table is shown before the items are inserted and right key is pressed (after the items are inserted) I get neither a selection on the table or on the scrollbar. But table scrolls. 

Output:
Several times
table Measure Event {type=41 Table {} time=70854328 data=null x=241 y=423 width=0 height=13 detail=0}
table Erase Event {type=40 Table {} time=70854328 data=null x=241 y=423 width=249 height=13 detail=16}
table Paint Event {type=42 Table {} time=70854328 data=null x=241 y=423 width=0 height=13 detail=16}
…

If the items are inserted before the table is shown I get a selection event on the table. 

Output:
Several times
table Measure Event {type=41 Table {} time=70854328 data=null x=241 y=423 width=0 height=13 detail=0}
table Erase Event {type=40 Table {} time=70854328 data=null x=241 y=423 width=249 height=13 detail=16}
table Paint Event {type=42 Table {} time=70854328 data=null x=241 y=423 width=0 height=13 detail=16}
…
And:
table Selection Event {type=13 Table {} time=70027750 data=null x=0 y=0 width=0 height=0 detail=0}


The ugly code here does not layout on the selection event of the table but on the selection of the scrollbar.

public class Snippet
{

   private static class FilterLayout
      extends Layout
   {

      private final Table table;

      public FilterLayout (Table table)
      {
         this.table = table;

      }

      @Override
      protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache)
      {
         return new Point(150, 500);
      }

      @Override
      protected void layout (Composite composite, boolean flushCache)
      {
         composite.getChildren()[1].setBounds(- table.getHorizontalBar().getSelection() + 3, 0, 100, 100);
         composite.getChildren()[0].setBounds(0, 20, 150,450);

      }

   }

   public static void main (String[] args)
   {
      Display display = new Display();
      Shell shell = new Shell(display);
      shell.setLayout(new GridLayout());
      shell.setLayoutData(new GridData(250, 150));
      final Composite c = new Composite(shell, SWT.NONE);
      Table table = new Table(c, SWT.BORDER | SWT.MULTI);
      c.setLayout(new FilterLayout(table));

      Label label = new Label(c, SWT.NORMAL);
      label.setText("Filter");
      label.setLayoutData(new GridData(10, 200));

      table.setLinesVisible(true);
      TableColumn col = new TableColumn(table, SWT.NONE);
      col.setWidth(250);
      TableColumn col2 = new TableColumn(table, SWT.NONE);
      col2.setWidth(250);
      table.setHeaderVisible(true);
      table.setLayoutData(new GridData(270, 150));

      // Selection, DefaultSelection, SetData, MeasureItem, EraseItem, PaintItem 
      table.addListener(SWT.Selection, new ListenerImpl("Selection", "table"));
      table.addListener(SWT.DefaultSelection, new ListenerImpl("DefaultSelection", "table"));
      table.addListener(SWT.SetData, new ListenerImpl("SetData", "table"));
      table.addListener(SWT.MeasureItem, new ListenerImpl("Measure", "table"));
      table.addListener(SWT.EraseItem, new ListenerImpl("Erase", "table"));
      table.addListener(SWT.PaintItem, new ListenerImpl("Paint", "table"));
      table.getHorizontalBar().addListener(SWT.Selection, new ListenerImpl("Selection", "scrollbar")
      {
         @Override
         public void handleEvent (Event arg0)
         {
            
            super.handleEvent(arg0);
            c.layout();
         }
      });
      shell.pack();
      shell.open(); // Bug
      for (int i = 0; i < 128; i++)
      {
         TableItem item = new TableItem(table, SWT.NONE);
         item.setText("Item                           " + i);
      }
//                  shell.open(); // NO-Bug
      while (!shell.isDisposed())
      {
         if (!display.readAndDispatch())
            display.sleep();
      }
      display.dispose();
   }

   private static class ListenerImpl
      implements Listener
   {

      private final String event;

      private final String widget;

      ListenerImpl (String event, String widget)
      {
         this.event = event;
         this.widget = widget;

      }

      public void handleEvent (Event event)
      {

         System.out.println(widget + " " + this.event + " " + event);
      }
   };
}
Comment 3 Dominik Riedweg CLA 2008-03-11 08:18:30 EDT
Changed version to 3.4 and severity to minor.
Comment 4 Eclipse Webmaster CLA 2019-09-06 15:33:08 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.