예제 #1
0
파일: UIUtils.java 프로젝트: ralic/dbeaver
 public static int getColumnAtPos(TreeItem item, int x, int y) {
   int columnCount = item.getParent().getColumnCount();
   for (int i = 0; i < columnCount; i++) {
     Rectangle rect = item.getBounds(i);
     if (rect.contains(x, y)) {
       return i;
     }
   }
   return -1;
 }
 @Test
 public void testPack() throws IOException {
   tree.setHeaderVisible(true);
   column.addListener(SWT.Resize, new LoggingListener());
   // Ensure that controlResized is fired when pack changes the width
   column.setWidth(12312);
   eventLog.clear();
   column.pack();
   assertSame(eventLog.get(0).widget, column);
   // Ensure that controlResized is *not* fired when pack doesn't change the
   // width
   eventLog.clear();
   column.pack();
   assertEquals(0, eventLog.size());
   // pack calculates a minimal width for an empty column
   column = new TreeColumn(tree, SWT.NONE);
   column.pack();
   assertTrue(column.getWidth() > 0);
   // Test that an image on a column is taken into account
   column = new TreeColumn(tree, SWT.NONE);
   Image image = createImage(display, Fixture.IMAGE_50x100);
   column.setImage(image);
   column.pack();
   assertTrue(column.getWidth() >= image.getBounds().width);
   // An item wider than the column itself strechtes the column
   column = new TreeColumn(tree, SWT.NONE);
   TreeItem item = new TreeItem(tree, SWT.NONE);
   item.setImage(image);
   column.pack();
   assertTrue(column.getWidth() >= item.getBounds().width);
   int widthNoSortIndicator = column.getWidth();
   tree.setSortColumn(column);
   tree.setSortDirection(SWT.UP);
   column.pack();
   assertTrue(column.getWidth() > widthNoSortIndicator);
 }