private void updateButtonState(Object newValue) { if (newValue == null) { setButtonEnabled(back, false); setButtonEnabled(forward, false); return; } Object first = getContainerDataSource().firstItemId(); Object last = getContainerDataSource().lastItemId(); if (!newValue.equals(first) && !newValue.equals(last)) { setButtonEnabled(back, true); setButtonEnabled(forward, true); } else if (newValue.equals(first)) { setButtonEnabled(back, false); setButtonEnabled(forward, true); } else { setButtonEnabled(back, true); setButtonEnabled(forward, false); } }
@Override public boolean isFirstId(Object itemId) { if (ordered) { return ((Container.Ordered) container).isFirstId(itemId); } return first != null && first.equals(itemId); }
@Override public boolean isLastId(Object itemId) { if (ordered) { return ((Container.Ordered) container).isLastId(itemId); } return last != null && last.equals(itemId); }
private void updateItemDescription() { String description = null; final Object itemId = getValue(); final Item item = getContainerDataSource().getItem(itemId); boolean isDescriptionBlank = true; if (item != null) { Property property = item.getItemProperty(descriptionPropertyName); if (property != null && property.getValue() != null) { description = property.getValue().toString(); } isDescriptionBlank = StringUtils.isBlank(description); descriptionLabel.setValue(isDescriptionBlank ? "" : description); } if (isDescriptionBlank) { mainLayout.removeStyleName("has-description"); } else { mainLayout.addStyleName("has-description"); } descriptionLabel.setVisible(!isDescriptionBlank); } }
@SuppressWarnings({"unchecked", "rawtypes"}) @Override public Class getType() { if (fieldType == null) { try { fieldType = (Class<T>) ((Container.Ordered) select .getContainerDataSource()).firstItemId().getClass(); } catch (Exception e) { // If field type isn't set or can't be detected just report // Object, should be fine in most cases (vaadin will just // assign value without conversion. return Object.class; } } return fieldType; }
/** * Adds new item after the given item. * * @see Container.Ordered#addItemAfter(java.lang.Object, java.lang.Object) */ @Override public Item addItemAfter(Object previousItemId, Object newItemId) throws UnsupportedOperationException { Item item = ((Container.Ordered) items).addItemAfter(previousItemId, newItemId); if (!(items instanceof Container.ItemSetChangeNotifier)) { refreshRowCache(); } return item; }
/** * Since the item set changed - the indices in the state might now point to the different items. * Since we know which items to select via {@code selectedIds}, we can update the indices in state as well. */ private void synchroniseSelection() { final List<Integer> formerSelectedIndices = getState().selection.selectedIndices; getState().selection.toggleSelection(-1); for (Object id : formerSelectedIndices) { if (getContainerDataSource().containsId(id)) { handleSelectionAtIndex(container.indexOfId(id), true); } } updateSelectedIds(); fireSelectionChange(); }
/** * Adds new item after the given item. * * @see Container.Ordered#addItemAfter(java.lang.Object) */ @Override public Object addItemAfter(Object previousItemId) throws UnsupportedOperationException { Object itemId = ((Container.Ordered) items) .addItemAfter(previousItemId); if (!(items instanceof Container.ItemSetChangeNotifier)) { refreshRowCache(); } return itemId; }
/** * Gets the ID of the first Item in the Container. * * @see Container.Ordered#firstItemId() */ @Override public Object firstItemId() { return ((Container.Ordered) items).firstItemId(); }
@Override public Object prevItemId(Object itemId) { if (ordered) { return ((Container.Ordered) container).prevItemId(itemId); } if (itemId == null) { return null; } return prev.get(itemId); }
@Override public Object lastItemId() { if (ordered) { return ((Container.Ordered) container).lastItemId(); } return last; }
@Override public Object nextItemId(Object itemId) { if (ordered) { return ((Container.Ordered) container).nextItemId(itemId); } if (itemId == null) { return null; } return next.get(itemId); }
@Override public Object firstItemId() { if (ordered) { return ((Container.Ordered) container).firstItemId(); } return first; }
/** * Gets the ID of the last Item in the Container. * * @see Container.Ordered#lastItemId() */ @Override public Object lastItemId() { return ((Container.Ordered) items).lastItemId(); }
/** * Gets the ID of the Item preceding the Item that corresponds to the * itemId. * * @see Container.Ordered#prevItemId(java.lang.Object) */ @Override public Object prevItemId(Object itemId) { return ((Container.Ordered) items).prevItemId(itemId); }
/** * Tests if the Item corresponding to the given Item ID is the last Item in * the Container. * * @see Container.Ordered#isLastId(java.lang.Object) */ @Override public boolean isLastId(Object itemId) { return ((Container.Ordered) items).isLastId(itemId); }
/** * Gets the ID of the Item following the Item that corresponds to itemId. * * @see Container.Ordered#nextItemId(java.lang.Object) */ @Override public Object nextItemId(Object itemId) { return ((Container.Ordered) items).nextItemId(itemId); }
/** * Tests if the Item corresponding to the given Item ID is the first Item in * the Container. * * @see Container.Ordered#isFirstId(java.lang.Object) */ @Override public boolean isFirstId(Object itemId) { return ((Container.Ordered) items).isFirstId(itemId); }
/** * Sets the previous value - if the current value is not the first available in the set. */ public void goBack() { Object currentItemId = combobox.getValue(); if (getContainerDataSource().isFirstId(currentItemId)) { return; } setValue(getContainerDataSource().prevItemId(currentItemId)); }
/** * Sets the next value - if the current value is not the last available in the set. */ public void goForward() { Object currentItemId = combobox.getValue(); if (getContainerDataSource().isLastId(currentItemId)) { return; } setValue(getContainerDataSource().nextItemId(currentItemId)); }