com.jiangyifen.ec2.ui.mgr.outlinemanage.AddOutline.java Source code

Java tutorial

Introduction

Here is the source code for com.jiangyifen.ec2.ui.mgr.outlinemanage.AddOutline.java

Source

package com.jiangyifen.ec2.ui.mgr.outlinemanage;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.TreeMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jiangyifen.ec2.bean.MobileAreacode;
import com.jiangyifen.ec2.bean.SipConfigType;
import com.jiangyifen.ec2.entity.AutoDialoutTask;
import com.jiangyifen.ec2.entity.Domain;
import com.jiangyifen.ec2.entity.Phone2PhoneSetting;
import com.jiangyifen.ec2.entity.Queue;
import com.jiangyifen.ec2.entity.SipConfig;
import com.jiangyifen.ec2.entity.User;
import com.jiangyifen.ec2.entity.UserQueue;
import com.jiangyifen.ec2.globaldata.ShareData;
import com.jiangyifen.ec2.service.csr.ami.QueueMemberRelationService;
import com.jiangyifen.ec2.service.csr.ami.ReloadAsteriskService;
import com.jiangyifen.ec2.service.eaoservice.AutoDialoutTaskService;
import com.jiangyifen.ec2.service.eaoservice.Phone2PhoneSettingService;
import com.jiangyifen.ec2.service.eaoservice.QueueService;
import com.jiangyifen.ec2.service.eaoservice.SipConfigService;
import com.jiangyifen.ec2.service.eaoservice.UserQueueService;
import com.jiangyifen.ec2.ui.mgr.system.tabsheet.OutlineManagement;
import com.jiangyifen.ec2.ui.mgr.util.StyleConfig;
import com.jiangyifen.ec2.ui.utils.CustomComboBox;
import com.jiangyifen.ec2.utils.SpringContextHolder;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.util.BeanItem;
import com.vaadin.data.validator.RegexpValidator;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;
import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.OptionGroup;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

/**
 * 
 * @author jrh
 */
@SuppressWarnings("serial")
public class AddOutline extends Window implements ClickListener, ValueChangeListener {
    // 
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    //  form ???
    private final Object[] TYPICAL_VISIBLE_PROPERTIES = new Object[] { "sipType", "name", "username", "secret",
            "host", "call_limit", "belong", "ispopupWin" };
    private final Object[] TYPICAL_VISIBLE_PROPERTIES_CAPTION = new Object[] { "", "??",
            "??", "?", "SIP?", "??", "", "??" };

    //  form   
    private final String[] TYPICAL_REQUIRED_PROPERTIES = new String[] { "sipType", "name", "username", "secret",
            "host", "call_limit", "belong", "ispopupWin" };

    //  form ???
    private final Object[] ADVANCED_VISIBLE_PROPERTIES = new Object[] { "sipType", "name", "username", "secret",
            "host", "call_limit", "belong", "ispopupWin", // 
            "context", "type", "qualify", "canreinvite", "nat", "disallow", "allow", "insecure", "fromuser",
            "fromdomain", "isDefaultOutline", // 
            "port", "cancallforward", "pickupgroup", "callgroup", "regseconds", "lastms", "defaultuser",
            "regserver", "regexten", "fullcontact", "subscribecontext", "accountcode", "amaflags", "callerid",
            "defaultip", "dtmfmode", "language", "ipaddr", "mailbox", "md5secret", "permit", "deny", "mask",
            "musiconhold", "restrictcid", "rtptimeout", "rtpholdtimeout", "setvar" };

    //   form   
    private final String[] ADVANCED_REQUIRED_PROPERTIES = new String[] { "sipType", "name", "username", "secret",
            "host", "call_limit", "belong", "ispopupWin", "context", "type", "qualify", "canreinvite", "nat",
            "disallow", "allow", "insecure", "fromuser", "fromdomain", "isDefaultOutline" };

    private final Object[] ADVANCED_REQUIRED_PROPERTIES_CAPTION = new Object[] { "", "??",
            "??", "?", "SIP?", "??", "", "??", "?",
            "", "", "?", "?", "???", "??",
            "??", "?", "?", "?" };
    /**
     * ?   
     */
    //Form
    private Form form;

    //  ?SIP
    private ComboBox sipType;

    //??
    private Button save;
    private Button cancel;
    private OptionGroup settingType; // ??

    /**
     * ?
     */
    private Domain domain;
    private SipConfig sipConfig;
    private OutlineManagement outlineManagement;
    private SipConfigService sipConfigService; // sip ?
    private ReloadAsteriskService reloadAsteriskService; // ?asterisk ?
    private QueueMemberRelationService queueMemberRelationService; // ???
    private Phone2PhoneSettingService phone2PhoneSettingService; // ??
    private UserQueueService userQueueService; // ???
    private QueueService queueService; // ?
    private AutoDialoutTaskService autoDialoutTaskService; // ???

    public AddOutline(OutlineManagement outlineManagement) {
        this.center();
        this.setModal(true);
        this.setResizable(false);
        this.setWidth("360px");
        this.setHeight("335px");
        this.setCaption("");
        this.outlineManagement = outlineManagement;

        domain = SpringContextHolder.getDomain();
        sipConfigService = SpringContextHolder.getBean("sipConfigService");
        reloadAsteriskService = SpringContextHolder.getBean("reloadAsteriskService");
        queueMemberRelationService = SpringContextHolder.getBean("queueMemberRelationService");
        phone2PhoneSettingService = SpringContextHolder.getBean("phone2PhoneSettingService");
        userQueueService = SpringContextHolder.getBean("userQueueService");
        queueService = SpringContextHolder.getBean("queueService");
        autoDialoutTaskService = SpringContextHolder.getBean("autoDialoutTaskService");

        //WindowLayout
        VerticalLayout windowContent = new VerticalLayout();
        windowContent.setSizeUndefined();
        windowContent.setMargin(false, true, true, true);
        windowContent.setSpacing(true);
        windowContent.setStyleName(StyleConfig.VERTICAL_STYLE);
        this.setContent(windowContent);

        // Form ?
        createFormComponent(windowContent);
    }

    /**
     * attach 
     */
    @Override
    public void attach() {
        super.attach();
        sipConfig = new SipConfig();
        sipConfig.setSipType(SipConfigType.sip_outline);
        settingType.setValue("typical");

        // ??
        createTypicalSipConfig();
    }

    /**
     * Form ?
     * @param windowContent
     */
    private void createFormComponent(VerticalLayout windowContent) {
        form = new Form();
        form.setValidationVisible(false);
        form.setValidationVisibleOnCommit(true);
        form.setInvalidCommitted(false);
        form.setWriteThrough(false);
        form.setImmediate(true);
        form.addStyleName("chb");
        form.setFormFieldFactory(new MyFieldFactory());
        form.setFooter(creatFormFooterComponents());
        windowContent.addComponent(form);
    }

    /**
     *  ??
     */
    private void createTypicalSipConfig() {
        //Form??
        form.setItemDataSource(new BeanItem<SipConfig>(sipConfig), Arrays.asList(TYPICAL_VISIBLE_PROPERTIES));
        for (int i = 0; i < TYPICAL_VISIBLE_PROPERTIES.length; i++) {
            form.getField(TYPICAL_VISIBLE_PROPERTIES[i])
                    .setCaption(TYPICAL_VISIBLE_PROPERTIES_CAPTION[i].toString() + "");
        }

        // 
        for (String required : TYPICAL_REQUIRED_PROPERTIES) {
            form.getField(required).setRequired(true);
            form.getField(required).setRequiredError(required + " ??");
        }

        form.getField("ispopupWin").setValue(true);
    }

    /**
     * advanced?
     */
    private void createAdvancedSipConfig() {
        //Form??
        form.setItemDataSource(new BeanItem<SipConfig>(sipConfig), Arrays.asList(ADVANCED_VISIBLE_PROPERTIES));
        for (int i = 0; i < ADVANCED_VISIBLE_PROPERTIES.length; i++) {
            form.getField(ADVANCED_VISIBLE_PROPERTIES[i])
                    .setCaption(ADVANCED_VISIBLE_PROPERTIES[i].toString() + "");
        }

        // 
        form.getField("context").setValue("incoming");
        form.getField("type").setValue("friend");
        form.getField("qualify").setValue("yes");
        form.getField("canreinvite").setValue("yes");
        form.getField("nat").setValue("yes");
        //      asterisk 11 ?force_rport,comedia ??? yes 
        //      form.getField("nat").setValue("force_rport,comedia");
        form.getField("cancallforward").setValue("yes");
        form.getField("disallow").setValue("all");
        form.getField("allow").setValue("alaw");
        form.getField("regseconds").setValue("0");
        form.getField("lastms").setValue("-1");
        form.getField("port").setValue("5060");
        form.getField("insecure").setValue("port,invite");
        form.getField("ispopupWin").setValue(true);

        // ???
        SipConfig originalDefaultOutline = sipConfigService.getDefaultOutlineByDomain(domain);
        if (originalDefaultOutline == null) {
            form.getField("isDefaultOutline").setValue(true);
            form.getField("isDefaultOutline").setReadOnly(true);
        } else {
            form.getField("isDefaultOutline").setValue(false);
        }

        // 
        for (int i = 0; i < ADVANCED_REQUIRED_PROPERTIES.length; i++) {
            form.getField(ADVANCED_REQUIRED_PROPERTIES[i]).setRequired(true);
            form.getField(ADVANCED_REQUIRED_PROPERTIES[i])
                    .setCaption(ADVANCED_REQUIRED_PROPERTIES_CAPTION[i].toString());
            form.getField(ADVANCED_REQUIRED_PROPERTIES[i])
                    .setRequiredError(ADVANCED_REQUIRED_PROPERTIES[i] + " ??");
        }
    }

    /**
     * Form ?
     * @return HorizontalLayout ?
     */
    private HorizontalLayout creatFormFooterComponents() {
        HorizontalLayout buttonsLayout = new HorizontalLayout();
        buttonsLayout.setSpacing(true);
        buttonsLayout.setWidth("100%");

        // ?
        save = new Button("?", this);
        save.setStyleName("default");
        buttonsLayout.addComponent(save);

        // ?
        cancel = new Button("?", this);
        buttonsLayout.addComponent(cancel);

        // ??
        Label settingTypeLabel = new Label("??");
        settingTypeLabel.setWidth("-1px");
        buttonsLayout.addComponent(settingTypeLabel);
        buttonsLayout.setComponentAlignment(settingTypeLabel, Alignment.MIDDLE_CENTER);

        // ??
        settingType = new OptionGroup();
        settingType.addItem("typical");
        settingType.addItem("advanced");
        settingType.select("typical");
        settingType.setItemCaption("typical", "?");
        settingType.setItemCaption("advanced", "");
        settingType.setImmediate(true);
        settingType.setStyleName("twocol100");
        settingType.addListener((ValueChangeListener) this);
        buttonsLayout.addComponent(settingType);
        buttonsLayout.setComponentAlignment(settingType, Alignment.MIDDLE_CENTER);

        return buttonsLayout;
    }

    @Override
    public void valueChange(ValueChangeEvent event) {
        Property source = event.getProperty();
        if (source == sipType) {
            TextField hostField = (TextField) form.getField("host");
            if (hostField != null) {
                if (SipConfigType.gateway_outline.equals(sipType.getValue())) {
                    hostField.setValue("dynamic");
                } else {
                    hostField.setValue("");
                }
            }
        } else {
            this.center();
            String typeValue = (String) settingType.getValue();
            if ("advanced".equals(typeValue)) {
                this.setHeight("700px");
                this.setWidth("395px");
                // advanced?
                createAdvancedSipConfig();
            } else {
                this.setWidth("360px");
                this.setHeight("335px");
                // ??
                createTypicalSipConfig();
            }
        }
    }

    @Override
    public void buttonClick(ClickEvent event) {
        Button source = event.getButton();
        if (source == save) {
            String outlineName = (String) form.getField("name").getValue();
            try {
                form.commit();
                // ??
                if (!"".equals(outlineName) && sipConfigService.existBySipname(outlineName)) {
                    this.showNotification(
                            "?? " + outlineName + " ??????");
                    return;
                }
            } catch (Exception e) {
                return;
            }
            // ?
            boolean saveSuccess = executeSave(outlineName);
            if (saveSuccess) {
                // ????  ShareData 
                List<String> outlines = ShareData.domainToOutlines.get(domain.getId());
                if (outlines == null) {
                    outlines = new ArrayList<String>();
                    ShareData.domainToOutlines.put(domain.getId(), outlines);
                }
                outlines.add(outlineName);

                // SIP??
                if (SipConfigType.sip_outline.equals(sipType.getValue())) {
                    // asterisk ?  sip_regirster_domainname.conf
                    sipConfigService.updateAsteriskRegisterSipConfigFile(domain);
                }

                // asterisk ?  sip_outline_domainname.conf
                sipConfigService.updateAsteriskOutlineSipConfigFile(domain);
                // ?? ?asterisk ?
                reloadAsteriskService.reloadSip();

                this.getParent().removeWindow(this);
            }
        } else if (source == cancel) {
            form.discard();
            this.getParent().removeWindow(this);
        }
    }

    /**
     * buttonClick  ?
     * @return
     */
    private boolean executeSave(String name) {
        // ?
        SipConfig originalDefaultOutline = null;
        // ????
        boolean isDefaultOutline = false;
        String settingTypeValue = (String) settingType.getValue();

        if ("typical".equals(settingTypeValue)) {
            String host = (String) form.getField("host").getValue();
            sipConfig.setFromdomain(host);
            String outlineUsername = (String) form.getField("username").getValue();
            sipConfig.setFromuser(outlineUsername);
            sipConfig.setInsecure("port,invite");
            sipConfig.setContext("incoming");
            sipConfig.setIsDefaultOutline(false);
            sipConfig.setNat("yes");
            //         asterisk 11 ?force_rport,comedia ??? yes 
            //         sipConfig.setNat("force_rport,comedia");
        }
        sipConfig.setDomain(domain);

        try {
            //  ???????????????
            if (form.getField("isDefaultOutline") != null) {
                isDefaultOutline = (Boolean) form.getField("isDefaultOutline").getValue();
            }
            originalDefaultOutline = sipConfigService.getDefaultOutlineByDomain(domain);
            if (originalDefaultOutline == null) { // ?   typical?
                sipConfig.setIsDefaultOutline(true);
                // ??
                updatePhoneInQueueMember(name, null);
            } else if (originalDefaultOutline != null && isDefaultOutline == true) { // advanced?
                originalDefaultOutline.setIsDefaultOutline(false);
                sipConfigService.update(originalDefaultOutline);
                // ??, ??
                updatePhoneInQueueMember(name, originalDefaultOutline.getUsername());
                // ?
                updatePhoneInAutoQueueMember(name, originalDefaultOutline.getUsername());
            }
        } catch (Exception e1) {
            logger.error(e1.getMessage() + "", e1);
            this.getApplication().getMainWindow().showNotification(
                    "????", Notification.TYPE_WARNING_MESSAGE);
            return false;
        }

        try {
            sipConfig = sipConfigService.update(sipConfig);

            // outlineManagementTable
            outlineManagement.updateTable(true);
            outlineManagement.getTable().setValue(null);
        } catch (Exception e) {
            // ??????
            if (isDefaultOutline == true && originalDefaultOutline != null) { // advanced?typical???
                originalDefaultOutline.setIsDefaultOutline(true);
                sipConfigService.update(originalDefaultOutline);
            }

            logger.error(e.getMessage() + "?", e);
            this.getApplication().getMainWindow().showNotification(
                    "????", Notification.TYPE_WARNING_MESSAGE);
            return false;
        }

        // ???
        if (sipConfig.getIsDefaultOutline() == true) {
            ShareData.domainToDefaultOutline.put(domain.getId(), name);
        }

        return true;
    }

    /**
     *    ????
     * @param currentOutlineName   ???
     * @param originalOutlineName   ???
     */
    private void updatePhoneInQueueMember(String currentOutlineName, String originalOutlineName) {
        // ?
        Phone2PhoneSetting globalSetting = phone2PhoneSettingService.getGlobalSettingByDomain(domain.getId());
        // ??
        if (globalSetting == null) {
            return;
        }

        // ??
        List<Queue> allCommonQueues = queueService.getAllByDomain(domain, true);
        List<String> allCommonQueueNames = new ArrayList<String>();
        for (Queue autoQueue : allCommonQueues) {
            allCommonQueueNames.add(autoQueue.getName());
        }

        // ???
        boolean isGlobalRunning = phone2PhoneSettingService.confirmSettingIsRunning(globalSetting);
        if (isGlobalRunning) {
            // ????
            if (globalSetting.getIsSpecifiedPhones()) {
                for (String phoneNum : globalSetting.getSpecifiedPhones()) {
                    for (String queueName : allCommonQueueNames) {
                        if (originalOutlineName != null) {
                            queueMemberRelationService.removeQueueMemberRelation(queueName,
                                    phoneNum + "@" + originalOutlineName);
                        }
                        queueMemberRelationService.addQueueMemberRelation(queueName,
                                phoneNum + "@" + currentOutlineName, 5);
                    }
                }
                // ??????????
                return;
            }

            // ???
            for (User specifiedCsr : globalSetting.getSpecifiedCsrs()) {
                // ???,???
                String phoneNum = specifiedCsr.getPhoneNumber();
                if (phoneNum == null || "".equals(phoneNum)) {
                    continue;
                }
                updateSpecifyCsrQueueMember(specifiedCsr, currentOutlineName, originalOutlineName, phoneNum,
                        allCommonQueueNames);
            }
        }

        // ??(??????)
        // ?? 1??????2???????
        List<Phone2PhoneSetting> customSettings = phone2PhoneSettingService.getAllCsrCustomSettings(domain.getId());
        for (Phone2PhoneSetting customSetting : customSettings) {
            // ???,???
            User csr = customSetting.getCreator();
            String phoneNum = csr.getPhoneNumber();
            if (phoneNum == null || "".equals(phoneNum)) {
                continue;
            }

            // ?????
            boolean needUpdateSpecifyCsr = true;
            if (!globalSetting.getIsSpecifiedPhones()) {
                for (User specifiedCsr : globalSetting.getSpecifiedCsrs()) {
                    // ????[???]
                    if (specifiedCsr.getId() == csr.getId()) {
                        needUpdateSpecifyCsr = false;
                        break;
                    }
                }
            }

            // 3????4???5?? <= ?,  >= ?
            if (needUpdateSpecifyCsr && globalSetting.getIsLicensed2Csr()) {
                boolean isCustomRunning = phone2PhoneSettingService.confirmSettingIsRunning(customSetting);
                if (isCustomRunning) {
                    updateSpecifyCsrQueueMember(csr, currentOutlineName, originalOutlineName, phoneNum,
                            allCommonQueueNames);
                }
            }
        }
    }

    /**
     * ?
     * @param currentOutlineName   ???
     * @param originalOutlineName   ???
     */
    private void updatePhoneInAutoQueueMember(String currentOutlineName, String originalOutlineName) {
        List<AutoDialoutTask> autoDialoutTasks = autoDialoutTaskService.getAllByDialoutType(domain, "");
        for (AutoDialoutTask autoDialoutTask : autoDialoutTasks) {
            Queue queue = autoDialoutTask.getQueue();
            String queueName = queue.getName();
            Set<String> phoneNos = autoDialoutTask.getPhoneNos();
            if (phoneNos == null) {
                continue;
            }
            for (String phoneNo : phoneNos) {
                queueMemberRelationService.removeQueueMemberRelation(queueName,
                        phoneNo + "@" + originalOutlineName);
                queueMemberRelationService.addQueueMemberRelation(queueName, phoneNo + "@" + currentOutlineName, 5);
            }
        }
    }

    /**
     * ??????
     * @param csr               ?
     * @param outlineName         ?
     * @param originalOutlineName   ?
     * @param phoneNum            ????
     * @param allCommonQueueNames   ?
     */
    private void updateSpecifyCsrQueueMember(User csr, String outlineName, String originalOutlineName,
            String phoneNum, List<String> allCommonQueueNames) {
        // ???? 
        if (ShareData.userToExten.keySet().contains(csr.getId())) {
            return;
        }

        // ???????
        List<UserQueue> userQueues = userQueueService.getAllByUsername(csr.getUsername());
        for (UserQueue userQueue : userQueues) {
            String queueName = userQueue.getQueueName();
            if (allCommonQueueNames.contains(queueName)) { // ?????,????
                if (originalOutlineName != null) {
                    queueMemberRelationService.removeQueueMemberRelation(userQueue.getQueueName(),
                            phoneNum + "@" + originalOutlineName);
                }
                queueMemberRelationService.addQueueMemberRelation(userQueue.getQueueName(),
                        phoneNum + "@" + outlineName, 5);
            }
        }
    }

    private class MyFieldFactory extends DefaultFieldFactory {
        private String ipRegex = "([1-9]||[1-9]\\d||1\\d{2}||2[0-4]\\d||25[0-5])(\\.(\\d||[1-9]\\d||1\\d{2}||2[0-4]\\d|25[0-5])){3}";
        private String mailRegex = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";

        @Override
        public Field createField(Item item, Object propertyId, Component uiContext) {
            if ("sipType".equals(propertyId)) {
                sipType = new ComboBox();
                sipType.setImmediate(true);
                sipType.addItem(SipConfigType.sip_outline);
                sipType.addItem(SipConfigType.gateway_outline);
                sipType.setWidth("200px");
                sipType.addListener((ValueChangeListener) AddOutline.this);
                sipType.setNullSelectionAllowed(false);
                return sipType;
            } else if ("type".equals(propertyId)) {
                ComboBox comboBox = new ComboBox();
                comboBox.setImmediate(true);
                comboBox.addItem("friend");
                comboBox.addItem("user");
                comboBox.addItem("peer");
                comboBox.setWidth("200px");
                comboBox.setNullSelectionAllowed(false);
                return comboBox;
            } else if ("qualify".equals(propertyId)) {
                ComboBox comboBox = new ComboBox();
                comboBox.setImmediate(true);
                comboBox.setWidth("200px");
                comboBox.addItem("yes");
                comboBox.addItem("no");
                comboBox.setNullSelectionAllowed(false);
                return comboBox;
            } else if ("canreinvite".equals(propertyId)) {
                ComboBox comboBox = new ComboBox();
                comboBox.setImmediate(true);
                comboBox.setWidth("200px");
                comboBox.addItem("yes");
                comboBox.addItem("no");
                comboBox.setNullSelectionAllowed(false);
                return comboBox;
            } else if ("belong".equals(propertyId)) {
                ComboBox comboBox = new ComboBox();
                comboBox.setImmediate(true);
                comboBox.setWidth("200px");
                comboBox.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS);
                for (MobileAreacode areacode : ShareData.areacodeList) {
                    comboBox.addItem(areacode.getAreaCode());
                    comboBox.setItemCaption(areacode.getAreaCode(),
                            areacode.getMobileArea() + "(" + areacode.getAreaCode() + ")");
                }
                comboBox.setNullSelectionAllowed(false);
                return comboBox;
            } else if ("ispopupWin".equals(propertyId)) {
                ComboBox comboBox = new ComboBox();
                comboBox.setImmediate(true);
                comboBox.setWidth("200px");
                comboBox.addItem(true);
                comboBox.addItem(false);
                comboBox.setItemCaption(true, "?-?");
                comboBox.setItemCaption(false, "?-??");
                comboBox.setValue(true);
                comboBox.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS);
                comboBox.setNullSelectionAllowed(false);
                return comboBox;
            } else if ("isDefaultOutline".equals(propertyId)) {
                TreeMap<Boolean, String> treeMap = new TreeMap<Boolean, String>();
                treeMap.put(true, "yes");
                treeMap.put(false, "no");

                CustomComboBox customComboBox = new CustomComboBox();
                customComboBox.setWidth("200px");
                customComboBox.setDataSource(treeMap);
                customComboBox.setNullSelectionAllowed(false);

                return customComboBox;
            } else if ("nat".equals(propertyId)) {
                ComboBox comboBox = new ComboBox();
                comboBox.setImmediate(true);
                comboBox.setWidth("200px");
                comboBox.addItem("yes");
                comboBox.addItem("no");
                //            asterisk 11 ?force_rport,comedia ??? yes 
                //            comboBox.addItem("force_rport,comedia");
                comboBox.setNullSelectionAllowed(false);
                return comboBox;
            } else if ("cancallforward".equals(propertyId)) {
                ComboBox comboBox = new ComboBox();
                comboBox.setImmediate(true);
                comboBox.setWidth("200px");
                comboBox.addItem("yes");
                comboBox.addItem("no");
                comboBox.setNullSelectionAllowed(false);
                return comboBox;
            }

            Field field = DefaultFieldFactory.get().createField(item, propertyId, uiContext);
            field.setWidth("200px");

            if ("call_limit".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\d{1,4}", "call_limit ??10000!"));
            } else if ("name".equals(propertyId)) {
                field.addValidator(
                        new RegexpValidator("\\d{0,80}", "username ??80??"));
            } else if ("username".equals(propertyId)) {
                field.addValidator(
                        new RegexpValidator("\\d{0,80}", "username ??80??"));
            } else if ("secret".equals(propertyId)) {
                field.addValidator(
                        new RegexpValidator("\\d{0,80}", "secret ??80??"));
            } else if ("context".equals(propertyId)) {
                field.addValidator(
                        new RegexpValidator("\\w{0,80}", "context ??80??"));
            } else if ("fromuser".equals(propertyId)) {
                field.addValidator(
                        new RegexpValidator("\\d{0,80}", "fromuser ??80??"));
            } else if ("disallow".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,100}",
                        "disallow ??100??"));
            } else if ("allow".equals(propertyId)) {
                field.addValidator(
                        new RegexpValidator("\\w{0,100}", "allow ??100??"));
            } else if ("host".equals(propertyId)) {
                field.addValidator(new RegexpValidator(ipRegex + "||(dynamic)",
                        "host ?ip?dynamic"));
            } else if ("fromdomain".equals(propertyId)) {
                field.addValidator(new RegexpValidator(ipRegex + "||(dynamic)",
                        "fromdomain ?ip?dynamic"));
            } else if ("lastms".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\-?\\d{1,4}", "lastms ??10000"));
            } else if ("amaflags".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,7}",
                        "amaflags ??7??"));
            } else if ("regseconds".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\d{0,18}",
                        "regseconds ??18??"));
            } else if ("defaultuser".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\d{0,80}",
                        "defaultuser ??80??"));
            } else if ("mask".equals(propertyId)) {
                field.addValidator(new RegexpValidator(ipRegex, "mask ip?"));
            } else if ("accountcode".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,20}",
                        "accountcode ??20??"));
            } else if ("callgroup".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,10}",
                        "callgroup ??10??"));
            } else if ("callerid".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,80}",
                        "callerid ??80??"));
            } else if ("defaultip".equals(propertyId)) {
                field.addValidator(new RegexpValidator(ipRegex, "defaultip ip?"));
            } else if ("dtmfmode".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,7}",
                        "dtmfmode ??7??"));
            } else if ("fullcontact".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,80}",
                        "fullcontact ??80??"));
            } else if ("ipaddr".equals(propertyId)) {
                field.addValidator(new RegexpValidator(ipRegex, "ipaddr ip?"));
            } else if ("port".equals(propertyId)) {
                field.addValidator(
                        new RegexpValidator("\\d{0,5}", "port ??5??"));
            } else if ("regserver".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,100}",
                        "regserver ??100??"));
            } else if ("insecure".equals(propertyId)) {
                field.addValidator(new RegexpValidator("(\\w*,?\\w*)*",
                        "insecure ??80??"));
            } else if ("mailbox".equals(propertyId)) {
                field.addValidator(new RegexpValidator(mailRegex, "mailbox ??"));
            } else if ("language".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,2}",
                        "language ??2??"));
            } else if ("md5secret".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,80}",
                        "md5secret ??80??"));
            } else if ("permit".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,95}",
                        "permit ??95??"));
            } else if ("deny".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,95}",
                        "deny ??95??"));
            } else if ("musiconhold".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,100}",
                        "musiconhold ??100??"));
            } else if ("pickupgroup".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,100}",
                        "pickupgroup ??100??"));
            } else if ("regexten".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,80}",
                        "regexten ??80??"));
            } else if ("restrictcid".equals(propertyId)) {
                field.addValidator(
                        new RegexpValidator("\\d{0,1}", "restrictcid ??10"));
            } else if ("rtptimeout".equals(propertyId)) {
                field.addValidator(
                        new RegexpValidator("\\d{0,3}", "rtptimeout ??999"));
            } else if ("rtpholdtimeout".equals(propertyId)) {
                field.addValidator(
                        new RegexpValidator("\\d{0,3}", "rtpholdtimeout ??999"));
            } else if ("setvar".equals(propertyId)) {
                field.addValidator(new RegexpValidator("\\w{0,100}",
                        "setvar ??100??"));
            }

            if (field instanceof TextField) {
                ((TextField) field).setNullRepresentation("");
                ((TextField) field).setNullSettingAllowed(true);
                ((TextField) field).setImmediate(true);
            }

            return field;
        }
    }

}