Search in sources :

Example 1 with ISort

use of org.jowidgets.cap.common.api.sort.ISort in project jo-client-platform by jo-source.

the class BeanTableAttributeListImpl method updateValues.

void updateValues(final IBeanTableModelConfig currentConfig) {
    eventsDisabled = true;
    currentSortingModel.clearSortIndices();
    defaultSortingModel.clearSortIndices();
    for (final Entry<String, AttributeComposite> entry : attributeComposites.entrySet()) {
        final AttributeComposite composite = entry.getValue();
        composite.updateValues(currentConfig);
    }
    int index = 0;
    for (final ISort sort : currentConfig.getSortModelConfig().getCurrentSorting()) {
        final AttributeComposite composite = attributeComposites.get(sort.getPropertyName());
        if (composite.isSortable()) {
            composite.getCurrentSorting().setValue(ComboBoxSortOrder.convert(sort.getSortOrder()));
            composite.getCurrentSortingIndex().setIndex(index + 1);
        }
        index++;
    }
    index = 0;
    for (final ISort sort : currentConfig.getSortModelConfig().getDefaultSorting()) {
        final AttributeComposite composite = attributeComposites.get(sort.getPropertyName());
        if (composite.isSortable()) {
            composite.getDefaultSorting().setValue(ComboBoxSortOrder.convert(sort.getSortOrder()));
            composite.getDefaultSortingIndex().setIndex(index + 1);
        }
        index++;
    }
    currentSortingModel.sortingLength = currentConfig.getSortModelConfig().getCurrentSorting().size();
    currentSortingModel.updateSortingIndexRanges();
    defaultSortingModel.sortingLength = currentConfig.getSortModelConfig().getDefaultSorting().size();
    defaultSortingModel.updateSortingIndexRanges();
    eventsDisabled = false;
    updateHeaders();
}
Also used : ISort(org.jowidgets.cap.common.api.sort.ISort) ITextLabelBluePrint(org.jowidgets.api.widgets.blueprint.ITextLabelBluePrint)

Example 2 with ISort

use of org.jowidgets.cap.common.api.sort.ISort in project jo-client-platform by jo-source.

the class BeanTableModelImplTest method testBeanChangeUpdate.

@Test
public void testBeanChangeUpdate() {
    tableModel.getSortModel().setCurrentSorting(Arrays.asList(new ISort() {

        @Override
        public SortOrder getSortOrder() {
            return SortOrder.ASC;
        }

        @Override
        public String getPropertyName() {
            return "key";
        }
    }));
    tableModel.load();
    triggerPageLoading();
    final IUpdatableResultCallback<IBeanDtosUpdate, List<IBeanDto>> updatableCallback = assertUpdatableResultCallback(resultCallback);
    updatableCallback.finished(new ArrayList<IBeanDto>());
    updatableCallback.update(new BeanDtosInsertionUpdate(Arrays.asList((IBeanDto) bean1, (IBeanDto) bean2)));
    updatableCallback.update(new BeanDtosChangeUpdate(Arrays.asList((IBeanDto) bean1a)));
    final int size = tableModel.getSize();
    assertTrue("2 beans should be loaded, but was " + size, size == 2);
    assertTrue("first bean should be changed by update", tableModel.getBean(0).getValue("value").equals(bean1a.getValue("value")));
    assertTrue("second bean should be unchanged by update", tableModel.getBean(1).getValue("value").equals(bean2.getValue("value")));
}
Also used : BeanDtosChangeUpdate(org.jowidgets.cap.common.tools.bean.BeanDtosChangeUpdate) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ISort(org.jowidgets.cap.common.api.sort.ISort) IBeanDtosUpdate(org.jowidgets.cap.common.api.bean.IBeanDtosUpdate) BeanDtosInsertionUpdate(org.jowidgets.cap.common.tools.bean.BeanDtosInsertionUpdate) Test(org.junit.Test)

Example 3 with ISort

use of org.jowidgets.cap.common.api.sort.ISort in project jo-client-platform by jo-source.

the class BeanDtoComparatorImpl method compare.

@Override
public int compare(final IBeanDto firstBeanDto, final IBeanDto secondBeanDto) {
    int result = 0;
    for (final ISort sort : sorting) {
        final String propertyName = sort.getPropertyName();
        final SortOrder sortOrder = sort.getSortOrder();
        if (null != sortOrder) {
            if (sortOrder.equals(SortOrder.ASC)) {
                result = compareWithCast(firstBeanDto, secondBeanDto, result, propertyName);
            } else if (sortOrder.equals(SortOrder.DESC)) {
                result = -1 * compareWithCast(firstBeanDto, secondBeanDto, result, propertyName);
            }
        }
        if (result != 0) {
            return result;
        }
    }
    return result;
}
Also used : SortOrder(org.jowidgets.cap.common.api.sort.SortOrder) ISort(org.jowidgets.cap.common.api.sort.ISort)

Example 4 with ISort

use of org.jowidgets.cap.common.api.sort.ISort in project jo-client-platform by jo-source.

the class BeanTableModelImplTest method testBeanChangeUpdateWithChangedPositionInSorting.

@Test
public void testBeanChangeUpdateWithChangedPositionInSorting() {
    tableModel.getSortModel().setCurrentSorting(Arrays.asList(new ISort() {

        @Override
        public SortOrder getSortOrder() {
            return SortOrder.DESC;
        }

        @Override
        public String getPropertyName() {
            return "value";
        }
    }));
    tableModel.load();
    triggerPageLoading();
    final IUpdatableResultCallback<IBeanDtosUpdate, List<IBeanDto>> updatableCallback = assertUpdatableResultCallback(resultCallback);
    updatableCallback.finished(new ArrayList<IBeanDto>());
    updatableCallback.update(new BeanDtosInsertionUpdate(Arrays.asList((IBeanDto) bean2, (IBeanDto) bean1)));
    updatableCallback.update(new BeanDtosChangeUpdate(Arrays.asList((IBeanDto) bean1a)));
    assertTrue("2 beans should be loaded, but was " + tableModel.getSize(), tableModel.getSize() == 2);
    assertTrue("the updated bean should be first now", tableModel.getBean(0).getValue("value").equals(bean1a.getValue("value")));
    assertTrue("the previously first bean should now be second", tableModel.getBean(1).getValue("value").equals(bean2.getValue("value")));
}
Also used : BeanDtosChangeUpdate(org.jowidgets.cap.common.tools.bean.BeanDtosChangeUpdate) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ISort(org.jowidgets.cap.common.api.sort.ISort) IBeanDtosUpdate(org.jowidgets.cap.common.api.bean.IBeanDtosUpdate) BeanDtosInsertionUpdate(org.jowidgets.cap.common.tools.bean.BeanDtosInsertionUpdate) Test(org.junit.Test)

Example 5 with ISort

use of org.jowidgets.cap.common.api.sort.ISort in project jo-client-platform by jo-source.

the class BeanTableModelImplTest method testBeanDeletionUpdate.

@Test
public void testBeanDeletionUpdate() {
    tableModel.getSortModel().setCurrentSorting(Arrays.asList(new ISort() {

        @Override
        public SortOrder getSortOrder() {
            return SortOrder.ASC;
        }

        @Override
        public String getPropertyName() {
            return "key";
        }
    }));
    tableModel.load();
    triggerPageLoading();
    final IUpdatableResultCallback<IBeanDtosUpdate, List<IBeanDto>> updatableCallback = assertUpdatableResultCallback(resultCallback);
    updatableCallback.finished(new ArrayList<IBeanDto>());
    updatableCallback.update(new BeanDtosInsertionUpdate(Arrays.asList((IBeanDto) bean1, (IBeanDto) bean2)));
    updatableCallback.update(new BeanDtosDeletionUpdate(Arrays.asList(bean1.getId())));
    final int size = tableModel.getSize();
    assertTrue("Only 1 beans should be loaded, but was " + size, size == 1);
    assertTrue("bean2 should be left", tableModel.getBean(0).getValue("value").equals(bean2.getValue("value")));
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) BeanDtosDeletionUpdate(org.jowidgets.cap.common.tools.bean.BeanDtosDeletionUpdate) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ISort(org.jowidgets.cap.common.api.sort.ISort) IBeanDtosUpdate(org.jowidgets.cap.common.api.bean.IBeanDtosUpdate) BeanDtosInsertionUpdate(org.jowidgets.cap.common.tools.bean.BeanDtosInsertionUpdate) Test(org.junit.Test)

Aggregations

ISort (org.jowidgets.cap.common.api.sort.ISort)6 LinkedList (java.util.LinkedList)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)3 IBeanDtosUpdate (org.jowidgets.cap.common.api.bean.IBeanDtosUpdate)3 BeanDtosInsertionUpdate (org.jowidgets.cap.common.tools.bean.BeanDtosInsertionUpdate)3 Test (org.junit.Test)3 SortOrder (org.jowidgets.cap.common.api.sort.SortOrder)2 BeanDtosChangeUpdate (org.jowidgets.cap.common.tools.bean.BeanDtosChangeUpdate)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Order (javax.persistence.criteria.Order)1 ITextLabelBluePrint (org.jowidgets.api.widgets.blueprint.ITextLabelBluePrint)1 BeanDtosDeletionUpdate (org.jowidgets.cap.common.tools.bean.BeanDtosDeletionUpdate)1