use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn in project drools-wb by kiegroup.
the class ActionColumnSynchronizer method isWorkItemFragmentBeforeInsertFactCol.
protected boolean isWorkItemFragmentBeforeInsertFactCol(final List<? extends MetaData> metaData) {
final List<ActionCol52> columnsToMove = metaData.stream().map(c -> (MoveColumnToMetaData) c).map(MoveColumnToMetaData::getColumn).map(c -> (ActionCol52) c).collect(Collectors.toList());
final List<String> bindingsUsedByWID = new ArrayList<>();
bindingsUsedByWID.addAll(columnsToMove.stream().filter(c -> c instanceof ActionWorkItemInsertFactCol52).map(c -> (ActionWorkItemInsertFactCol52) c).map(ActionWorkItemInsertFactCol52::getBoundName).collect(Collectors.toList()));
final AtomicBoolean result = new AtomicBoolean(true);
final int tgtIndex = ((MoveColumnToMetaData) metaData.get(0)).getTargetColumnIndex();
final List<BaseColumn> modelColumns = model.getExpandedColumns();
// Cannot move "Insert and Set field" created by the WID to after other "Insert and Set field"
for (String binding : bindingsUsedByWID) {
model.getActionCols().stream().filter(c -> !columnsToMove.contains(c)).filter(c -> c instanceof ActionInsertFactCol52).filter(c -> !(c instanceof ActionWorkItemInsertFactCol52)).map(c -> (ActionInsertFactCol52) c).filter(c -> c.getBoundName().equals(binding)).map(modelColumns::indexOf).filter(i -> tgtIndex >= i).findFirst().ifPresent(i -> result.set(false));
}
return result.get();
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn in project drools-wb by kiegroup.
the class ActionColumnSynchronizer method doMoveActionFragment.
protected void doMoveActionFragment(final List<MoveColumnToMetaData> metaData) throws VetoException {
final MoveColumnToMetaData md = metaData.get(0);
final BaseColumn firstColumnInFragment = md.getColumn();
final BaseColumn lastColumnInFragment = metaData.get(metaData.size() - 1).getColumn();
final int srcColumnFirstIndex = model.getExpandedColumns().indexOf(firstColumnInFragment);
final int srcColumnLastIndex = model.getExpandedColumns().indexOf(lastColumnInFragment);
final List<ActionCol52> srcModelFragmentColumns = IntStream.rangeClosed(srcColumnFirstIndex, srcColumnLastIndex).mapToObj(i -> model.getExpandedColumns().get(i)).map(column -> (ActionCol52) column).collect(Collectors.toList());
final int srcModelFragmentColumnsCount = srcModelFragmentColumns.size();
if (srcModelFragmentColumnsCount == 0) {
throw new ModelSynchronizer.MoveVetoException();
}
if (srcModelFragmentColumnsCount != metaData.size()) {
throw new ModelSynchronizer.MoveVetoException();
}
final int tgtColumnIndex = md.getTargetColumnIndex();
final int tgtActionIndex = findTargetActionIndex(md);
final List<BaseColumn> allModelColumns = model.getExpandedColumns();
moveModelData(tgtColumnIndex, allModelColumns.indexOf(srcModelFragmentColumns.get(0)), allModelColumns.indexOf(srcModelFragmentColumns.get(0)) + srcModelFragmentColumnsCount - 1);
// Moving left
if (tgtColumnIndex < srcColumnFirstIndex) {
final AtomicInteger offset = new AtomicInteger(0);
srcModelFragmentColumns.forEach(column -> {
model.getActionCols().remove(column);
model.getActionCols().add(tgtActionIndex + offset.getAndIncrement(), column);
});
}
// Moving right
if (tgtColumnIndex > srcColumnFirstIndex) {
srcModelFragmentColumns.forEach(column -> {
model.getActionCols().remove(column);
model.getActionCols().add(tgtActionIndex, column);
});
}
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn in project drools-wb by kiegroup.
the class GridWidgetColumnFactoryImplTest method columnResizingListenerSetup_ActionSetFieldColumn.
@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());
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn in project drools-wb by kiegroup.
the class GridWidgetColumnFactoryImplTest method columnResizingListenerSetup_DescriptionColumn.
@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());
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn in project drools-wb by kiegroup.
the class BaseActionWorkItemConverterTest method checkConvertColumn.
@Test
public void checkConvertColumn() {
final BaseColumn column = getColumn();
final GridColumn<?> uiColumn = converter.convertColumn(column, access, gridWidget);
assertTrue(uiColumn.isResizable());
assertTrue(uiColumn.isVisible());
assertEquals(WIDTH, uiColumn.getWidth(), 0.0);
assertEquals(2, uiColumn.getHeaderMetaData().size());
final GridColumn.HeaderMetaData row0 = uiColumn.getHeaderMetaData().get(0);
assertEquals(WID_NAME, row0.getTitle());
assertEquals(ActionCol52.class.getName(), row0.getColumnGroup());
final GridColumn.HeaderMetaData row1 = uiColumn.getHeaderMetaData().get(1);
assertEquals(HEADER, row1.getTitle());
assertEquals(getExpectedColumnGroup(), row1.getColumnGroup());
}
Aggregations