GridWidgetColumnFactoryImpl implements GridWidgetColumnFactory { @Override public GridColumn<?> convertColumn(final BaseColumn column, final GuidedDecisionTablePresenter.Access access, final GuidedDecisionTableView gridWidget) { for (BaseColumnConverter converter : converters) { if (converter.handles(column)) { final GridColumn<?> uiColumn = converter.convertColumn(column, access, gridWidget); if (uiColumn instanceof BaseUiColumn) { ((BaseUiColumn) uiColumn).setColumnResizeListener((double width) -> column.setWidth(((int) width))); } column.setWidth((int) uiColumn.getWidth()); return uiColumn; } } throw new IllegalArgumentException("Column '" + column.getHeader() + "' was not converted."); }  @Override void setConverters(final List<BaseColumnConverter> converters); @Override void initialise(final GuidedDecisionTable52 model,
                           final AsyncPackageDataModelOracle oracle,
                           final ColumnUtilities columnUtilities,
                           final GuidedDecisionTableView.Presenter presenter); @Override GridColumn<?> convertColumn(final BaseColumn column,
                                       final GuidedDecisionTablePresenter.Access access,
                                       final GuidedDecisionTableView gridWidget);  }
@Test public void columnResizingListenerSetup_RowNumberColumn() { final BaseColumn column = new RowNumberCol52(); final GridColumn<?> uiColumn = factory.convertColumn(column, access, gridWidget); assertFalse(uiColumn instanceof BaseUiColumn); assertEquals((int) uiColumn.getWidth(), column.getWidth()); assertEquals(50.0, column.getWidth(), 0.0); }
@Test public void columnResizingListenerSetup_DescriptionColumn() { final BaseColumn column = new DescriptionCol52(); final GridColumn<?> uiColumn = factory.convertColumn(column, access, gridWidget); assertTrue(uiColumn instanceof BaseUiColumn); assertEquals((int) uiColumn.getWidth(), column.getWidth()); assertEquals(150.0, column.getWidth(), 0.0); uiColumn.setWidth(200.0); assertEquals(200, column.getWidth()); }
@Test public void columnResizingListenerSetup_MetadataColumn() { final MetadataCol52 column = new MetadataCol52(); column.setMetadata("metadata"); final GridColumn<?> uiColumn = factory.convertColumn(column, access, gridWidget); assertTrue(uiColumn instanceof BaseUiColumn); assertEquals((int) uiColumn.getWidth(), column.getWidth()); uiColumn.setWidth(200.0); assertEquals(200, column.getWidth()); }
@Test public void columnResizingListenerSetup_AttributeColumn() { final AttributeCol52 column = new AttributeCol52(); column.setAttribute(Attribute.SALIENCE.getAttributeName()); final GridColumn<?> uiColumn = factory.convertColumn(column, access, gridWidget); assertTrue(uiColumn instanceof BaseUiColumn); assertEquals((int) uiColumn.getWidth(), column.getWidth()); uiColumn.setWidth(200.0); assertEquals(200, column.getWidth()); }
@Test public void columnResizingListenerSetup_ConditionColumn() { final Pattern52 pattern = mock(Pattern52.class); final ConditionCol52 column = new ConditionCol52(); column.setFactField("MyField"); column.setHeader("MyColumn"); when(model.getPattern(eq(column))).thenReturn(pattern); when(pattern.getFactType()).thenReturn("MyFact"); when(oracle.getFieldType("MyFact", "MyField")).thenReturn(DataType.TYPE_STRING); final GridColumn<?> uiColumn = factory.convertColumn(column, access, gridWidget); assertTrue(uiColumn instanceof BaseUiColumn); assertEquals((int) uiColumn.getWidth(), column.getWidth()); uiColumn.setWidth(200.0); assertEquals(200, column.getWidth()); }
@Test public void columnResizingListenerSetup_ActionSetFieldColumn() { final Pattern52 pattern = mock(Pattern52.class); final ActionSetFieldCol52 column = new ActionSetFieldCol52(); column.setFactField("MyField"); column.setHeader("MyColumn"); column.setBoundName("$f"); when(model.getConditions()).thenReturn(new ArrayList<CompositeColumn<? extends BaseColumn>>() {{ add(pattern); }}); when(pattern.getFactType()).thenReturn("MyFact"); when(pattern.getBoundName()).thenReturn("$f"); when(pattern.isBound()).thenReturn(true); when(oracle.getFieldType("MyFact", "MyField")).thenReturn(DataType.TYPE_STRING); final GridColumn<?> uiColumn = factory.convertColumn(column, access, gridWidget); assertTrue(uiColumn instanceof BaseUiColumn); assertEquals((int) uiColumn.getWidth(), column.getWidth()); uiColumn.setWidth(200.0); assertEquals(200, column.getWidth()); }
@Test public void columnResizingListenerSetup_ActionInsertFactColumn() { final ActionInsertFactCol52 column = new ActionInsertFactCol52(); column.setFactType("MyFact"); column.setFactField("MyField"); column.setHeader("MyColumn"); when(oracle.getFieldType("MyFact", "MyField")).thenReturn(DataType.TYPE_STRING); final GridColumn<?> uiColumn = factory.convertColumn(column, access, gridWidget); assertTrue(uiColumn instanceof BaseUiColumn); assertEquals((int) uiColumn.getWidth(), column.getWidth()); uiColumn.setWidth(200.0); assertEquals(200, column.getWidth()); }
@Test public void testHiddenColumn_ConditionColumn() { final Pattern52 pattern = mock(Pattern52.class); final ConditionCol52 column = new ConditionCol52(); column.setFactField("MyField"); column.setHeader("MyColumn"); column.setHideColumn(true); when(model.getPattern(eq(column))).thenReturn(pattern); when(pattern.getFactType()).thenReturn("MyFact"); when(oracle.getFieldType("MyFact", "MyField")).thenReturn(DataType.TYPE_STRING); final GridColumn<?> uiColumn = factory.convertColumn(column, access, gridWidget); assertEquals(false, uiColumn.isVisible()); }
@Test public void testNumericColumn_IsContainedInOperator() { final BRLConditionVariableColumn column = new BRLConditionVariableColumn("$a", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age", "in"); column.setHeader("age is"); final GridColumn gridColumn = factory.convertColumn(column, access, gridWidget); assertTrue(gridColumn instanceof StringUiColumn); }
@Test public void testNumericColumn_EqualOperator() { final BRLConditionVariableColumn column = new BRLConditionVariableColumn("$a", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age", "=="); column.setHeader("age equal to"); when(oracle.getFieldType("Applicant", "age")).thenReturn(DataType.TYPE_NUMERIC_INTEGER); final GridColumn gridColumn = factory.convertColumn(column, access, gridWidget); assertTrue(gridColumn instanceof IntegerUiColumn); }