谁有JAVA TREEVIEW的例子?急,我用的是JDEVELOPER,不是ECLIPS.谢谢.

解决方案 »

  1.   

    package isearch.swust.action;import java.util.ArrayList;
    import java.util.List;import org.apache.struts2.ServletActionContext;
    import org.apache.struts2.convention.annotation.Action;
    import org.apache.struts2.convention.annotation.ParentPackage;
    import org.apache.struts2.convention.annotation.Result;
    import org.springframework.context.annotation.Scope;
    import org.springframework.stereotype.Controller;import com.google.gson.Gson;
    import com.opensymphony.xwork2.ActionSupport;@ParentPackage("isearch3")
    @Controller()
    @Scope("prototype")public class ThesauruscategoryAction extends ActionSupport {
    private String id;
    private String text;
    private boolean hasChildren;
    private boolean isexpand;//
    private boolean complete;//是否展开子节点
    private String value;
    private List<ThesauruscategoryAction> ChildrenNodes;
    public String getId() {
    return id;
    }
    public void setId(String id) {
    this.id = id;
    }
    public String getText() {
    return text;
    }
    public void setText(String text) {
    this.text = text;
    }
    public boolean isHasChildren() {
    return hasChildren;
    }
    public void setHasChildren(boolean hasChildren) {
    this.hasChildren = hasChildren;
    }
    public boolean isIsexpand() {
    return isexpand;
    }
    public void setIsexpand(boolean isexpand) {
    this.isexpand = isexpand;
    }
    public boolean isComplete() {
    return complete;
    }
    public void setComplete(boolean complete) {
    this.complete = complete;
    } public String getValue() {
    return value;
    }
    public void setValue(String value) {
    this.value = value;
    }
    public List<ThesauruscategoryAction> getChildrenNodes() {
    return ChildrenNodes;
    }
    public void setChildrenNodes(List<ThesauruscategoryAction> childrenNodes) {
    ChildrenNodes = childrenNodes;
    } @Action(value="sendNode",results={
    @Result(name="success",type="json")
    })
    public String sendNode(){
    List<ThesauruscategoryAction> list=new ArrayList<ThesauruscategoryAction>();
    ThesauruscategoryAction tree1 = new ThesauruscategoryAction();//root
    tree1.setId("1");
    tree1.setText("中国");
    tree1.setHasChildren(true);
    tree1.setIsexpand(false);
    tree1.setComplete(false);//root
    tree1.setValue("86");
    List<ThesauruscategoryAction> tree = new ArrayList<ThesauruscategoryAction>();//children

    tree1.setChildrenNodes(tree);

    ThesauruscategoryAction tree2 = new ThesauruscategoryAction();//firstchild
    ThesauruscategoryAction tree3 = new ThesauruscategoryAction();//secondchild
    ThesauruscategoryAction tree4 = new ThesauruscategoryAction();//thirdchild

    tree2.setId("0.1");
    tree2.setText("北京");
    tree2.setHasChildren(true);
    tree2.setIsexpand(false);
    tree2.setComplete(false);
    tree2.setValue("1");
    tree3.setId("0.2");
    tree3.setText("上海");
    tree3.setHasChildren(false);
    tree3.setIsexpand(false);
    tree3.setComplete(false);
    tree3.setValue("2");
    tree4.setId("0.3");
    tree4.setText("天津");
    tree4.setHasChildren(false);
    tree4.setIsexpand(false);
    tree4.setComplete(false);
    tree4.setValue("3");

    tree.add(tree2);
    tree.add(tree3);
    tree.add(tree4);

    List<ThesauruscategoryAction> tree21 = new  ArrayList<ThesauruscategoryAction>();
    tree2.setChildrenNodes(tree21);
    ThesauruscategoryAction tr1= new ThesauruscategoryAction();
    ThesauruscategoryAction tr2 = new ThesauruscategoryAction();
    tr1.setId("1.1");
    tr1.setText("东城区");
    tr1.setHasChildren(false);
    tr1.setIsexpand(false);
    tr1.setComplete(false);
    tr1.setValue("11");
    tr2.setId("1.2");
    tr2.setText("海淀区");
    tr2.setHasChildren(false);
    tr2.setIsexpand(false);
    tr2.setComplete(false);
    tr2.setValue("12");
    tree21.add(tr1);
    tree21.add(tr2);


    list.add(tree1);//putRoot Gson gson=new Gson();
    String json=gson.toJson(list);
    System.out.println(tree1);
    System.out.println(json);//json格式
    System.out.println(list);
    System.out.println(gson);

    SendJson.send(ServletActionContext.getResponse(), list);
    return SUCCESS;
    }
    }