/*
 * Copyright 2006-2007 Queplix Corp.
 *
 * Licensed under the Queplix Public License, Version 1.1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.queplix.com/solutions/commercial-open-source/queplix-public-license/
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 */


package com.queplix.core.client.frames.mainframe.impl;

import com.queplix.core.client.common.event.Event;
import com.queplix.core.client.common.ui.ButtonData;
import com.queplix.core.client.common.ui.EventButtonData;
import com.queplix.core.client.common.ui.IconButton;
import com.queplix.core.client.common.ui.IconData;
import com.queplix.core.client.common.ui.ToolbarContext;
import com.queplix.core.client.frames.mainframe.MainToolbarBuilder;

/**
 *
 * @author dmitry.antonov
 */
public class DefaultMainToolbarBuilder implements MainToolbarBuilder {
    
    public static interface Events {
        Event BACK = new Event();
        Event FORWARD = new Event();
        Event CLEAR_ALL = new Event();
        Event LAST_SEARCH = new Event();
        Event LAST_SEARCH_MENU = new Event();
        Event LOAD_SAVED_SEARCH = new Event();
        Event SAVE_CURRENT_SEARCH = new Event();
        Event PRINT_FORM = new Event();
        //Event PRINT_GRID = new Event();
        Event E_MAIL = new Event();
        Event BROADCAST = new Event();
        Event ALERTS = new Event();
        Event AD_HOC_REPORTS = new Event();
        Event REPORT_SCHEDULER = new Event();
        Event SAVE_SETTINGS = new Event();
    }
    
    private static interface Buttons {
        ButtonData BACK = new ButtonData(null, "Back", "toolbar/back.gif",
                "toolbar/back_disabled.gif", "toolbar/back_bright.gif");
        ButtonData FORWARD = new ButtonData(null, "Forward",
                "toolbar/forward.gif", "toolbar/forward_disabled.gif",
                "toolbar/forward_bright.gif");
        ButtonData CLEAR_ALL = new ButtonData(null, "Clear All",
                "toolbar/clear_all.gif", null, "toolbar/clear_all_bright.gif");
        ButtonData LAST_SEARCH = new ButtonData(null, "Last Search",
                "toolbar/last_search.gif", "toolbar/last_search_disabled.gif",
                "toolbar/last_search_bright.gif");
        ButtonData LAST_SEARCH_MENU = new ButtonData(null,
                "Last Search Options", "toolbar/button_menu.gif", null,
                "toolbar/button_menu_bright.gif");
        ButtonData LOAD_SAVED_SEARCH = new ButtonData("Load Saved Search");
        ButtonData SAVE_CURRENT_SEARCH = new ButtonData("Save Current Search");
        ButtonData PRINT_FORM = new ButtonData(null, "Print Form",
                "toolbar/print_form.gif", "toolbar/print_form_disabled.gif",
                "toolbar/print_form_bright.gif");
        ButtonData PRINT_GRID = new ButtonData(null, "Print Grid",
                "toolbar/print_grid.gif", "toolbar/print_grid_disabled.gif",
                "toolbar/print_grid_bright.gif");
        ButtonData E_MAIL = new ButtonData(null, "E-mail", "toolbar/e_mail.gif",
                null, "toolbar/e_mail_bright.gif");
        ButtonData BROADCAST = new ButtonData(null, "Broadcasts",
                "toolbar/broadcast.gif", null, "toolbar/broadcast_bright.gif");
        ButtonData ALERTS = new ButtonData(null, "Alerts", "toolbar/alerts.gif",
                null, "toolbar/alerts_bright.gif");
        ButtonData AD_HOC_REPORTS = new ButtonData(null,
                "Ad-Hoc Report Designer", "toolbar/ad_hoc_reports.gif", null,
                "toolbar/ad_hoc_reports_bright.gif");
        ButtonData REPORT_SCHEDULER = new ButtonData(null, "Report Scheduler",
                "toolbar/report_scheduler.gif", null,
                "toolbar/report_scheduler_bright.gif");
        ButtonData SAVE_SETTINGS = new ButtonData(null, "Save Settings",
                "toolbar/save_settings.gif", null,
                "toolbar/save_settings_bright.gif");
    }
    
    private static final IconData DIVIDER_ICON = new IconData("toolbar_divider", null, true);
    private static final IconData COMPANY_LOGO_ICON = new IconData("toolbar/logo_company.gif", null);
    
    public static final String DIVIDER = "divider";
    public static final String COMPANY_LOGO = "company_logo";
    public static final String BACK = "back";
    public static final String FORWARD = "forward";
    public static final String CLEAR_ALL = "clear_all";
    public static final String LAST_SEARCH = "last_search";
    public static final String PRINT_FORM = "print_form";
    public static final String E_MAIL = "e_mail";
    public static final String ADHOC_REPORTS = "adhoc_reports";
    public static final String SAVE_SETTINGS = "save_settings";
    public static final String IDLE_INDICATOR = "idle_indicator";
    

    
    /** Creates a new instance of DefaultMainToolbarBuilder */
    public DefaultMainToolbarBuilder() {
    }

    public void buildControl(ToolbarContext context, String controlName) {
        if (controlName.equalsIgnoreCase(COMPANY_LOGO)) {
            context.addIcon(COMPANY_LOGO_ICON, true);
        } else if (controlName.equalsIgnoreCase(DIVIDER)) {
            context.addIcon(DIVIDER_ICON, true);
        } else if (controlName.equalsIgnoreCase(BACK)) {
            context.addButton(Events.BACK, Buttons.BACK, true);
        } else if (controlName.equalsIgnoreCase(FORWARD)) {
            context.addButton(Events.FORWARD, Buttons.FORWARD, true);
        } else if (controlName.equalsIgnoreCase(CLEAR_ALL)) {
            context.addButton(Events.CLEAR_ALL, Buttons.CLEAR_ALL, true);
        } else if (controlName.equalsIgnoreCase(LAST_SEARCH)) {
            IconButton button = context.addButton(Events.LAST_SEARCH, Buttons.LAST_SEARCH,
                true);
            IconButton menuButton = context.addMenuButton(Events.LAST_SEARCH_MENU,
                Buttons.LAST_SEARCH_MENU, true,
                new EventButtonData[]{
                        new EventButtonData(Events.LOAD_SAVED_SEARCH,
                                Buttons.LOAD_SAVED_SEARCH),
                        new EventButtonData(Events.SAVE_CURRENT_SEARCH,
                                Buttons.SAVE_CURRENT_SEARCH)
                });
            context.mergeButtons(button, menuButton);
        } else if (controlName.equalsIgnoreCase(PRINT_FORM)) {
            context.addButton(Events.PRINT_FORM, Buttons.PRINT_FORM, true);
        } else if (controlName.equalsIgnoreCase(E_MAIL)) {
            context.addButton(Events.E_MAIL, Buttons.E_MAIL, true);
        } else if (controlName.equalsIgnoreCase(ADHOC_REPORTS)) {
            context.addButton(Events.AD_HOC_REPORTS, Buttons.AD_HOC_REPORTS, true);        
        } else if (controlName.equalsIgnoreCase(SAVE_SETTINGS)) {
            context.addButton(Events.SAVE_SETTINGS, Buttons.SAVE_SETTINGS, true);
        }
        
    }

    public String[] getSupportedControls() {
        return new String[] {DIVIDER, COMPANY_LOGO, BACK, FORWARD, CLEAR_ALL,
                             LAST_SEARCH, PRINT_FORM, E_MAIL, ADHOC_REPORTS,
                             SAVE_SETTINGS, IDLE_INDICATOR};
    }
    
}
