com.holonplatform.vaadin7.internal.components.DefaultComponentContainerComposer Maven / Gradle / Ivy
/*
* Copyright 2000-2017 Holon TDCN.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.holonplatform.vaadin7.internal.components;
import com.holonplatform.vaadin7.components.PropertyValueComponentSource;
import com.holonplatform.vaadin7.components.ComposableComponent.Composer;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
/**
* Default {@link Composer} using a {@link ComponentContainer} as composition layout and adding the componens to the
* layout in the order they are returned from the a {@link PropertyValueComponentSource}.
*
* Provides a construction parameter to automatically set all composed components to full width.
*
*
* @since 5.0.0
*/
public class DefaultComponentContainerComposer implements Composer {
private final boolean fullWidthComponents;
/**
* Constructor
* @param fullWidthComponents true
to set the width for all composed components as 100%
.
*/
public DefaultComponentContainerComposer(boolean fullWidthComponents) {
super();
this.fullWidthComponents = fullWidthComponents;
}
/**
* Gets whether to set the width for all composed components as 100%
.
* @return true
if the components width must be setted to 100%
*/
protected boolean isFullWidthComponents() {
return fullWidthComponents;
}
/*
* (non-Javadoc)
* @see com.holonplatform.vaadin.components.ComposableComponent.Composer#compose(com.vaadin.ui.Component,
* java.lang.Object)
*/
@Override
public void compose(ComponentContainer content, PropertyValueComponentSource source) {
// remove all components
content.removeAllComponents();
// add components
source.getValueComponents().forEach(valueComponent -> {
final Component component = valueComponent.getComponent();
if (component == null) {
throw new RuntimeException(
"The value component [" + valueComponent + "] returned a null component from getComponent()");
}
if (isFullWidthComponents()) {
component.setWidth("100%");
}
content.addComponent(component);
});
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy