public void testAddDoubleClickListener() { final TableRidget ridget = getRidget(); final Table control = getWidget(); try { ridget.addDoubleClickListener(null); fail(); } catch (final RuntimeException npe) { ok(); } final FTActionListener listener1 = new FTActionListener(); ridget.addDoubleClickListener(listener1); final FTActionListener listener2 = new FTActionListener(); ridget.addDoubleClickListener(listener2); ridget.addDoubleClickListener(listener2); final Event doubleClick = new Event(); doubleClick.widget = control; doubleClick.type = SWT.MouseDoubleClick; control.notifyListeners(SWT.MouseDoubleClick, doubleClick); assertEquals(1, listener1.getCount()); assertEquals(1, listener2.getCount()); ridget.removeDoubleClickListener(listener1); control.notifyListeners(SWT.MouseDoubleClick, doubleClick); assertEquals(1, listener1.getCount()); }
public void testSetSortedColumnFiresEvents() { final TableRidget ridget = getRidget(); assertEquals(-1, ridget.getSortedColumn()); expectPropertyChangeEvents( new PropertyChangeEvent( ridget, ISortableByColumn.PROPERTY_SORTED_COLUMN, Integer.valueOf(-1), Integer.valueOf(0))); ridget.setSortedColumn(0); verifyPropertyChangeEvents(); expectNoPropertyChangeEvent(); ridget.setSortedColumn(0); verifyPropertyChangeEvents(); expectPropertyChangeEvents( new PropertyChangeEvent( ridget, ISortableByColumn.PROPERTY_SORTED_COLUMN, Integer.valueOf(0), Integer.valueOf(1))); ridget.setSortedColumn(1); verifyPropertyChangeEvents(); }
public void testSetComparator() { final TableRidget ridget = getRidget(); final Table control = getWidget(); // sorts from a to z final Comparator<Object> comparator = new TypedComparator<String>(); try { ridget.setComparator(-1, comparator); fail(); } catch (final RuntimeException rex) { ok(); } try { ridget.setComparator(2, comparator); fail(); } catch (final RuntimeException rex) { ok(); } ridget.setSortedAscending(true); final int lastItemIndex = control.getItemCount() - 1; assertEquals("John", control.getItem(0).getText(0)); // $NON-NLS-1$ assertEquals("Frank", control.getItem(lastItemIndex).getText(0)); // $NON-NLS-1$ ridget.setComparator(0, comparator); assertEquals("John", control.getItem(0).getText(0)); // $NON-NLS-1$ assertEquals("Frank", control.getItem(lastItemIndex).getText(0)); // $NON-NLS-1$ ridget.setSortedColumn(0); assertEquals("Frank", control.getItem(0).getText(0)); // $NON-NLS-1$ assertEquals("John", control.getItem(lastItemIndex).getText(0)); // $NON-NLS-1$ ridget.setComparator(0, null); assertEquals("John", control.getItem(0).getText(0)); // $NON-NLS-1$ assertEquals("Frank", control.getItem(lastItemIndex).getText(0)); // $NON-NLS-1$ ridget.setComparator(1, comparator); ridget.setSortedColumn(1); assertEquals("Doe", control.getItem(0).getText(1)); // $NON-NLS-1$ assertEquals("Zappa", control.getItem(lastItemIndex).getText(1)); // $NON-NLS-1$ ridget.setSortedAscending(false); assertEquals("Zappa", control.getItem(0).getText(1)); // $NON-NLS-1$ assertEquals("Doe", control.getItem(lastItemIndex).getText(1)); // $NON-NLS-1$ }
/** Tests the method {@code clearColumnFormatters()}. */ public void testClearColumnFormatters() { final TableRidget ridget = getRidget(); final IColumnFormatter formatter = new ColumnFormatter() { @Override public String getText(final Object element) { return "dummy"; //$NON-NLS-1$ } }; ridget.setColumnFormatter(1, formatter); IColumnFormatter[] retFormatters = ReflectionUtils.invokeHidden( ridget, "getColumnFormatters", ridget.getColumnCount()); // $NON-NLS-1$ assertNotNull(retFormatters); assertEquals(ridget.getColumnCount(), retFormatters.length); assertNull(retFormatters[0]); assertNotNull(retFormatters[1]); assertSame(formatter, retFormatters[1]); ridget.clearColumnFormatters(); retFormatters = ReflectionUtils.invokeHidden( ridget, "getColumnFormatters", ridget.getColumnCount()); // $NON-NLS-1$ assertNotNull(retFormatters); assertEquals(ridget.getColumnCount(), retFormatters.length); assertNull(retFormatters[0]); assertNull(retFormatters[1]); }
/** * Tests that for multiple selection, the ridget selection state and the ui selection state cannot * be changed by the user when ridget is set to "output only". */ public void testOutputMultipleSelectionCannotBeChangedFromUI() { final TableRidget ridget = getRidget(); final Table control = getWidget(); ridget.setSelectionType(SelectionType.MULTI); assertEquals(0, ridget.getSelection().size()); assertEquals(0, control.getSelectionCount()); ridget.setOutputOnly(true); control.setFocus(); // move down and up to select row 0; space does not select in tables UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_DOWN); UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_UP); assertEquals(0, ridget.getSelection().size()); assertEquals(0, control.getSelectionCount()); ridget.setOutputOnly(false); control.setFocus(); // move down and up to select row 0; space does not select in tables UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_DOWN); UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_UP); assertEquals(1, ridget.getSelection().size()); assertEquals(1, control.getSelectionCount()); }
public void testIsCheckBoxInFirstColumn() throws Exception { final TableRidget ridget = getRidget(); TableViewer tableViewer = ReflectionUtils.invokeHidden(ridget, "getTableViewer"); // $NON-NLS-1$ assertFalse(ridget.isCheckBoxInFirstColumn(tableViewer)); // style != SWT.CHECK final Table table = new Table(getShell(), SWT.CHECK); table.setHeaderVisible(true); new TableColumn(table, SWT.NONE); new TableColumn(table, SWT.NONE); ridget.setUIControl(table); tableViewer = ReflectionUtils.invokeHidden(ridget, "getTableViewer"); // $NON-NLS-1$ assertFalse(ridget.isCheckBoxInFirstColumn(tableViewer)); // property of first column != boolean final String[] properties1 = new String[] {"hasCat", "firstname"}; // $NON-NLS-1$ //$NON-NLS-2$ final String[] headers1 = new String[] {"Cat", "First Name"}; // $NON-NLS-1$ //$NON-NLS-2$ getRidget().bindToModel(manager, "persons", Person.class, properties1, headers1); // $NON-NLS-1$ tableViewer = ReflectionUtils.invokeHidden(ridget, "getTableViewer"); // $NON-NLS-1$ assertTrue(ridget.isCheckBoxInFirstColumn(tableViewer)); // property of first column == boolean }
public void testSetColumnSortabilityFiresEvents() { final TableRidget ridget = getRidget(); expectNoPropertyChangeEvent(); ridget.setColumnSortable(0, true); verifyPropertyChangeEvents(); expectPropertyChangeEvents( new PropertyChangeEvent( ridget, ISortableByColumn.PROPERTY_COLUMN_SORTABILITY, null, Integer.valueOf(0))); ridget.setColumnSortable(0, false); verifyPropertyChangeEvents(); expectNoPropertyChangeEvent(); ridget.setColumnSortable(0, false); verifyPropertyChangeEvents(); expectPropertyChangeEvents( new PropertyChangeEvent( ridget, ISortableByColumn.PROPERTY_COLUMN_SORTABILITY, null, Integer.valueOf(0))); ridget.setColumnSortable(0, true); verifyPropertyChangeEvents(); expectNoPropertyChangeEvent(); ridget.setColumnSortable(0, true); verifyPropertyChangeEvents(); }
public void testSetSortedAscendingFiresEvents() { final TableRidget ridget = getRidget(); ridget.setSortedAscending(true); expectPropertyChangeEvents( new PropertyChangeEvent( ridget, ISortableByColumn.PROPERTY_SORT_ASCENDING, Boolean.TRUE, Boolean.FALSE)); ridget.setSortedAscending(false); verifyPropertyChangeEvents(); expectNoPropertyChangeEvent(); ridget.setSortedAscending(false); verifyPropertyChangeEvents(); expectPropertyChangeEvents( new PropertyChangeEvent( ridget, ISortableByColumn.PROPERTY_SORT_ASCENDING, Boolean.FALSE, Boolean.TRUE)); ridget.setSortedAscending(true); verifyPropertyChangeEvents(); expectNoPropertyChangeEvent(); ridget.setSortedAscending(true); verifyPropertyChangeEvents(); }
/** Tests that toggling output state on/off does not change the selection. */ public void testTogglingOutputDoesNotChangeSelection() { final TableRidget ridget = getRidget(); ridget.setSelection(0); assertEquals(0, ridget.getSelectionIndex()); ridget.setOutputOnly(true); assertEquals(0, ridget.getSelectionIndex()); ridget.setSelection((Object) null); assertEquals(-1, ridget.getSelectionIndex()); ridget.setOutputOnly(false); assertEquals(-1, ridget.getSelectionIndex()); }
@Override public void testAddClickListener() { final TableRidget ridget = getRidget(); ridget.updateFromModel(); final Table control = getWidget(); control.getColumn(0).setWidth(100); control.getColumn(1).setWidth(100); try { ridget.addClickListener(null); fail(); } catch (final RuntimeException npe) { ok(); } final FTClickListener listener1 = new FTClickListener(); ridget.addClickListener(listener1); final FTClickListener listener2 = new FTClickListener(); ridget.addClickListener(listener2); ridget.addClickListener(listener2); final Event mdEvent = new Event(); mdEvent.widget = control; mdEvent.type = SWT.MouseDown; mdEvent.button = 2; final TableItem row2 = control.getItem(2); mdEvent.item = row2; mdEvent.x = row2.getBounds().x + 1; mdEvent.y = row2.getBounds().y + 1; control.notifyListeners(SWT.MouseDown, mdEvent); assertEquals(0, listener1.getCount()); assertEquals(0, listener2.getCount()); mdEvent.type = SWT.MouseUp; control.notifyListeners(SWT.MouseUp, mdEvent); assertEquals(1, listener1.getCount()); assertEquals(1, listener2.getCount()); final ClickEvent event = listener2.getEvent(); assertEquals(ridget, event.getSource()); assertEquals(2, event.getButton()); assertEquals(0, event.getColumnIndex()); assertEquals(row2.getData(), event.getRow()); ridget.removeClickListener(listener1); mdEvent.type = SWT.MouseDown; control.notifyListeners(SWT.MouseDown, mdEvent); mdEvent.type = SWT.MouseUp; control.notifyListeners(SWT.MouseUp, mdEvent); assertEquals(1, listener1.getCount()); }
public void testSetColumnFormatter() { final TableRidget ridget = getRidget(); final Table table = getWidget(); final IColumnFormatter formatter = new ColumnFormatter() { @Override public String getText(final Object element) { final Person person = (Person) element; return person.getLastname().toUpperCase(); } }; final String lastName = person1.getLastname(); final String lastNameUpperCase = lastName.toUpperCase(); try { ridget.setColumnFormatter(-1, formatter); fail(); } catch (final RuntimeException rex) { ok(); } try { ridget.setColumnFormatter(99, formatter); fail(); } catch (final RuntimeException rex) { ok(); } ridget.setColumnFormatter(1, formatter); assertEquals(lastName, table.getItem(0).getText(1)); ridget.updateFromModel(); assertEquals(lastNameUpperCase, table.getItem(0).getText(1)); ridget.setColumnFormatter(1, null); assertEquals(lastNameUpperCase, table.getItem(0).getText(1)); ridget.updateFromModel(); assertEquals(lastName, table.getItem(0).getText(1)); }
public void testSetMoveableColumns() { final TableRidget ridget = getRidget(); final Table table = getWidget(); assertFalse(ridget.hasMoveableColumns()); assertFalse(table.getColumn(0).getMoveable()); assertFalse(table.getColumn(1).getMoveable()); ridget.setMoveableColumns(true); assertTrue(ridget.hasMoveableColumns()); assertTrue(table.getColumn(0).getMoveable()); assertTrue(table.getColumn(1).getMoveable()); ridget.setMoveableColumns(false); assertFalse(ridget.hasMoveableColumns()); assertFalse(table.getColumn(0).getMoveable()); assertFalse(table.getColumn(1).getMoveable()); }
public void testAddSelectionListener() { final TableRidget ridget = getRidget(); final Table control = getWidget(); try { ridget.addSelectionListener(null); fail(); } catch (final RuntimeException npe) { ok(); } final TestSelectionListener selectionListener = new TestSelectionListener(); ridget.addSelectionListener(selectionListener); ridget.setSelection(person1); assertEquals(1, selectionListener.getCount()); ridget.removeSelectionListener(selectionListener); ridget.setSelection(person2); assertEquals(1, selectionListener.getCount()); ridget.clearSelection(); ridget.addSelectionListener(selectionListener); ridget.setSelectionType(SelectionType.SINGLE); assertEquals(0, ridget.getSelection().size()); assertEquals(0, control.getSelectionCount()); control.setFocus(); UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_DOWN); assertEquals(1, ridget.getSelection().size()); assertEquals(1, control.getSelectionCount()); assertEquals(2, selectionListener.getCount()); final SelectionEvent selectionEvent = selectionListener.getSelectionEvent(); assertEquals(ridget, selectionEvent.getSource()); assertTrue(selectionEvent.getOldSelection().isEmpty()); assertEquals(ridget.getSelection(), selectionEvent.getNewSelection()); // System.out.println("SelectionEvent: " + selectionListener.getSelectionEvent()); UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_DOWN); assertEquals(1, ridget.getSelection().size()); assertEquals(1, control.getSelectionCount()); assertEquals(3, selectionListener.getCount()); final SelectionEvent selectionEvent2 = selectionListener.getSelectionEvent(); assertEquals(ridget, selectionEvent.getSource()); assertEquals(selectionEvent.getNewSelection(), selectionEvent2.getOldSelection()); assertEquals(ridget.getSelection(), selectionEvent2.getNewSelection()); // System.out.println("SelectionEvent: " + selectionListener.getSelectionEvent()); ridget.removeSelectionListener(selectionListener); }
public void testGetSortedColumn() { final TableRidget ridget = getRidget(); try { ridget.setSortedColumn(2); fail(); } catch (final RuntimeException rex) { ok(); } assertEquals(-1, ridget.getSortedColumn()); ridget.setComparator(0, new TypedComparator<String>()); assertEquals(-1, ridget.getSortedColumn()); ridget.setSortedColumn(0); assertEquals(0, ridget.getSortedColumn()); ridget.setComparator(0, null); assertEquals(-1, ridget.getSortedColumn()); ridget.setComparator(1, new TypedComparator<String>()); ridget.setSortedColumn(1); assertEquals(1, ridget.getSortedColumn()); ridget.setSortedColumn(-1); assertEquals(-1, ridget.getSortedColumn()); // no comparator in column 0 ridget.setSortedColumn(0); assertEquals(-1, ridget.getSortedColumn()); }
public void testIsColumnSortable() { final TableRidget ridget = getRidget(); try { assertFalse(ridget.isColumnSortable(-1)); fail(); } catch (final RuntimeException rex) { ok(); } try { assertFalse(ridget.isColumnSortable(2)); fail(); } catch (final RuntimeException rex) { ok(); } for (int i = 0; i < 2; i++) { assertFalse(ridget.isColumnSortable(i)); // columns are sortable by default, when they have a comparator ridget.setComparator(i, new TypedComparator<String>()); assertTrue(ridget.isColumnSortable(i)); ridget.setColumnSortable(i, false); assertFalse(ridget.isColumnSortable(i)); ridget.setColumnSortable(i, true); assertTrue(ridget.isColumnSortable(i)); // columns are not sortable without a comparator ridget.setComparator(i, null); assertFalse(ridget.isColumnSortable(i)); } }
public void testColumnHeaderChangesSortability() { final TableRidget ridget = getRidget(); final Table table = getWidget(); ridget.setColumnSortable(0, true); ridget.setComparator(0, new TypedComparator<String>()); ridget.setColumnSortable(1, true); ridget.setComparator(1, new TypedComparator<String>()); ridget.setSortedColumn(-1); assertEquals(-1, ridget.getSortedColumn()); assertFalse(ridget.isSortedAscending()); final Event e = new Event(); e.type = SWT.Selection; e.widget = table.getColumn(0); e.widget.notifyListeners(SWT.Selection, e); assertEquals(0, ridget.getSortedColumn()); assertTrue(ridget.isSortedAscending()); e.widget.notifyListeners(SWT.Selection, e); assertEquals(0, ridget.getSortedColumn()); assertFalse(ridget.isSortedAscending()); e.widget.notifyListeners(SWT.Selection, e); assertEquals(-1, ridget.getSortedColumn()); assertFalse(ridget.isSortedAscending()); e.widget.notifyListeners(SWT.Selection, e); assertEquals(0, ridget.getSortedColumn()); assertTrue(ridget.isSortedAscending()); }
public void testSetSortedAscending() { final Table control = getWidget(); final TableRidget ridget = getRidget(); ridget.bindToModel( manager, "persons", Person.class, new String[] {"lastname", "firstname"}, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ ridget.updateFromModel(); final int lastItemIndex = control.getItemCount() - 1; assertEquals(-1, ridget.getSortedColumn()); assertFalse(ridget.isSortedAscending()); ridget.setComparator(0, new TypedComparator<String>()); ridget.setSortedColumn(0); assertTrue(ridget.isSortedAscending()); assertEquals("Doe", control.getItem(0).getText(0)); // $NON-NLS-1$ assertEquals("Zappa", control.getItem(lastItemIndex).getText(0)); // $NON-NLS-1$ ridget.setSortedAscending(false); assertFalse(ridget.isSortedAscending()); assertEquals("Zappa", control.getItem(0).getText(0)); // $NON-NLS-1$ assertEquals("Doe", control.getItem(lastItemIndex).getText(0)); // $NON-NLS-1$ ridget.setSortedAscending(true); assertTrue(ridget.isSortedAscending()); assertEquals("Doe", control.getItem(0).getText(0)); // $NON-NLS-1$ assertEquals("Zappa", control.getItem(lastItemIndex).getText(0)); // $NON-NLS-1$ ridget.setComparator(0, null); assertEquals(-1, ridget.getSortedColumn()); assertFalse(ridget.isSortedAscending()); }