use of org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem in project kie-wb-common by kiegroup.
the class DNDDataTypesHandler method shiftCurrentByReference.
void shiftCurrentByReference(final DataType current, final DataType reference, final DNDDataTypesHandlerShiftStrategy shiftStrategy) {
final String referenceHash = getDataTypeList().calculateHash(reference);
final DataType clone = cloneDataType(current);
final Optional<DataTypeListItem> currentItem = getDataTypeList().findItem(current);
final boolean isCurrentItemCollapsed = currentItem.map(DataTypeListItem::isCollapsed).orElse(false);
// destroy current data type
currentItem.ifPresent(item -> {
if (isTopLevelShiftOperation(current, shiftStrategy)) {
item.destroyWithoutDependentTypes();
} else {
item.destroyWithDependentTypes();
}
});
// create new data type by using shift strategy
getDataTypeList().findItemByDataTypeHash(referenceHash).ifPresent(ref -> {
shiftStrategy.getConsumer().accept(ref, clone);
});
// keep the state of the new data type item consistent
dataTypeList.findItemByDataTypeHash(getDataTypeList().calculateHash(clone)).ifPresent(item -> {
if (isCurrentItemCollapsed) {
item.collapse();
} else {
item.expand();
}
expandParents(item.getDataType());
highlightLevel(item.getDragAndDropElement());
});
}
use of org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem in project kie-wb-common by kiegroup.
the class DataTypeConstraintTest method testOpenModal.
@Test
public void testOpenModal() {
final DataTypeListItem listItem = mock(DataTypeListItem.class);
final String constraint = "1,2,3";
final String type = "string";
final BiConsumer<String, ConstraintType> onShowConsumer = (s, c) -> {
/* Nothing. */
};
doReturn(listItem).when(dataTypeConstraint).getListItem();
doReturn(constraint).when(dataTypeConstraint).getValue();
doReturn(onShowConsumer).when(dataTypeConstraint).getOnShowConsumer();
when(listItem.getType()).thenReturn(type);
dataTypeConstraint.openModal();
constraintModal.load(type, constraint, ENUMERATION);
constraintModal.show(onShowConsumer);
}
use of org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem in project kie-wb-common by kiegroup.
the class DataTypeSearchBarTest method testGetDataTypeListItemsSortedByPositionY.
@Test
public void testGetDataTypeListItemsSortedByPositionY() {
final DataTypeListItem list0 = mock(DataTypeListItem.class);
final DataTypeListItem list1 = mock(DataTypeListItem.class);
final HTMLElement element0 = mock(HTMLElement.class);
final HTMLElement element1 = mock(HTMLElement.class);
final DNDListComponent dndListComponent = mock(DNDListComponent.class);
final Integer positionY0 = 3;
final Integer positionY1 = 2;
final Map<String, Integer> store = new HashMap<>();
when(dndListComponent.getPositionY(element0)).thenReturn(positionY0);
when(dndListComponent.getPositionY(element1)).thenReturn(positionY1);
when(list0.getDragAndDropElement()).thenReturn(element0);
when(list1.getDragAndDropElement()).thenReturn(element1);
when(dataTypeList.getItems()).thenReturn(asList(list0, list1));
when(dataTypeList.getDNDListComponent()).thenReturn(dndListComponent);
doReturn(store).when(searchBar).getDataTypeListPositionsStore();
final List<DataTypeListItem> actualListItems = searchBar.getDataTypeListItemsSortedByPositionY();
final List<DataTypeListItem> expectedListItems = asList(list1, list0);
assertEquals(expectedListItems, actualListItems);
}
use of org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem in project kie-wb-common by kiegroup.
the class DataTypeSearchBarViewTest method testIsParentElementOnListWhenIsNotPresent.
@Test
public void testIsParentElementOnListWhenIsNotPresent() {
final DataTypeListItem item = mock(DataTypeListItem.class);
final HTMLElement element = mock(HTMLElement.class);
final String id = "id";
when(element.getAttribute(UUID_ATTR)).thenReturn("otherId");
when(item.getDragAndDropElement()).thenReturn(element);
final List<DataTypeListItem> groupedElements = Arrays.asList(item);
boolean isPresent = view.isParentElementOnList(groupedElements, id);
assertFalse(isPresent);
}
use of org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem in project kie-wb-common by kiegroup.
the class DataTypeSearchBarViewTest method testExpandListItems.
@Test
public void testExpandListItems() {
final DataTypeListItem item1 = mock(DataTypeListItem.class);
final DataTypeListItem item2 = mock(DataTypeListItem.class);
final List<DataTypeListItem> list = asList(item1, item2);
view.expandListItems(list);
verify(item1).expand();
verify(item2).expand();
}
Aggregations