use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.
the class BeanTableModelImpl method getNewData.
private Map<Integer, ArrayList<IBeanProxy<BEAN_TYPE>>> getNewData(final Set<IBeanProxy<BEAN_TYPE>> oldSelection, final List<Integer> newSelection, final Iterable<? extends IBeanDto> beans, final List<IBeanProxy<BEAN_TYPE>> removedBeanProxies) {
// hold the beans that should be deleted but that are currently not deleted
final Set<IBeanDto> beansToDelete = CollectionUtils.createHashSet(beans);
final Map<Integer, ArrayList<IBeanProxy<BEAN_TYPE>>> newData = new HashMap<Integer, ArrayList<IBeanProxy<BEAN_TYPE>>>();
int newPageIndex = 0;
ArrayList<IBeanProxy<BEAN_TYPE>> newPage = new ArrayList<IBeanProxy<BEAN_TYPE>>(pageSize);
final int pageCount = getPage(dataModel.getDataRowCount()) + 1;
int addedNullCount = 0;
final List<IBeanProxy<BEAN_TYPE>> beansToUnregister = new LinkedList<IBeanProxy<BEAN_TYPE>>();
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
final ArrayList<IBeanProxy<BEAN_TYPE>> page = data.get(pageIndex);
// add a regular page
if (page != null) {
for (final IBeanProxy<BEAN_TYPE> bean : page) {
final boolean deletedBeanRemoved = beansToDelete.remove(bean);
if (deletedBeanRemoved) {
beansToUnregister.add(bean);
removedBeanProxies.add(bean);
rowCountOfPages--;
if (countedRowCount != null) {
countedRowCount = Integer.valueOf(countedRowCount.intValue() - 1);
}
} else if (newPage.size() < pageSize && addedNullCount < pageSize) {
newPage.add(bean);
} else {
if (addedNullCount < pageSize) {
newData.put(newPageIndex, newPage);
}
newPageIndex++;
newPage = new ArrayList<IBeanProxy<BEAN_TYPE>>(pageSize);
newPage.add(bean);
}
if (oldSelection.remove(bean)) {
if (!deletedBeanRemoved) {
newSelection.add(newPageIndex * pageSize + newPage.size() - 1);
}
}
if (bean == null) {
addedNullCount++;
} else {
addedNullCount = 0;
}
}
} else // add a null page (add 'pageSize' times a 'null')
if (addedNullCount < pageSize) {
for (int i = 0; i < pageSize; i++) {
if (newPage.size() < pageSize) {
newPage.add(null);
addedNullCount++;
} else {
if (addedNullCount < pageSize) {
newData.put(newPageIndex, newPage);
}
newPageIndex++;
newPage = new ArrayList<IBeanProxy<BEAN_TYPE>>(pageSize);
newPage.add(null);
addedNullCount++;
}
}
} else // skip the page
// (there a more than one page of null's added, so the page can be skipped)
{
newPage = new ArrayList<IBeanProxy<BEAN_TYPE>>(pageSize);
newPageIndex++;
addedNullCount = addedNullCount + pageSize;
}
}
beansStateTracker.unregister(beansToUnregister);
// add the last new page if it has data
if (newPage.size() > 0) {
newData.put(newPageIndex, newPage);
}
return newData;
}
use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.
the class BeanTableModelImpl method addBeanDtos.
@Override
public List<IBeanProxy<BEAN_TYPE>> addBeanDtos(final Collection<? extends IBeanDto> beanDtos, final boolean sorted) {
Assert.paramNotNull(beanDtos, "beanDtos");
final List<IBeanProxy<BEAN_TYPE>> proxies = new ArrayList<IBeanProxy<BEAN_TYPE>>(beanDtos.size());
for (final IBeanDto beanDto : beanDtos) {
final IBeanProxy<BEAN_TYPE> beanProxy = createBeanProxy(beanDto);
proxies.add(beanProxy);
}
addBeans(proxies, sorted);
return proxies;
}
use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.
the class BeanTableModelImpl method addBeansSorted.
private void addBeansSorted(final Collection<IBeanProxy<BEAN_TYPE>> beansToAdd) {
final List<IBeanProxy<BEAN_TYPE>> selectedBeans = getSelectedBeans();
final Comparator<IBeanDto> comparator = BeanDtoComparator.create(sortModel.getSorting());
final ListIterator<IBeanProxy<BEAN_TYPE>> addedDataIterator = addedData.listIterator();
boolean beanListenerIndicesStale = false;
for (final IBeanProxy<BEAN_TYPE> bean : beansToAdd) {
while (addedDataIterator.hasNext()) {
final IBeanProxy<BEAN_TYPE> nextBean = addedDataIterator.next();
final int compare = comparator.compare(bean, nextBean);
if (compare < 0) {
addedDataIterator.previous();
break;
} else if (beanListenerIndicesStale) {
updateRowIndexOfBean(bean, rowCountOfPages + addedDataIterator.previousIndex());
}
}
addedDataIterator.add(bean);
beanListenerIndicesStale = true;
final int rowIndex = rowCountOfPages + addedDataIterator.previousIndex();
bean.addPropertyChangeListener(new BeanPropertyChangeListener(rowIndex));
}
beansStateTracker.register(beansToAdd);
cachedReaderService.addBeans(getParentBeanKeys(), new HashSet<IBeanProxy<BEAN_TYPE>>(beansToAdd));
setSelectedBeans(selectedBeans);
}
use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.
the class BeanTableModelImpl method removeSelection.
private List<IBeanProxy<BEAN_TYPE>> removeSelection() {
final List<IBeanProxy<BEAN_TYPE>> result = new LinkedList<IBeanProxy<BEAN_TYPE>>();
final List<Integer> currentSelection = getSelection();
if (!currentSelection.isEmpty()) {
for (final Integer index : currentSelection) {
final int selectedIndex = index.intValue();
final IBeanProxy<BEAN_TYPE> selectedBean = getBean(selectedIndex);
if (selectedBean != null && !selectedBean.isDummy()) {
result.add(selectedBean);
}
}
dataModel.removeDataModelListener(tableDataModelListener);
final List<Integer> emptySelection = Collections.emptyList();
setSelection(emptySelection);
dataModel.addDataModelListener(tableDataModelListener);
fireSelectionChanged();
}
return result;
}
use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.
the class BeanLinkCreatorCommand method getBeanLink.
private IBeanLink<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE> getBeanLink(final IExecutionContext executionContext) {
final ICapApiBluePrintFactory cbpf = CapUiToolkit.bluePrintFactory();
final IBeanLinkPanelBluePrint<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE> linkPanelBp = cbpf.beanLinkPanel();
linkPanelBp.setLinkBeanForm(linkBeanForm);
linkPanelBp.setLinkableBeanForm(linkableBeanForm);
linkPanelBp.setLinkableTable(linkableTable);
final IBeanLinkDialogBluePrint<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE> dialogBp = cbpf.beanLinkDialog(linkPanelBp);
dialogBp.setMinPackSize(new Dimension(800, 600));
dialogBp.setMaxPackSize(new Dimension(1600, 1000));
dialogBp.setExecutionContext(executionContext);
dialogBp.setMissingInputHint(null);
dialogBp.setContentScrolled(false);
if (dialogBounds != null) {
dialogBp.setPosition(dialogBounds.getPosition()).setSize(dialogBounds.getSize());
dialogBp.autoPackOff().autoCenterOff();
}
final IBeanLinkDialog<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE> linkDialog;
linkDialog = Toolkit.getActiveWindow().createChildWindow(dialogBp);
final IBeanProxy<LINK_BEAN_TYPE> defaultLinkBean;
if (linkDefaultFactory != null) {
defaultLinkBean = linkDefaultFactory.create();
} else {
defaultLinkBean = createDefaultBean(linkBeanForm, linkBeanTypeId, linkBeanType, linkBeanPropertyValidators);
}
final List<IBeanProxy<LINKABLE_BEAN_TYPE>> defaultLinkedBeans;
if (linkableBeanForm != null) {
defaultLinkedBeans = Collections.singletonList(createDefaultBean(linkableBeanForm, linkableBeanTypeId, linkableBeanType, linkableBeanPropertyValidators));
} else {
defaultLinkedBeans = Collections.emptyList();
}
linkDialog.setValue(new IBeanLink<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE>() {
@Override
public IBeanProxy<LINK_BEAN_TYPE> getLinkBean() {
return defaultLinkBean;
}
@Override
public List<IBeanProxy<LINKABLE_BEAN_TYPE>> getLinkableBeans() {
return defaultLinkedBeans;
}
});
linkDialog.setVisible(true);
final IBeanLink<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE> result;
if (linkDialog.isOkPressed()) {
final IBeanLink<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE> dialogValue = linkDialog.getValue();
result = new IBeanLink<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE>() {
@Override
public IBeanProxy<LINK_BEAN_TYPE> getLinkBean() {
final IBeanProxy<LINK_BEAN_TYPE> original = dialogValue.getLinkBean();
return original != null ? original : defaultLinkBean;
}
@Override
public List<IBeanProxy<LINKABLE_BEAN_TYPE>> getLinkableBeans() {
return dialogValue.getLinkableBeans();
}
};
} else {
result = null;
}
dialogBounds = linkDialog.getBounds();
linkDialog.dispose();
return result;
}
Aggregations