📄 datafactory.java
字号:
/**
* @作者:陈刚
* @Email:glchengang@yeah.net
* @Blog:http://blog.csdn.net/glchengang
*/
package jface.treeviewer;
import java.util.ArrayList;
/**
* 此类负责生成TreeViewer的方法setInput所需要的参数
*/
public class DataFactory {
public static Object createTreeData() {
/*
* ----------------生成数据对象----------------------
*/
//生成人的数据对象
PeopleEntity p1 = new PeopleEntity("陈刚");
PeopleEntity p2 = new PeopleEntity("陈知行");
PeopleEntity p3 = new PeopleEntity("韩立新");
PeopleEntity p4 = new PeopleEntity("桃子");
PeopleEntity p5 = new PeopleEntity("林雅仕");
PeopleEntity p6 = new PeopleEntity("陈常恩");
PeopleEntity p7 = new PeopleEntity("Giles");
PeopleEntity p8 = new PeopleEntity("Tom");
PeopleEntity p9 = new PeopleEntity("Rose");
//生成城市的数据对象
CityEntity city1 = new CityEntity("北京");
CityEntity city2 = new CityEntity("台湾");
CityEntity city3 = new CityEntity("桂林");
CityEntity city4 = new CityEntity("芝加哥");
CityEntity city5 = new CityEntity("纽约");
//生成国家的数据对象
CountryEntity c1 = new CountryEntity("中国");
CountryEntity c2 = new CountryEntity("美国");
/*
* ----------------将数据对象连结起来------------------------------
*/
//---------------------人和城市的关系---------------------
{//陈刚、陈知行、韩立新是在北京的
ArrayList list = new ArrayList();
list.add(p1);
list.add(p2);
list.add(p3);
city1.setChildren(list);
}
{ //桃子、林雅仕、陈常恩是在台湾的
ArrayList list = new ArrayList();
list.add(p4);
list.add(p5);
list.add(p6);
city2.setChildren(list);
}
{ //Giles、Tom、Rose是在纽约的
ArrayList list = new ArrayList();
list.add(p7);
list.add(p8);
list.add(p9);
city5.setChildren(list);
}
//------------------城市和国家的关系---------------------
{//北京、台湾、桂林属于中国
ArrayList list = new ArrayList();
list.add(city1);
list.add(city2);
list.add(city3);
c1.setChildren(list);
}
{//芝加哥、纽约属于美国
ArrayList list = new ArrayList();
list.add(city4);
list.add(city5);
c2.setChildren(list);
}
//--------将国家置于一个对象之下这个对象可以是List,也可以是数组------
{
ArrayList list = new ArrayList();
list.add(c1);
list.add(c2);
return list;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -