Search in sources :

Example 1 with CubaTokenListLabel

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;
}
Also used : CustomField(com.vaadin.ui.CustomField) CubaTokenListLabel(com.haulmont.cuba.web.widgets.CubaTokenListLabel) java.util(java.util) TokenList(com.haulmont.cuba.gui.components.TokenList) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) CssLayout(com.vaadin.ui.CssLayout) MarginInfo(com.vaadin.shared.ui.MarginInfo) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Button(com.vaadin.ui.Button) Subscription(com.haulmont.bali.events.Subscription) Instance(com.haulmont.chile.core.model.Instance) CubaScrollBoxLayout(com.haulmont.cuba.web.widgets.CubaScrollBoxLayout) Entity(com.haulmont.cuba.core.entity.Entity) Component(com.vaadin.ui.Component) CubaTokenListLabel(com.haulmont.cuba.web.widgets.CubaTokenListLabel)

Example 2 with CubaTokenListLabel

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);
    }
}
Also used : CubaTokenListLabel(com.haulmont.cuba.web.widgets.CubaTokenListLabel)

Example 3 with CubaTokenListLabel

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);
    }
}
Also used : CubaTokenListLabel(com.haulmont.cuba.web.widgets.CubaTokenListLabel)

Example 4 with CubaTokenListLabel

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();
}
Also used : CubaTokenListLabel(com.haulmont.cuba.web.widgets.CubaTokenListLabel)

Aggregations

CubaTokenListLabel (com.haulmont.cuba.web.widgets.CubaTokenListLabel)4 Subscription (com.haulmont.bali.events.Subscription)1 Instance (com.haulmont.chile.core.model.Instance)1 Entity (com.haulmont.cuba.core.entity.Entity)1 TokenList (com.haulmont.cuba.gui.components.TokenList)1 ValueSource (com.haulmont.cuba.gui.components.data.ValueSource)1 CubaScrollBoxLayout (com.haulmont.cuba.web.widgets.CubaScrollBoxLayout)1 MarginInfo (com.vaadin.shared.ui.MarginInfo)1 Button (com.vaadin.ui.Button)1 Component (com.vaadin.ui.Component)1 CssLayout (com.vaadin.ui.CssLayout)1 CustomField (com.vaadin.ui.CustomField)1 java.util (java.util)1 CollectionUtils (org.apache.commons.collections4.CollectionUtils)1