/*
* 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.List;
import java.util.Vector;
import org.eclipse.swt.graphics.Image;
/**
*
*
*/
public class TreeObject {
private Image image;
private boolean expand;
private String text;
public boolean isExpanded() {
return expand;
}
public void setExpanded(boolean expand) {
this.expand = expand;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
public TreeObject getParent() {
return parent;
}
public void setParent(TreeObject parent) {
this.parent = parent;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
private TreeObject parent;
private List childrenList=new Vector();
public void addTreeObject(TreeObject object){
object.setParent(this);
childrenList.add(object);
}
public int countTreeObjects(){
return childrenList.size();
}
public TreeObject getTreeObjectAt(int index){
return ((TreeObject)childrenList.get(index));
}
public TreeObject[] getTreeObjects(){
return ((TreeObject[])childrenList.toArray(new TreeObject[childrenList.size()]));
}
public void removeTreeObject(TreeObject object){
childrenList.remove(object);
}
/**
* @param object
*/
public void upTreeObject(TreeObject object) {
int index=checkIndex(object);
if(index>0){
childrenList.remove(object);
childrenList.add(index-1,object);
}
}
public void downTreeObject(TreeObject object) {
int index=checkIndex(object);
if(index<childrenList.size()-1){
childrenList.remove(object);
childrenList.add(index+1,object);
}
}
public void topTreeObject(TreeObject object) {
int index=checkIndex(object);
if(index>0){
childrenList.remove(object);
childrenList.add(0,object);
}
}
public void bottomTreeObject(TreeObject object) {
int index=checkIndex(object);
if(index<childrenList.size()-1){
childrenList.remove(object);
childrenList.add(childrenList.size(),object);
}
}
private int checkIndex(TreeObject object){
TreeObject objects[]=getTreeObjects();
for(int i=0;i<objects.length;i++){
if(objects[i]==object){
return i;
}
}
return -1;
}
/**
*
*/
public void removeAllTreeObject() {
childrenList.removeAll(childrenList);
}
/**
* @param itemObject
* @return
*/
public boolean contain(TreeObject itemObject) {
for(int i=0;i<countTreeObjects();i++){
if(getTreeObjectAt(i)==itemObject){
return true;
}else{
getTreeObjectAt(i).contain(itemObject);
}
}
return false;
}
/**
* @param object
* @param index
*/
public void addTreeObject(TreeObject object, int index) {
// TODO Auto-generated method stub
object.setParent(this);
childrenList.add(index,object);
}
public int indexOf(TreeObject object){
return childrenList.indexOf(object);
}
}
|