// Copyright (c) 2002 Oracle Corporation
package oracle.portal.sample.v2.devguide.eventform;

import java.util.ResourceBundle;
import oracle.portal.provider.v2.PortletDefinition;
import oracle.portal.provider.v2.personalize.PortletReference;
import oracle.portal.provider.v2.personalize.NameValuePersonalizationObject;
import oracle.portal.sample.v2.devguide.eventform.resource.EventFormBundle;

/**
 * A class that implements the sample event portlet's customization storage.
 */
public class EventFormCustomization extends NameValuePersonalizationObject
{
    //
    // SPLASHTEXT_KEY       - splash text appearing at the top of the portlet
    // PARAMETER1_LABEL_KEY - the text beside the parameter 1 edit field
    // PARAMETER2_LABEL_KEY - the text beside the parameter 2 edit field
    // PARAMETER1_VALUE_KEY - the value for parameter 1 when firing the 'submit'
    //                        event on a mobile display
    // PARAMETER2_VALUE_KEY - the value for parameter 2 when firing the 'submit'
    //                        event on a mobile display
    // SUBMIT_LABEL_KEY     - the text that appears on the button that
    //                        fires the 'submit' event
    // CANCEL_LABEL_KEY     - the text that appears on the button that
    //                        fires the 'cancel' event
    //
    public static final String SPLASHTEXT_KEY       = EventFormBundle.SPLASHTEXT_KEY;
    public static final String PARAMETER1_LABEL_KEY = EventFormBundle.PARAMETER1_LABEL_KEY;
    public static final String PARAMETER2_LABEL_KEY = EventFormBundle.PARAMETER2_LABEL_KEY;
    public static final String PARAMETER1_VALUE_KEY = "PARAM1VALUE";
    public static final String PARAMETER2_VALUE_KEY = "PARAM2VALUE";
    public static final String SUBMIT_LABEL_KEY     = EventFormBundle.SUBMIT_LABEL_KEY;
    public static final String CANCEL_LABEL_KEY     = EventFormBundle.CANCEL_LABEL_KEY;

    /**
     * Sample event portlet customization constructor.
     */
    public EventFormCustomization()
    {
    }

    /**
     * Set initial values for customizable values.
     */
    public void init(PortletReference ref)
    {
        super.init(ref);

        PortletDefinition portletDef = ref.getPortletDefinition();
        ResourceBundle bundle = portletDef.getResourceBundle(ref.getLocale());

        String splashText = bundle.getString(EventFormBundle.SPLASHTEXT_KEY);
        if (splashText == null) 
        {
            splashText = ""; // can have no splash text
        }
        setSplashText(splashText);

        String parameter1Label = 
            bundle.getString(EventFormBundle.PARAMETER1_LABEL_KEY);
        if (parameter1Label == null) 
        {
            // cant have the text field without a label
            parameter1Label = "Parameter #1"; 
        }
        setParameter1Label(parameter1Label);

        String parameter2Label = 
            bundle.getString(EventFormBundle.PARAMETER2_LABEL_KEY);
        if (parameter2Label == null) 
        {
            // cant have the text field without a label
            parameter2Label = "Parameter #2"; 
        }
        setParameter2Label(parameter2Label);

        setParameter1ValueForMobile("");
        setParameter2ValueForMobile("");

        String submitLabel = bundle.getString(EventFormBundle.SUBMIT_LABEL_KEY);
        if (submitLabel == null) 
        {
            submitLabel = "Submit"; // cant have a button with no label 
        }
        setSubmitLabel(submitLabel);

        String cancelLabel = bundle.getString(EventFormBundle.CANCEL_LABEL_KEY);
        if (cancelLabel == null) 
        {
            cancelLabel = "Cancel"; // cant have a button with no label
        }
        setCancelLabel(cancelLabel);
    }

    /**
     * Removes edit default data.
     *
     * This class is used to store both customizations and edit defaults data.
     * When using an object for customization this method should be called
     * to remove the initialized edit defaults values.
     */
    public void removeEditDefaultData()
    {
        setSplashText(null);
        setParameter1Label(null);
        setParameter2Label(null);
        setParameter1ValueForMobile(null);
        setParameter2ValueForMobile(null);
        setSubmitLabel(null);
        setCancelLabel(null);
    }

    public String getSplashText()
    {
        return getString(SPLASHTEXT_KEY);
    }

    public void setSplashText(String splashText)
    {
        putString(SPLASHTEXT_KEY, splashText);
    }

    public String getParameter1Label()
    {
        return getString(PARAMETER1_LABEL_KEY);
    }

    public void setParameter1Label(String parameter1Label)
    {
        putString(PARAMETER1_LABEL_KEY, parameter1Label);
    }

    public String getParameter1ValueForMobile()
    {
        return getString(PARAMETER1_VALUE_KEY);
    }

    public void setParameter1ValueForMobile(String parameter1Value)
    {
        putString(PARAMETER1_VALUE_KEY, parameter1Value);
    }

    public String getParameter2Label()
    {
        return getString(PARAMETER2_LABEL_KEY);
    }

    public void setParameter2Label(String parameter2Label)
    {
        putString(PARAMETER2_LABEL_KEY, parameter2Label);
    }

    public String getParameter2ValueForMobile()
    {
        return getString(PARAMETER2_VALUE_KEY);
    }

    public void setParameter2ValueForMobile(String parameter2Value)
    {
        putString(PARAMETER2_VALUE_KEY, parameter2Value);
    }

    public String getSubmitLabel()
    {
        return getString(SUBMIT_LABEL_KEY);
    }

    public void setSubmitLabel(String submitLabel)
    {
        putString(SUBMIT_LABEL_KEY, submitLabel);
    }

    public String getCancelLabel()
    {
        return getString(CANCEL_LABEL_KEY);
    }

    public void setCancelLabel(String cancelLabel)
    {
        putString(CANCEL_LABEL_KEY, cancelLabel);
    }
}

