use of com.haulmont.cuba.web.widgets.CubaTokenListLabel in project cuba by cuba-platform.
the class CubaTokenList method createToken.
protected CubaTokenListLabel createToken() {
CubaTokenListLabel label = new CubaTokenListLabel();
label.setWidth("100%");
label.addListener((CubaTokenListLabel.RemoveTokenListener) source -> {
if (owner.isEditableWithParent()) {
doRemove(source);
}
});
return label;
}
use of com.haulmont.cuba.web.widgets.CubaTokenListLabel in project cuba by cuba-platform.
the class CubaTokenList method clearValue.
protected void clearValue() {
Collection<T> oldValue = new HashSet<>(getValue());
for (CubaTokenListLabel label : new ArrayList<>(itemComponents.values())) {
T item = componentItems.get(label);
if (item != null) {
itemComponents.remove(item);
componentItems.remove(label);
}
if (owner.itemChangeHandler != null) {
owner.itemChangeHandler.removeItem(item);
}
}
if (owner.itemChangeHandler == null) {
fireValueChangeEvent(oldValue);
}
}
use of com.haulmont.cuba.web.widgets.CubaTokenListLabel in project cuba by cuba-platform.
the class CubaTokenList method updateTokensEditable.
protected void updateTokensEditable() {
if (tokenContainer == null || tokenContainer.getComponentCount() == 0) {
return;
}
boolean editable = owner.isEditableWithParent();
for (int i = 0; i < tokenContainer.getComponentCount(); i++) {
CubaTokenListLabel label = (CubaTokenListLabel) tokenContainer.getComponent(i);
label.setEditable(editable);
}
}
use of com.haulmont.cuba.web.widgets.CubaTokenListLabel in project cuba by cuba-platform.
the class CubaTokenList method refreshTokens.
public void refreshTokens(Collection<T> newValue) {
tokenContainer.removeAllComponents();
if (newValue == null) {
newValue = Collections.emptyList();
}
List<T> usedItems = new ArrayList<>();
for (T entity : newValue) {
CubaTokenListLabel label = itemComponents.get(entity);
if (label == null) {
label = createToken();
itemComponents.put(entity, label);
componentItems.put(label, entity);
}
label.setEditable(owner.isEditableWithParent());
label.setText(owner.getInstanceCaption(entity));
label.setWidthUndefined();
setTokenStyle(label, entity.getId());
tokenContainer.addComponent(label);
usedItems.add(entity);
}
for (T componentItem : new ArrayList<>(itemComponents.keySet())) {
if (!usedItems.contains(componentItem)) {
componentItems.remove(itemComponents.get(componentItem));
itemComponents.remove(componentItem);
}
}
updateTokenContainerVisibility();
updateEditorMargins();
}
Aggregations