All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.holonplatform.vaadin7.internal.components.builders.DefaultGridPropertyListingBuilder Maven / Gradle / Ivy

/*
 * Copyright 2016-2017 Axioma srl.
 * 
 * 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.builders;

import com.holonplatform.core.Path;
import com.holonplatform.core.datastore.DataTarget;
import com.holonplatform.core.datastore.Datastore;
import com.holonplatform.core.i18n.Localizable;
import com.holonplatform.core.internal.utils.ObjectUtils;
import com.holonplatform.core.property.Property;
import com.holonplatform.core.property.PropertyBox;
import com.holonplatform.core.property.PropertySet;
import com.holonplatform.vaadin7.components.PropertyListing;
import com.holonplatform.vaadin7.components.builders.PropertyListingBuilder.GridPropertyListingBuilder;
import com.holonplatform.vaadin7.data.ItemDataProvider;
import com.holonplatform.vaadin7.internal.components.DefaultPropertyListing;
import com.holonplatform.vaadin7.internal.components.DefaultItemListing.RenderingMode;
import com.holonplatform.vaadin7.internal.data.DatastoreCommitHandler;
import com.holonplatform.vaadin7.internal.data.DatastoreItemDataProvider;
import com.holonplatform.vaadin7.internal.data.PropertiesItemIdentifier;
import com.holonplatform.vaadin7.internal.data.container.PropertyBoxItemAdapter;
import com.vaadin.data.Validator;
import com.vaadin.data.util.converter.Converter;
import com.vaadin.ui.renderers.Renderer;

/**
 * Defauklt {@link DefaultGridPropertyListingBuilder} implementation.
 *
 * @since 5.0.0
 */
@SuppressWarnings("rawtypes")
public class DefaultGridPropertyListingBuilder extends
		AbstractGridItemListingBuilder
		implements GridPropertyListingBuilder {

	private final Iterable> properties;

	@SuppressWarnings("unchecked")
	public 

> DefaultGridPropertyListingBuilder(Iterable

properties) { super(new DefaultPropertyListing(RenderingMode.GRID)); this.properties = (Iterable>) properties; // default adapter dataSourceBuilder.itemAdapter(new PropertyBoxItemAdapter()); // setup datasource properties.forEach(p -> { dataSourceBuilder.withProperty(p, p.getType()); if (p.isReadOnly()) { dataSourceBuilder.readOnly(p, true); } if (Path.class.isAssignableFrom(p.getClass())) { dataSourceBuilder.sortable(p, true); } }); } /* * (non-Javadoc) * @see * com.holonplatform.vaadin.components.builders.PropertyListingBuilder#dataSource(com.holonplatform.vaadin.data. * ItemDataProvider, com.holonplatform.core.property.Property[]) */ @Override public GridPropertyListingBuilder dataSource(ItemDataProvider dataProvider, Property... identifierProperties) { ObjectUtils.argumentNotNull(identifierProperties, "Identifier properties must be not null"); if (identifierProperties.length == 0) { throw new IllegalArgumentException("Identifier properties must be not empty"); } return dataSource(dataProvider, new PropertiesItemIdentifier(identifierProperties)); } /* * (non-Javadoc) * @see * com.holonplatform.vaadin.components.builders.PropertyListingBuilder#dataSource(com.holonplatform.core.datastore. * Datastore, com.holonplatform.core.datastore.DataTarget, com.holonplatform.core.property.Property[]) */ @Override public GridPropertyListingBuilder dataSource(Datastore datastore, DataTarget dataTarget, Property... identifierProperties) { commitHandler(new DatastoreCommitHandler(datastore, dataTarget)); dataSource(new DatastoreItemDataProvider(datastore, dataTarget, PropertySet.of(properties)), identifierProperties); return builder(); } /* * (non-Javadoc) * @see * com.holonplatform.vaadin.components.builders.PropertyListingBuilder#withValidator(com.holonplatform.core.property * .Property, com.vaadin.data.Validator) */ @Override public GridPropertyListingBuilder withValidator(Property property, Validator validator) { ObjectUtils.argumentNotNull(validator, "Validator must be not null"); getInstance().getPropertyColumn(property).addValidator(validator); return builder(); } /* * (non-Javadoc) * @see * com.holonplatform.vaadin.components.builders.PropertyListingBuilder#required(com.holonplatform.core.property. * Property, com.holonplatform.core.i18n.Localizable) */ @Override public GridPropertyListingBuilder required(Property property, Localizable message) { getInstance().getPropertyColumn(property).setRequired(true); getInstance().getPropertyColumn(property).setRequiredMessage(message); return builder(); } /* * (non-Javadoc) * @see com.holonplatform.vaadin.components.builders.PropertyListingBuilder.GridPropertyListingBuilder#render(com. * holonplatform.core.property.Property, com.vaadin.ui.renderers.Renderer) */ @Override public GridPropertyListingBuilder render(Property property, Renderer renderer) { ObjectUtils.argumentNotNull(property, "Property must be not null"); getInstance().getPropertyColumn(property).setRenderer(renderer); return builder(); } /* * (non-Javadoc) * @see com.holonplatform.vaadin.components.builders.PropertyListingBuilder.GridPropertyListingBuilder#render(com. * holonplatform.core.property.Property, com.vaadin.data.util.converter.Converter, com.vaadin.ui.renderers.Renderer) */ @Override public GridPropertyListingBuilder render(Property property, Converter converter, Renderer renderer) { ObjectUtils.argumentNotNull(property, "Property must be not null"); getInstance().getPropertyColumn(property).setConverter(converter); getInstance().getPropertyColumn(property).setRenderer(renderer); return builder(); } /* * (non-Javadoc) * @see com.holonplatform.vaadin.internal.components.builders.AbstractComponentBuilder#build(com.vaadin.ui. * AbstractComponent) */ @Override protected PropertyListing build(DefaultPropertyListing instance) { return instance; } /* * (non-Javadoc) * @see com.holonplatform.vaadin.internal.components.builders.AbstractComponentConfigurator#builder() */ @Override protected GridPropertyListingBuilder builder() { return this; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy