package de.examples.matrixboard;

import java.io.Serializable;

import org.eclnt.ccaddons.pbc.CCDashboardItem;
import org.eclnt.ccaddons.pbc.CCMatrixDashboard;
import org.eclnt.ccaddons.pbc.CCMatrixDashboard.ItemInfo;
import org.eclnt.editor.annotations.CCGenClass;
import org.eclnt.jsfserver.pagebean.PageBean;

@CCGenClass (expressionBase="#{d.MatrixBoardBean}")

public class MatrixBoardBean
    extends PageBean 
    implements Serializable
{
    // ------------------------------------------------------------------------
    // inner classes
    // ------------------------------------------------------------------------
    
    /* Listener to the user of the page bean. */
    public interface IListener extends Serializable
    {
    }
    
    // ------------------------------------------------------------------------
    // members
    // ------------------------------------------------------------------------
    
    private IListener m_listener;
    
    // ------------------------------------------------------------------------
    // constructors & initialization
    // ------------------------------------------------------------------------

    public MatrixBoardBean() {
    	initDashboard();
    }

    public String getPageName() { return "/examples/matrixboard/matrixboard.xml"; }
    public String getRootExpressionUsedInPage() { return "#{d.MatrixBoardBean}"; }

    // ------------------------------------------------------------------------
    // public usage
    // ------------------------------------------------------------------------

    /* Initialization of the bean. Add any parameter that is required within your scenario. */
    public void prepare(IListener listener)
    {
        m_listener = listener;
    }

    // ------------------------------------------------------------------------
    // private usage
    // ------------------------------------------------------------------------
    
    class MyMatrixDashboardListener implements CCMatrixDashboard.IListener
    {
        @Override
        public void reactOnMovedOrResized(ItemInfo itemInfo)
        {
        	System.out.println("ID: " + itemInfo.getItemSize());
        	System.out.println("X: " + itemInfo.getItemX());
        	System.err.println("Y: " + itemInfo.getItemY());
        	
        }
        @Override
        public void reactOnMenuItemAction(ItemInfo itemInfo, String command)
        {
        }
    }
    
    CCMatrixDashboard m_dashboard = new CCMatrixDashboard();


  
    public CCMatrixDashboard getDashboard() { return m_dashboard; }
    
    String[] COLORS = new String[] {"#2c84ee","#d44a26","#2d8bef","#2d8bef","#2c84ee"};
    String[] TEXTS = new String[] {"Mails","Inbound","Outbound","Orders","Info"};
    String[] ICONS = new String[] {"f010","f011","f012","f013","f014"};
    
    private void initDashboard()
    {
        m_dashboard = new CCMatrixDashboard();
        for (int i = 0; i < 5; i++)
        {
            CCDashboardItem dbi = new CCDashboardItem(true);
            dbi.setId("" + i);
            dbi.setText(TEXTS[i]);
            dbi.setBackground(COLORS[i]);
            dbi.setImage("/awesomefont("+ICONS[i]+",#FFFFFF,20)");
            dbi.setForeground("#FFFFFF");
            
            m_dashboard.addItem(dbi);
        }
        m_dashboard.prepare(new MyMatrixDashboardListener(), true, "mypersistid");
    }
}
