// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   TemplatePicker.java

package com.ptc.windchill.enterprise.doc.tags;

import com.ptc.core.components.beans.CreateAndEditWizBean;
import com.ptc.core.components.rendering.RenderingContext;
import com.ptc.core.components.rendering.guicomponents.ComboBox;
import com.ptc.core.components.rendering.guicomponents.Label;
import com.ptc.core.components.tags.components.AbstractHtmlTag;
import com.ptc.core.components.tags.propertyPanel.RenderPropertyPanelTag;
import com.ptc.core.foundation.type.server.impl.TypeHelper;
import com.ptc.netmarkets.util.beans.NmCommandBean;
import com.ptc.netmarkets.util.beans.NmHelperBean;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.*;
import org.apache.log4j.Logger;
import wt.admin.AdminDomainRef;
import wt.doc.WTDocumentHelper;
import wt.doc.WTDocumentService;
import wt.log4j.LogR;
import wt.util.WTMessage;

public class TemplatePicker extends AbstractHtmlTag
{

    public TemplatePicker()
    {
    }

    public String getLabel()
    {
        return label;
    }

    public void setLabel(String s)
    {
        label = s;
    }

    public String getToolTip()
    {
        return toolTip;
    }

    public void setToolTip(String s)
    {
        toolTip = s;
    }

    public String getId()
    {
        return id;
    }

    public void setId(String s)
    {
        id = s;
    }

    public void doTag()
        throws JspException
    {
        ArrayList arraylist;
        ArrayList arraylist1;
        ArrayList arraylist2;
        PageContext pagecontext;
        JspWriter jspwriter;
        NmCommandBean nmcommandbean;
        ArrayList arraylist3;
        String s1;
        String s2;
        String s3;
        ComboBox combobox;
        String s5;
        String s6;
        RenderPropertyPanelTag renderpropertypaneltag;
        RenderingContext renderingcontext;
        try
        {
            arraylist = new ArrayList();
            arraylist1 = new ArrayList();
            arraylist2 = new ArrayList();
            pagecontext = (PageContext)getJspContext();
            jspwriter = pagecontext.getOut();
            NmHelperBean nmhelperbean = new NmHelperBean(getJspContext());
            nmcommandbean = nmhelperbean.getNmCommandBean();
            wt.inf.container.WTContainerRef wtcontainerref = CreateAndEditWizBean.getContainerRef(nmcommandbean);
            wt.fc.WTReference wtreference = CreateAndEditWizBean.getDefaultAdminDomainRef(nmcommandbean);
            LOGGER.debug((new StringBuilder()).append("adminDomainRef :").append(wtreference).toString());
            arraylist3 = WTDocumentHelper.service.getTemplates(wtcontainerref, (AdminDomainRef)wtreference);
            if(arraylist3.size() == 0)
            {
                jspwriter.println("<table class='pp'>");
                String s = WTMessage.getLocalizedMessage("com.ptc.windchill.enterprise.doc.documentResource", "NO_TEMPLATES", null);
                Label label1 = new Label((new StringBuilder()).append("<B>").append(s).append("</B>").toString());
                render(label1, pagecontext);
                jspwriter.println("</table>");
                return;
            }
        }
        catch(Exception exception)
        {
            throw new JspException(exception);
        }
        s1 = null;
        s2 = NmCommandBean.convert(nmcommandbean.getRequest().getParameter("doctemplate"));
        for(int i = 0; i < arraylist3.size(); i++)
        {
            String as[] = (String[])(String[])arraylist3.get(i);
            String s4 = as[1];
            com.ptc.core.meta.common.TypeIdentifier typeidentifier = TypeHelper.getTypeIdentifier(as[3]);
            String s7 = TypeHelper.getLocalizedTypeString(typeidentifier, nmcommandbean.getLocale());
            String s8 = as[4];
            if(i == 0)
                s1 = s8;
            if(s8.equals(s2))
                arraylist2.add(s2);
            Object aobj[] = {
                s7, s4
            };
            String s9 = WTMessage.getLocalizedMessage("com.ptc.windchill.enterprise.doc.documentResource", "TEMPLATE_NAME", aobj);
            arraylist.add(s9);
            arraylist1.add(s8);
        }

        s3 = CreateAndEditWizBean.getCurrentObjectHandle(nmcommandbean.getRequest());
        combobox = new ComboBox(arraylist1, arraylist, arraylist2);
        if(label == null)
            label = WTMessage.getLocalizedMessage("com.ptc.windchill.enterprise.doc.documentResource", "TEMPLATE_LABEL", null);
        combobox.setLabel(label);
        if(toolTip != null)
            combobox.setTooltip(toolTip);
        combobox.setRenderLabel(false);
        combobox.setName("doctemplate");
        combobox.addHiddenField("templateOid", s1);
        combobox.addHiddenField("PrePopulateObjectList", s1);
        if(id == null)
            id = "createType";
        combobox.setId(id);
        s5 = "/servlet/TypeBasedIncludeServlet?contextAction=defineItemAttributesPanel";
        if(!"".equals(s3))
            s5 = (new StringBuilder()).append(s5).append("&currentObjectHandle=").append(s3).toString();
        s6 = (new StringBuilder()).append("refreshDriverAttributes('").append(s5).append("');").toString();
        combobox.addJsAction("onChange", (new StringBuilder()).append("pickerGo(this.value,'").append(s3).append("',").append("'true');").append(s6).toString());
        combobox.setMultiSelect(false);
        combobox.addStyleClass("ppdata");
        combobox.setRequired(true);
        renderpropertypaneltag = (RenderPropertyPanelTag)findAncestorWithClass(this, com/ptc/core/components/tags/propertyPanel/RenderPropertyPanelTag);
        renderingcontext = new RenderingContext(pagecontext);
        if(renderpropertypaneltag == null)
        {
            jspwriter.println("<table class='pp'>");
            jspwriter.println((new StringBuilder()).append("<td align=left>").append(combobox.getLabel()).append("</td>").toString());
            jspwriter.println("<td valign=middle>");
            render(combobox, pagecontext);
            jspwriter.println("</td>");
            jspwriter.println("</table>");
        } else
        {
            renderpropertypaneltag.addGuiComponent(combobox, combobox.getLabel(), renderingcontext);
        }
    }

    private static final Logger LOGGER;
    public static final String RESOURCE = "com.ptc.windchill.enterprise.doc.documentResource";
    private String label;
    private String toolTip;
    private String id;

    static 
    {
        try
        {
            LOGGER = LogR.getLogger(com/ptc/windchill/enterprise/doc/tags/TemplatePicker.getName());
        }
        catch(Exception exception)
        {
            throw new ExceptionInInitializerError(exception);
        }
    }
}
