import org.apache.pivot.wtk.Accordion;
import org.apache.pivot.wtk.ActivityIndicator;
import org.apache.pivot.wtk.ApplicationContext;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.Container;
import org.apache.pivot.wtk.content.AccordionHeaderDataRenderer;

public class AnimatedHeaderRenderer extends AccordionHeaderDataRenderer {

	private ActivityIndicator indicator;
	
	public AnimatedHeaderRenderer() {
		super();
		indicator = new ActivityIndicator();
		indicator.setPreferredWidth(14);
		indicator.setPreferredHeight(14);
		this.insert(indicator, 0);
		indicator.setActive(true);
		
		ApplicationContext.ScheduledCallback m_UpdateCallback = ApplicationContext.scheduleRecurringCallback(new Runnable() {
			@Override
			public void run() {
				//does not work : parent is always null
//				Component parent = AnimatedHeaderRenderer.this.getParent();
//				if (parent != null) {
//					parent.repaint();	
//				}
				
				//does not work : ancestor is always null
//				Container ancestor = AnimatedHeaderRenderer.this.getAncestor(Accordion.class);
//				if (ancestor != null) {
//					ancestor.repaint();
//				}

				//does not work : refresh only when hovering the mouse on the Accordion, immediate or not
//				AnimatedHeaderRenderer.this.repaint();
				
				//does not work : refresh only when hovering the mouse on the Accordion
//				AnimatedHeaderRenderer.this.invalidate();
				
				//does not work : refresh only when hovering the mouse on the Accordion, immediate or not
//				indicator.repaint();
				
				//does not work : refresh only when hovering the mouse on the Accordion
//				indicator.invalidate();
			}
		}, 100);
	}
}
