package com.sii.rental.ui.views;

import java.util.Collection;

import javax.annotation.PostConstruct;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;

import com.opcoach.training.rental.Customer;
import com.opcoach.training.rental.RentalAgency;

public class RentalProvider extends LabelProvider implements ITreeContentProvider {

	@PostConstruct
	public void init() {
		
	}
		
	@Override
	public Object[] getElements(Object inputElement) {
		
		if(inputElement instanceof Collection<?>)
		{
			return ((Collection) inputElement).toArray(); 
		}
		else
		{
			return null;	
		}
	}
	
	@Override
	public Object[] getChildren(Object parentElement) {
		if(parentElement instanceof RentalAgency)
		{
			return ((RentalAgency) parentElement).getCustomers().toArray();
		}
		else
		{
			return null;
		}
	}
	
	@Override
	public Object getParent(Object element) {
		//if(element instanceof EObject)
		//{
		//	return (EObject) element.eContainer();
		//}
		//else
		//{
			return null;
		//}
	}
	
	@Override
	public boolean hasChildren(Object element) {
		return true;
	}
	
	@Override
	public String getText(Object element) {
		if(element instanceof RentalAgency)
		{
			return ((RentalAgency) element).getName();
		}
		else if (element instanceof Customer)
		{
			return ((Customer) element).getDisplayName();
		}
		else
		{
			return super.getText(element);
		}
	}
}

@@ -600,21 +600,16 @@
 on%3C?%3E)%0D%0A
-%09%09%7B%0D%0A
 %09%09%09retur
@@ -651,29 +651,24 @@
 ay(); %0D%0A
-%09%09%7D%0D%0A
 %09%09else%0D%0A
 %09%09%7B%0D%0A%09%09%09
@@ -651,37 +651,32 @@
 ay(); %0D%0A%09%09else%0D%0A
-%09%09%7B%0D%0A
 %09%09%09return null;%09
@@ -677,21 +677,16 @@
 null;%09%0D%0A
-%09%09%7D%0D%0A
 %09%7D%0D%0A%09%0D%0A%09
@@ -787,37 +787,32 @@
  RentalAgency)%0D%0A
-%09%09%7B%0D%0A
 %09%09%09return ((Rent
@@ -863,32 +863,23 @@
 ray();%0D%0A
-%09%09%7D%0D%0A
 %09%09else
-%0D%0A%09%09%7B
+ 
 %0D%0A%09%09%09ret
@@ -889,21 +889,16 @@
  null;%0D%0A
-%09%09%7D%0D%0A
 %09%7D%0D%0A%09%0D%0A%09
@@ -988,23 +988,16 @@
 bject)%0D%0A
-%09%09//%7B%0D%0A
 %09%09//%09ret
@@ -1033,23 +1033,16 @@
 ner();%0D%0A
-%09%09//%7D%0D%0A
 %09%09//else
@@ -1047,15 +1047,8 @@
 se%0D%0A
-%09%09//%7B%0D%0A
 %09%09%09r
@@ -1064,15 +1064,8 @@
 l;%0D%0A
-%09%09//%7D%0D%0A
 %09%7D%0D%0A
@@ -1242,21 +1242,16 @@
 gency)%0D%0A
-%09%09%7B%0D%0A
 %09%09%09retur
@@ -1285,29 +1285,24 @@
 getName();%0D%0A
-%09%09%7D%0D%0A
 %09%09else if (e
@@ -1330,21 +1330,16 @@
 tomer)%0D%0A
-%09%09%7B%0D%0A
 %09%09%09retur
@@ -1384,21 +1384,16 @@
 );%0D%0A
-%09%09%7D%0D%0A
 %09%09else%0D%0A
 %09%09%7B%0D
@@ -1392,13 +1392,8 @@
 se%0D%0A
-%09%09%7B%0D%0A
 %09%09%09r
@@ -1427,13 +1427,8 @@
 );%0D%0A
-%09%09%7D%0D%0A
 %09%7D%0D%0A

update provider