Subversion Repositories SmartDukaan

Rev

Rev 6530 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.catalog.dashboard.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeItem;

/**
 * A tree containing links to display different sets of items
 * based on item statuses and some other parameters.
 */
public class CatalogTree extends Composite {
    
    public static final String ALL_ITEMS = "All Items";
    public static final String ALL_ACTIVE_ITEMS = "Active Items";
    public static final String ALL_PHASED_OUT_ITEMS = "Phased Out Items";
    public static final String ALL_PAUSED_ITEMS = "Paused Items";
    public static final String IN_PROCESS_ITEMS = "In Process Items";
    public static final String CONTENT_COMPLETE_ITEMS = "Content Complete Items";
    public static final String INACTIVE_ITEMS_WITH_INVENTORY = "Inactive Items with Inventory";
    public static final String BREAKEVEN_ITEMS = "Items below Break Even Price";
    
    public static final String RISKY_ITEMS = "Risky Items";
    
    public static final String BEST_DEALS = "Best Deals";
    public static final String BEST_SELLERS = "Best Sellers";
    public static final String LATEST_ARRIVALS = "Latest Arrivals";
    
    public static final String SEARCH = "Search";
    
    public static final String INVENTORY_OUTOFSYNC_ITEM_LIST = "Inventory Out-of-Sync Items";
    
    public static final String PRIVATE_DEALS = "Private Deals";
    
    private Tree tree;
    
    interface TreeListener {
        void onTreeItemClicked(String itemTypes);
    }
    
    TreeListener treeListener;

    public CatalogTree() {
        tree = new Tree();
        TreeItem root = new TreeItem("Catalog");
        TreeItem report = new TreeItem("Reports");
        tree.addItem(root);
        tree.addItem(report);
        

        addItem(root, ALL_ITEMS);
        addItem(root, ALL_ACTIVE_ITEMS);
        addItem(root, ALL_PHASED_OUT_ITEMS);
        addItem(root, ALL_PAUSED_ITEMS);
        addItem(root, IN_PROCESS_ITEMS);
        addItem(root, CONTENT_COMPLETE_ITEMS);
        
        addItem(root, RISKY_ITEMS);
        
        addItem(root, BEST_DEALS);
        addItem(root, BEST_SELLERS);
        addItem(root, LATEST_ARRIVALS);
        
        addItem(root, SEARCH);
        addItem(root,INVENTORY_OUTOFSYNC_ITEM_LIST);
        
        addItem(root,PRIVATE_DEALS);
        
        addItem(report, INACTIVE_ITEMS_WITH_INVENTORY);
        addItem(report, BREAKEVEN_ITEMS);

        root.setState(true);
        initWidget(tree);
    }

    private void addItem(TreeItem root, final String title) {
        Anchor item = new Anchor(title);
        root.addItem(item);
        item.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                treeListener.onTreeItemClicked(title);
            }
        });
    }
    
    public void setTreeListener(TreeListener treeListener) {
        this.treeListener = treeListener;
    }
}