/*
* Created on 2004/11/05
* Author aki@www.xucker.jpn.org
* License Apache2.0 or Common Public License
*/
package org.jpn.xucker.commons.swt.ui.tree;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
/**
*
*
*/
public class TreeBuilder {
public static Map createTree(Tree tree,TreeObject rootObject){
tree.removeAll();
Map map=new HashMap();
TreeItem root=new TreeItem(tree,SWT.NULL);
root.setText(rootObject.getText());
root.setImage(rootObject.getImage());
//System.out.println("root:"+rootObject.getText()+","+rootObject.isExpanded());
root.setExpanded(rootObject.isExpanded());
map.put(root,rootObject);
for(int i=0;i<rootObject.countTreeObjects();i++){
mapping(root,rootObject.getTreeObjectAt(i),map);
}
return map;
}
private static void mapping(TreeItem parent,TreeObject object,Map map){
if(object.getText()!=null){
TreeItem item=new TreeItem(parent,SWT.NULL);
item.setText(object.getText());
item.setImage(object.getImage());
item.setExpanded(object.isExpanded());
//System.out.println(item.getText()+","+item.getExpanded());
map.put(item,object);
for(int i=0;i<object.countTreeObjects();i++){
mapping(item,object.getTreeObjectAt(i),map);
}
}
}
}
|