2013-05-08 2 views
9

Vaadin 7에서 프로젝트를하고 있습니다. Treetable 용 Lazy Query Container를 구현해야합니다. 나는 웹 서비스로부터 Treetable을위한 데이터를 얻을 것이다.Vaadin - Lazy Query Container

웹 서비스가있는 지연 쿼리 컨테이너를 데이터 소스로 사용하는 방법을 보여줄 수 있습니까?

나를 구현하기 위해 필요한 단계를 알려 주시거나 샘플 코드를 보여주십시오.

+0

사람이 대답하시기 바랍니다. – Gugan

+0

@ 관음, 그것을 해결 했습니까? – quento

답변

6

가 여기 LQC에 대한 좋은 문서입니다 : 문서에 https://vaadin.com/wiki/-/wiki/Main/Lazy%20Query%20Container

예제는는 javax.persistence API를 사용하여 MovieQuery를 구현하고는 있지만 기초로 간단한 MockQuery example를 사용하여 웹 서비스로 가져 오는 실제 데이터를 대체하기 쉬울 수 있습니다 전화.

+0

응답 해 주셔서 감사합니다. 실제 데이터 가져 오기를 웹 서비스 호출로 대체하는 몇 가지 예를 보여줄 수 있습니까? – Gugan

+0

그리고 이것은 이미 알고 있습니다. 정말 이것을 Treetable에서 구현하는 방법을 알고 싶습니까? LQC에 대한 계층 적 접근! – Gugan

0

지연로드Hierarchical 인터페이스를 살펴보십시오.
모든 데이터는 웹 서비스 IViewService에서 읽습니다.
이 예제에서는 Tree 구성 요소를 사용하지만 TreeTable에서도 작동합니다.

그것은 요소이 작동하지 않는 여러 번 읽지 않는,합니다 (HashMaphierarchy 내 경우) 로컬 구조의 모든 요소를 ​​저장하는 매우 중요합니다. 나는 Vaadin이 equals()hashCode()을 사용하지 않기 때문에 나는 생각한다.

import java.util.Collection; 
import java.util.Collections; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 

import com.softmodeler.common.CommonPlugin; 
import com.softmodeler.model.OutputNode; 
import com.softmodeler.service.IViewService; 
import com.vaadin.data.Container.Hierarchical; 
import com.vaadin.data.Item; 
import com.vaadin.data.Property; 
import com.vaadin.data.util.BeanItem; 

/** 
* @author Flavio Donzé 
* @version 1.0 
*/ 
public class OutputNodeHierachical implements Hierarchical { 
    private static final long serialVersionUID = 8289589835030184018L; 

    /** the view service */ 
    private IViewService service = CommonPlugin.getService(IViewService.class); 

    /** collection of all root nodes */ 
    private List<OutputNode> rootNodes = null; 
    /** parent=>children mapping */ 
    private Map<OutputNode, List<OutputNode>> hierarchy = new HashMap<>(); 

    /** 
    * constructor 
    * 
    * @param rootNodes collection of all root nodes 
    */ 
    public OutputNodeHierachical(List<OutputNode> rootNodes) { 
     this.rootNodes = Collections.unmodifiableList(rootNodes); 

     addToHierarchy(rootNodes); 
    } 

    @Override 
    public Collection<?> getChildren(Object itemId) { 
     try { 
      List<OutputNode> children = hierarchy.get(itemId); 
      if (children == null) { 
       OutputNode node = (OutputNode) itemId; 
       children = service.getChildren(node.getNodeId(), false); 

       hierarchy.put(node, children); 

       // add children to hierarchy, their children will be added on click 
       addToHierarchy(children); 
      } 
      return children; 
     } catch (Exception e) { 
      VaadinUtil.handleException(e); 
     } 
     return null; 
    } 

    /** 
    * add each element to the hierarchy without their children hierarchy(child=>null) 
    * 
    * @param children elements to add 
    */ 
    private void addToHierarchy(List<OutputNode> children) { 
     for (OutputNode child : children) { 
      hierarchy.put(child, null); 
     } 
    } 

    @Override 
    public boolean areChildrenAllowed(Object itemId) { 
     return !((OutputNode) itemId).getChilds().isEmpty(); 
    } 

    @Override 
    public boolean hasChildren(Object itemId) { 
     return !((OutputNode) itemId).getChilds().isEmpty(); 
    } 

    @Override 
    public Object getParent(Object itemId) { 
     String parentId = ((OutputNode) itemId).getParentId(); 
     for (OutputNode node : hierarchy.keySet()) { 
      if (node.getNodeId().equals(parentId)) { 
       return node; 
      } 
     } 
     return null; 
    } 

    @Override 
    public Collection<?> rootItemIds() { 
     return rootNodes; 
    } 

    @Override 
    public boolean isRoot(Object itemId) { 
     return rootNodes.contains(itemId); 
    } 

    @Override 
    public Item getItem(Object itemId) { 
     return new BeanItem<OutputNode>((OutputNode) itemId); 
    } 

    @Override 
    public boolean containsId(Object itemId) { 
     return hierarchy.containsKey(itemId); 
    } 

    @Override 
    public Collection<?> getItemIds() { 
     return hierarchy.keySet(); 
    } 

    @Override 
    public int size() { 
     return hierarchy.size(); 
    } 

    @Override 
    public boolean setParent(Object itemId, Object newParentId) throws UnsupportedOperationException { 
     throw new UnsupportedOperationException(); 
    } 

    @Override 
    public boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed) throws UnsupportedOperationException { 
     throw new UnsupportedOperationException(); 
    } 

    @Override 
    public Item addItem(Object itemId) throws UnsupportedOperationException { 
     throw new UnsupportedOperationException(); 
    } 

    @Override 
    public Object addItem() throws UnsupportedOperationException { 
     throw new UnsupportedOperationException(); 
    } 

    @Override 
    public boolean removeItem(Object itemId) throws UnsupportedOperationException { 
     throw new UnsupportedOperationException(); 
    } 

    @Override 
    public boolean removeAllItems() throws UnsupportedOperationException { 
     throw new UnsupportedOperationException(); 
    } 

    @Override 
    public Class<?> getType(Object propertyId) { 
     throw new UnsupportedOperationException(); 
    } 

    @Override 
    public Collection<?> getContainerPropertyIds() { 
     throw new UnsupportedOperationException(); 
    } 

    @Override 
    public Property<?> getContainerProperty(Object itemId, Object propertyId) { 
     throw new UnsupportedOperationException(); 
    } 

    @Override 
    public boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue) throws UnsupportedOperationException { 
     throw new UnsupportedOperationException(); 
    } 

    @Override 
    public boolean removeContainerProperty(Object propertyId) throws UnsupportedOperationException { 
     throw new UnsupportedOperationException(); 
    } 

} 

이 같은 Tree에 컨테이너를 추가 :

OutputNodeHierachical dataSource = new OutputNodeHierachical(rootNodes); 

Tree mainTree = new Tree(); 
mainTree.setSizeFull(); 
mainTree.setContainerDataSource(dataSource); 
mainTree.addItemClickListener(new ItemClickListener() { 
    private static final long serialVersionUID = -413371711541672605L; 

    @Override 
    public void itemClick(ItemClickEvent event) { 
     OutputNode node = (OutputNode) event.getItemId(); 
     openObject(node.getObjectId()); 
    } 
});