public static LayoutClickEvent createEvent(ComponentContainer layout, MouseEventDetails mouseDetails, Connector clickedConnector) { Component clickedComponent = (Component) clickedConnector; Component childComponent = clickedComponent; while (childComponent != null && childComponent.getParent() != layout) { childComponent = childComponent.getParent(); } return new LayoutClickEvent(layout, mouseDetails, clickedComponent, childComponent); } }
@Override public void setWidth(float width, Unit unit) { getRootOrThrow().setWidth(width, unit); }
/** * Adds or removes a style name. Multiple styles can be specified as a * space-separated list of style names. * * If the {@code add} parameter is true, the style name is added to the * component. If the {@code add} parameter is false, the style name is * removed from the component. * <p> * Functionally this is equivalent to using {@link #addStyleName(String)} or * {@link #removeStyleName(String)} * * @since 8.5 * @param style * the style name to be added or removed * @param add * <code>true</code> to add the given style, <code>false</code> * to remove it * @see #addStyleName(String) * @see #removeStyleName(String) */ public default void setStyleName(String style, boolean add) { if (add) { addStyleName(style); } else { removeStyleName(style); } }
private static String getWidthString(Component component) { String width = "width: "; if (hasRelativeWidth(component)) { width += "RELATIVE, " + component.getWidth() + " %"; } else if (component instanceof Window && component.getParent() == null) { width += "MAIN WINDOW"; } else if (component.getWidth() >= 0) { width += "ABSOLUTE, " + component.getWidth() + " " + component.getWidthUnits().getSymbol(); } else { width += "UNDEFINED"; } return width; }
private static String getHeightString(Component component) { String height = "height: "; if (hasRelativeHeight(component)) { height += "RELATIVE, " + component.getHeight() + " %"; } else if (component instanceof Window && component.getParent() == null) { height += "MAIN WINDOW"; } else if (component.getHeight() > 0) { height += "ABSOLUTE, " + component.getHeight() + " " + component.getHeightUnits().getSymbol(); } else { height += "UNDEFINED"; } return height; }
protected void toggleMaximized(final Component panel, final boolean maximized) { if (maximized) { panel.setVisible(true); panel.addStyleName("max"); } else { panel.removeStyleName("max"); } }
@Override public void setCaption(String caption) { getRootOrThrow().setCaption(caption); }
/** * Adds a component to a given vertical layout and applies some sizing and formatting options. * * @param verticalLayout the vertical layout * @param component the component to be added */ private void addToComponent(VerticalLayout verticalLayout, Component component) { HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setWidth(100, Unit.PERCENTAGE); Label label = new Label(component.getCaption()); label.setWidth(200, Unit.PIXELS); component.setSizeFull(); component.setCaption(null); horizontalLayout.addComponent(label); horizontalLayout.addComponent(component); horizontalLayout.setExpandRatio(component, 1.0f); verticalLayout.addComponent(horizontalLayout); }
@Override public void setSizeFull() { getRootOrThrow().setSizeFull(); }
public boolean apply(Component component) { component.setCaption(CmsVaadinUtils.localizeString(component.getCaption())); return true; } });
public static boolean parentCanDefineWidth(Component component) { Component parent = component.getParent(); if (parent == null) { if (parent.getWidth() < 0) { } else if (parent instanceof Window) { return parent.getCaption() != null && !parent.getCaption().isEmpty(); } else if (hasRelativeWidth(parent)) { if (parent.getParent() == null) { return true;
/** * Adds one or more style names to this component by using one or multiple * parameters. * * @param styles * the style name or style names to be added to the component * @see #addStyleName(String) * @see #setStyleName(String) * @see #removeStyleName(String) * @since 8.1 */ public default void addStyleNames(String... styles) { for (String style : styles) { addStyleName(style); } }
@Override public void clearError() { Component el = getComponentError(); if (el == null) return; el.setCaption(""); el.setVisible(false); }
@Override public void buttonClick(final ClickEvent event) { if (getCompositionRoot().getStyleName().contains(STYLE_VISIBLE)) { getCompositionRoot().removeStyleName(STYLE_VISIBLE); } else { getCompositionRoot().addStyleName(STYLE_VISIBLE); } } }
/** * This only implements the events and component parent calls. The extending * classes must implement component list maintenance and call this method * before component list maintenance. * * @see com.vaadin.ui.ComponentContainer#removeComponent(Component) */ @Override public void removeComponent(Component c) { if (equals(c.getParent())) { c.setParent(null); fireComponentDetachEvent(c); markAsDirty(); } }
/** * Initializes the label for the file path display {@link #m_filePathLabel}. */ private void initFilePathLabel() { m_filePathLabel = new TextField(); m_filePathLabel.setWidth("100%"); m_filePathLabel.setEnabled(true); m_filePathLabel.setReadOnly(true); m_filePathLabel = new Label(m_messages.key(Messages.GUI_FILENAME_LABEL_0)); }
@Override public void setIcon(String icon) { this.icon = icon; if (StringUtils.isNotEmpty(icon)) { Resource iconResource = getIconResource(icon); getComposition().setIcon(iconResource); getComposition().addStyleName(ICON_STYLE); } else { getComposition().setIcon(null); getComposition().removeStyleName(ICON_STYLE); } }
/** * Generates an error message when the client is trying to to something * ('what') with a connector which is disabled or invisible. * * @since 7.1.8 * @param connector * the connector which is disabled (or invisible) * @return an error message */ public static String getIgnoredDisabledError(String what, ClientConnector connector) { String msg = "Ignoring " + what + " for disabled connector " + connector.getClass().getName(); if (connector instanceof Component) { String caption = ((Component) connector).getCaption(); if (caption != null) { msg += ", caption=" + caption; } } return msg; } }