Example usage for com.vaadin.ui Component getParent

List of usage examples for com.vaadin.ui Component getParent

Introduction

In this page you can find the example usage for com.vaadin.ui Component getParent.

Prototype

@Override
public HasComponents getParent();

Source Link

Document

Gets the parent component of the component.

Usage

From source file:jp.primecloud.auto.ui.ServiceTable.java

License:Open Source License

public ServiceTable(String caption, Container container, MyCloudTabs sender) {
    super(caption, container);
    this.sender = sender;
    setVisibleColumns(new Object[] {});

    setWidth("100%");
    setHeight("100%");

    setPageLength(0);//  www  . ja va 2s. co m
    setSortDisabled(true);
    setColumnReorderingAllowed(false);
    setColumnCollapsingAllowed(false);
    setSelectable(true);
    setMultiSelect(false);
    setImmediate(true);
    setNullSelectionAllowed(false);
    setStyleName("service-table");

    addGeneratedColumn("no", new ColumnGenerator() {
        public Component generateCell(Table source, Object itemId, Object columnId) {
            ComponentDto p = (ComponentDto) itemId;
            Label nlbl = new Label(String.valueOf(p.getComponent().getComponentNo()));
            return nlbl;
        }
    });

    addGeneratedColumn("name", new ColumnGenerator() {
        public Component generateCell(Table source, Object itemId, Object columnId) {
            ComponentDto p = (ComponentDto) itemId;
            String name;
            if (StringUtils.isEmpty(p.getComponent().getComment())) {
                name = p.getComponent().getComponentName();
            } else {
                name = p.getComponent().getComment() + "\n[" + p.getComponent().getComponentName() + "]";
            }
            Label nlbl = new Label(name, Label.CONTENT_PREFORMATTED);
            return nlbl;
        }
    });
    //???
    addGeneratedColumn("srvs", new ColumnGenerator() {
        public Component generateCell(Table source, Object itemId, Object columnId) {
            ComponentDto p = (ComponentDto) itemId;
            int srvs = 0;
            for (ComponentInstanceDto componentInstance : p.getComponentInstances()) {
                if (BooleanUtils.isTrue(componentInstance.getComponentInstance().getAssociate())) {
                    srvs++;
                }
            }
            Label lbl = new Label(Integer.toString(srvs));
            return lbl;
        }
    });

    addGeneratedColumn("status", new ColumnGenerator() {
        public Component generateCell(Table source, Object itemId, Object columnId) {
            ComponentDto p = (ComponentDto) itemId;
            String a = p.getStatus().substring(0, 1).toUpperCase() + p.getStatus().substring(1).toLowerCase();

            Icons icon = Icons.fromName(a);
            Label slbl = new Label("<img src=\"" + VaadinUtils.getIconPath(ServiceTable.this, icon) + "\"><div>"
                    + a + "</div>", Label.CONTENT_XHTML);
            slbl.setHeight(COLUMN_HEIGHT);

            return slbl;
        }
    });

    addGeneratedColumn("loadBalancer", new ColumnGenerator() {
        public Component generateCell(Table source, Object itemId, Object columnId) {

            ComponentDto dto = (ComponentDto) itemId;

            MyCloudTabs myCloudTabs = null;
            Component c = ServiceTable.this;
            while (c != null) {
                if (c instanceof MyCloudTabs) {
                    myCloudTabs = (MyCloudTabs) c;
                    break;
                }
                c = c.getParent();
            }
            Button btn = null;
            for (LoadBalancerDto lbDto : (Collection<LoadBalancerDto>) myCloudTabs.loadBalancerTable
                    .getItemIds()) {
                if (dto.getComponent().getComponentNo().equals(lbDto.getLoadBalancer().getComponentNo())) {
                    btn = getLoadBalancerButton(lbDto);
                    break;
                }
            }
            if (btn != null) {
                return btn;
            } else {
                return (new Label(""));
            }
        }

    });

    addGeneratedColumn("serviceDetail", new ColumnGenerator() {
        public Component generateCell(Table source, Object itemId, Object columnId) {
            ComponentDto p = (ComponentDto) itemId;
            ComponentType componentType = p.getComponentType();

            // ??
            String name = componentType.getComponentTypeNameDisp();
            Icons nameIcon = Icons.fromName(componentType.getComponentTypeName());

            Label slbl = new Label("<img src=\"" + VaadinUtils.getIconPath(ServiceTable.this, nameIcon)
                    + "\"><div>" + name + "</div>", Label.CONTENT_XHTML);
            slbl.setHeight(COLUMN_HEIGHT);
            return slbl;

        }
    });

    //???
    setColumnHeaders(CAPNAME);

    //????StyleName
    setCellStyleGenerator(new Table.CellStyleGenerator() {
        public String getStyle(Object itemId, Object propertyId) {

            if (propertyId == null) {
                return "";
            } else {
                return propertyId.toString().toLowerCase();
            }
        }
    });

    setColumnExpandRatio("serviceDetail", 100);

    addListener(Table.ValueChangeEvent.class, sender, "tableRowSelected");
}

From source file:jp.primecloud.auto.ui.ServiceTable.java

License:Open Source License

void loadBalancerButtonClick(ClickEvent event) {
    Button btn = event.getButton();
    LoadBalancerDto dto = (LoadBalancerDto) btn.getData();

    MyCloudTabs myCloudTabs = null;//  w  w w .  j a v a  2 s .  c  om
    Component c = ServiceTable.this;
    while (c != null) {
        if (c instanceof MyCloudTabs) {
            myCloudTabs = (MyCloudTabs) c;
            break;
        }
        c = c.getParent();
    }
    //??
    myCloudTabs.loadBalancerTable.select(dto);
    //?Tab?
    myCloudTabs.tabDesc.setSelectedTab(myCloudTabs.pnLoadBalancer);
}

From source file:jp.primecloud.auto.ui.util.VaadinUtils.java

License:Open Source License

/**
 * TODO: /*  w w  w. j a  v  a 2  s  . c  o m*/
 *
 * @param component
 * @return
 */
public static Application getApplication(Component component) {
    Application application = null;
    while (component != null) {
        if (component instanceof Window) {
            application = ((Window) component).getApplication();
            break;
        }
        component = component.getParent();
    }
    return application;
}

From source file:lifetime.component.welcome.register.OKButton.java

License:Apache License

protected RegistrationForm getRegistrationForm() {
    Component view = getParent();

    while (!(view instanceof RegisterView)) {
        view = view.getParent();
    }/*from w ww  .ja v  a  2  s. com*/

    RegisterView rView = (RegisterView) view;
    return rView.getContent().getRegistrationForm();
}

From source file:lifetime.component.welcome.register.RegisterMenu.java

License:Apache License

public RegistrationForm getRegistrationForm() {
    Component parent = getParent();
    if (parent != null) {
        while (!(parent instanceof RegisterView)) {
            parent = parent.getParent();
        }/*ww  w . j av a2  s.co m*/
        RegisterView registerView = (RegisterView) parent;
        return registerView.getContent().getRegistrationForm();
    } else {
        return null;
    }
}

From source file:nz.co.senanque.vaadinsupport.FieldFactory.java

License:Apache License

private MaduraForm getParentForm(AbstractField field) {
    Component parent = field.getParent();
    while (parent != null) {
        parent = parent.getParent();
        if (parent instanceof MaduraForm) {
            break;
        }//w ww  .ja v a  2 s . c  o m
    }
    return (MaduraForm) parent;
}

From source file:org.escidoc.browser.ui.view.helpers.CloseTabsViewHelper.java

License:Open Source License

/**
 * Recursive procedure to find the parent of a Layout that is a TabSheet
 * //from  ww  w  .  j  a v  a  2  s. co  m
 * @param son
 * @return
 * @throws NullPointerException
 */
private Component getParent(Component son) throws NullPointerException {
    Component father;
    if (son.getParent().getClass().toString().equals("class com.vaadin.ui.TabSheet")) {
        return son.getParent();
    } else {
        father = getParent(son.getParent());
    }
    return father;
}

From source file:org.jdal.vaadin.ui.ComponentViewAdapter.java

License:Apache License

public ComponentViewAdapter(Component component) {
    if (component.getParent() != null) {
        component.setParent(null);/*w  w  w. jav a 2s  . com*/
    }

    setCompositionRoot(component);
}

From source file:org.jdal.vaadin.VaadinUtils.java

License:Apache License

/**
 * Return the window where a component is attached
 * @param component//from  w  w  w  . ja  v  a 2  s . co  m
 * @return the window or null if none
 */
public static Window getWindow(Component component) {
    while (component.getParent() != null) {
        if (component.getParent() instanceof Window)
            return (Window) component.getParent();

        component = component.getParent();
    }

    return null;
}

From source file:org.lucidj.browser.BrowserView.java

License:Apache License

private void unfocus(Component component) {
    Component parent = component.getParent();

    while (parent != null) {
        if (parent instanceof Component.Focusable) {
            ((Component.Focusable) parent).focus();
            break;
        } else {/*from   ww w  . jav  a2  s . c om*/
            parent = parent.getParent();
        }
    }
}