/**
 * 
 */
package minijaja.ihm.controleur;

import minijaja.ast_struct.Node;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;


/**
 * Compilateur.minijaja.ihm.controleur.TreeContentProvider.java
 * @author Ludovic
 * cree le 17 nov. 07
 */
public class MjjTreeContentProvider implements ITreeContentProvider {
	
	
	/**
	 * Constructeur de la classe minijaja.ihm.controleur.TreeContentProvider.java
	 */
	public MjjTreeContentProvider() {
		super();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
	 */
	//@Override
	public Object[] getChildren(Object parentElement) {
		Object[] listeFils = new Object[((Node)parentElement).jjtGetNumChildren()];
		int i;
		for(i = 0; i < ((Node)parentElement).jjtGetNumChildren(); i++){
			// -- les fils :
			listeFils[i]= ((Node)parentElement).jjtGetChild(i);	
		}
		return listeFils;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
	 */
	//@Override
	public Object getParent(Object element) {
		return ((Node)element).jjtGetParent();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
	 */
	//@Override
	public boolean hasChildren(Object element) {
		if(((Node)element).jjtGetNumChildren() == 0){
			return false;
		}
		return true;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
	 */
	//@Override
	public Object[] getElements(Object inputElement) {
		
		Object[] listeFils = new Object[((Node)inputElement).jjtGetNumChildren()];
		int i;
		for(i = 0; i < ((Node)inputElement).jjtGetNumChildren(); i++){
			// -- les fils :
			listeFils[i]= ((Node)inputElement).jjtGetChild(i);	
		}
		return listeFils;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
	 */
	//@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
	//@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		// TODO Auto-generated method stub

	}

}
