Search in sources :

Example 1 with HasComponents

use of com.vaadin.ui.HasComponents in project ANNIS by korpling.

the class IDGenerator method assignID.

public static String assignID(Component c, String fieldName) {
    String id = null;
    if (c != null && fieldName != null && !fieldName.isEmpty()) {
        Preconditions.checkArgument(c.isAttached(), "Component " + c.getConnectorId() + " must be attached before it can get an automatic ID.");
        id = c.getId();
        if (id == null) {
            // try to get the parent ID
            HasComponents parent = c.getParent();
            if (parent == null || parent instanceof UI) {
                // use class name as ID
                id = fieldName;
            } else {
                String parentID = parent.getId();
                if (parentID == null) {
                    parentID = assignID(parent);
                }
                String idBase = parentID + ":" + fieldName;
                // check that no other child has the same ID
                int counter = 1;
                id = idBase;
                while (childHasID(parent, id)) {
                    id = idBase + "." + counter++;
                }
            }
            c.setId(id);
        }
    }
    return id;
}
Also used : UI(com.vaadin.ui.UI) HasComponents(com.vaadin.ui.HasComponents)

Example 2 with HasComponents

use of com.vaadin.ui.HasComponents in project ANNIS by korpling.

the class IDGenerator method assignID.

public static String assignID(Component c, String fieldName) {
    String id = null;
    if (c != null && fieldName != null && !fieldName.isEmpty()) {
        Preconditions.checkArgument(c.isAttached(), "Component " + c.getConnectorId() + " must be attached before it can get an automatic ID.");
        id = c.getId();
        if (id == null) {
            // try to get the parent ID
            HasComponents parent = c.getParent();
            if (parent == null || parent instanceof UI) {
                // use class name as ID
                id = fieldName;
            } else {
                String parentID = parent.getId();
                if (parentID == null) {
                    parentID = assignID(parent);
                }
                String idBase = parentID + "-" + fieldName;
                // check that no other child has the same ID
                int counter = 1;
                id = idBase;
                while (childHasID(parent, id)) {
                    id = idBase + "." + counter++;
                }
            }
            c.setId(id);
        }
    }
    return id;
}
Also used : UI(com.vaadin.ui.UI) HasComponents(com.vaadin.ui.HasComponents)

Example 3 with HasComponents

use of com.vaadin.ui.HasComponents in project opencms-core by alkacon.

the class CmsVaadinUtils method visitDescendants.

/**
 * Visits all descendants of a given component (including the component itself) and applies a predicate
 * to each.<p>
 *
 * If the predicate returns false for a component, no further descendants will be processed.<p>
 *
 * @param component the component
 * @param handler the predicate
 */
public static void visitDescendants(Component component, Predicate<Component> handler) {
    List<Component> stack = Lists.newArrayList();
    stack.add(component);
    while (!stack.isEmpty()) {
        Component currentComponent = stack.get(stack.size() - 1);
        stack.remove(stack.size() - 1);
        if (!handler.apply(currentComponent)) {
            return;
        }
        if (currentComponent instanceof HasComponents) {
            List<Component> children = Lists.newArrayList((HasComponents) currentComponent);
            Collections.reverse(children);
            stack.addAll(children);
        }
    }
}
Also used : AbstractComponent(com.vaadin.ui.AbstractComponent) Component(com.vaadin.ui.Component) HasComponents(com.vaadin.ui.HasComponents)

Example 4 with HasComponents

use of com.vaadin.ui.HasComponents in project charts by vaadin.

the class ChartOptions method searchAndNotifyListeners.

private void searchAndNotifyListeners(Component component) {
    if (component instanceof HasComponents) {
        HasComponents container = (HasComponents) component;
        Iterator<Component> iter = container.iterator();
        while (iter.hasNext()) {
            searchAndNotifyListeners(iter.next());
        }
    } else if (component instanceof Chart) {
        Chart listener = (Chart) component;
        listener.drawChart();
    }
}
Also used : HasComponents(com.vaadin.ui.HasComponents) Component(com.vaadin.ui.Component)

Example 5 with HasComponents

use of com.vaadin.ui.HasComponents in project jmix by jmix-framework.

the class AbstractCanvasLayout method setWeight.

@Override
public void setWeight(int weight) {
    Layout unwrapThis = this.unwrap(Layout.class);
    HasComponents parent = unwrapThis.getParent();
    if (parent instanceof AbstractOrderedLayout) {
        for (com.vaadin.ui.Component child : parent) {
            if (unwrapThis.equals(child)) {
                ((AbstractOrderedLayout) parent).setExpandRatio(unwrapThis, weight);
            } else if (((AbstractOrderedLayout) parent).getExpandRatio(child) == 0) {
                ((AbstractOrderedLayout) parent).setExpandRatio(child, 1);
            }
        }
    }
}
Also used : Layout(com.vaadin.ui.Layout) DashboardLayout(io.jmix.dashboards.model.visualmodel.DashboardLayout) CanvasLayout(io.jmix.dashboardsui.component.CanvasLayout) HBoxLayout(io.jmix.ui.component.HBoxLayout) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout) JmixCssActionsLayout(io.jmix.ui.widget.JmixCssActionsLayout) HasComponents(com.vaadin.ui.HasComponents) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout)

Aggregations

HasComponents (com.vaadin.ui.HasComponents)6 AbstractOrderedLayout (com.vaadin.ui.AbstractOrderedLayout)2 Component (com.vaadin.ui.Component)2 Layout (com.vaadin.ui.Layout)2 UI (com.vaadin.ui.UI)2 DashboardLayout (io.jmix.dashboards.model.visualmodel.DashboardLayout)2 CanvasLayout (io.jmix.dashboardsui.component.CanvasLayout)2 HBoxLayout (io.jmix.ui.component.HBoxLayout)2 JmixCssActionsLayout (io.jmix.ui.widget.JmixCssActionsLayout)2 AbstractComponent (com.vaadin.ui.AbstractComponent)1