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

info.joseluismartin.vaadin.data.ContainerPersistentServiceAdapter Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
/*
 * Copyright 2009-2012 the original author or authors.
 *
 * 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 info.joseluismartin.vaadin.data;

import info.joseluismartin.dao.Page;
import info.joseluismartin.service.PersistentService;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.vaadin.data.Container;
import com.vaadin.data.Container.Filter;
import com.vaadin.data.Container.Filterable;
import com.vaadin.data.Container.Sortable;

/**
 * Let a Vaadin container to be a persistent service.
 * 
 * @author Jose Luis Martin - ([email protected])
 */
@SuppressWarnings({"rawtypes", "unchecked"})
public class ContainerPersistentServiceAdapter 
	implements PersistentService {
	
	private Container container;

	/**
	 * {@inheritDoc}
	 */
	
	public Page getPage(Page page) {
		if (container instanceof Sortable) {
			Sortable sortable = (Sortable) container;
			sortable.sort(new Object[] {page.getSortName()}, new boolean[] {page.getOrder() == Page.Order.ASC});
		}
		
		if (container instanceof Filterable) {
			Filterable filterable = (Filterable) container;
			filterable.addContainerFilter(getFilter(page.getFilter()));
		}
		
		Collection itemIds = container.getItemIds();
		
		List data = new ArrayList(page.getPageSize());
		
		for (Object itemId : itemIds) {
			data.add(container.getItem(itemId));
		}
		
		page.setData(data);
		
		return page;
	}

	/**
	 * @param filter
	 * @return
	 */
	private Filter getFilter(Object filter) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	public List getKeys(Page page) {
		return new ArrayList(container.getItemIds());
	}

	/**
	 * {@inheritDoc}
	 */
	public T initialize(T entity, int depth) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	public T initialize(T entity) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	public T save(T entity) {
		return entity;
	}

	/**
	 * {@inheritDoc}
	 */
	public void delete(T entity) {
		// TODO Auto-generated method stub
		
	}

	/**
	 * {@inheritDoc}
	 */
	public void deleteById(PK id) {
		// TODO Auto-generated method stub
		
	}

	/**
	 * {@inheritDoc}
	 */
	public List getAll() {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	public Collection save(Collection collection) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	public void delete(Collection collection) {
		// TODO Auto-generated method stub
		
	}

	/**
	 * {@inheritDoc}
	 */
	public void deleteById(Collection ids) {
		// TODO Auto-generated method stub
		
	}

	/**
	 * {@inheritDoc}
	 */
	public T get(PK id) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	public  E get(PK id, Class clazz) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	public  List getAll(Class clazz) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	public Class getEntityClass() {
		// TODO Auto-generated method stub
		return null;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy