Java tutorial
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 EditOutline 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", "type", "context", "qualify", "canreinvite", "nat", "disallow", "allow", "call_limit", "belong", "ispopupWin", "isDefaultOutline" }; private final Object[] TYPICAL_VISIBLE_PROPERTIES_CAPTION = new Object[] { "", "??", "??", "?", "SIP?", "", "?", "", "?", "?", "???", "??", "??", "?", "??", "?" }; // form private final String[] TYPICAL_REQUIRED_PROPERTIES = new String[] { "sipType", "name", "username", "secret", "host", "type", "context", "qualify", "canreinvite", "nat", "disallow", "allow", "call_limit", "belong", "ispopupWin", "isDefaultOutline" }; // form ??? private final Object[] ADVANCED_VISIBLE_PROPERTIES = new Object[] { "sipType", "name", "username", "secret", "host", "type", "context", // "qualify", "canreinvite", "nat", "disallow", "allow", "call_limit", "belong", "ispopupWin", "isDefaultOutline", "insecure", "fromuser", "fromdomain", // "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", "type", "context", "qualify", "canreinvite", "nat", "disallow", "allow", "call_limit", "belong", "ispopupWin", "isDefaultOutline", "insecure", "fromuser", "fromdomain" }; private final Object[] ADVANCED_REQUIRED_PROPERTIES_CAPTION = new Object[] { "", "??", "??", "?", "SIP?", "", "?", "", "?", "?", "???", "??", "??", "", "??", "?", "??", "?", "?" }; /** * ? */ private OptionGroup settingType; // ? //Form private Form form; // ?SIP private ComboBox sipType; //?? private Button save; private Button cancel; /** * ? */ private Domain domain; // private String oldSipname; // ??? 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 EditOutline(OutlineManagement outlineManagement) { this.center(); this.setModal(true); this.setWidth("360px"); this.setHeight("565px"); this.setResizable(false); 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 = (SipConfig) outlineManagement.getTable().getValue(); oldSipname = sipConfig.getName(); settingType.setValue("typical"); // ?? typicalEditOutline(); } /** * Form ? * @param windowContent */ private void createFormComponent(VerticalLayout windowContent) { form = new Form(); form.setValidationVisibleOnCommit(true); form.setValidationVisible(false); form.setInvalidCommitted(false); form.setWriteThrough(false); form.setImmediate(true); form.addStyleName("chb"); form.setFormFieldFactory(new MyFieldFactory()); form.setFooter(creatFormFooterComponents()); windowContent.addComponent(form); } /** * ?? */ private void typicalEditOutline() { //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()); } // ? form.getField("type").setValue(sipConfig.getType()); form.getField("qualify").setValue(sipConfig.getQualify()); form.getField("canreinvite").setValue(sipConfig.getCanreinvite()); form.getField("nat").setValue(sipConfig.getNat()); form.getField("isDefaultOutline").setValue(sipConfig.getIsDefaultOutline()); // ?? if (sipConfig.getIsDefaultOutline() == true) { form.getField("isDefaultOutline").setReadOnly(true); } // for (String required : TYPICAL_REQUIRED_PROPERTIES) { form.getField(required).setRequired(true); form.getField(required).setRequiredError(required + " ??"); } } /** * ?? */ private void advancedEditOutline() { //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("type").setValue(sipConfig.getType()); form.getField("qualify").setValue(sipConfig.getQualify()); form.getField("canreinvite").setValue(sipConfig.getCanreinvite()); form.getField("isDefaultOutline").setValue(sipConfig.getIsDefaultOutline()); form.getField("nat").setValue(sipConfig.getNat()); form.getField("cancallforward").setValue(sipConfig.getCancallforward()); // ?? if (sipConfig.getIsDefaultOutline() == true) { form.getField("isDefaultOutline").setReadOnly(true); } // 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] + " ??"); } } /** * * @return */ 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("380px"); // ? advancedEditOutline(); } else { this.setWidth("360px"); this.setHeight("565px"); // ?? typicalEditOutline(); } } } @Override public void buttonClick(ClickEvent event) { Button source = event.getButton(); if (source == save) { // ?name username ?? String outlineName = (String) form.getField("name").getValue(); System.out.println("outlineName:" + outlineName); try { form.commit(); if (!"".equals(outlineName) && !outlineName.equals(oldSipname) && sipConfigService.existBySipname(outlineName)) { this.getApplication().getMainWindow() .showNotification("? " + outlineName + " ????"); return; } } catch (Exception e) { return; } boolean saveSuccess = executeSave(outlineName); if (saveSuccess == true) { // ?? (ShareData ?Map) updateShareData(outlineName); // ?sip ??? if (SipConfigType.sip_outline.equals(sipConfig.getSipType())) { // 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 outlineName) { // ? 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); } try { // ?????? if (form.getField("isDefaultOutline").isReadOnly() == false) { isDefaultOutline = (Boolean) form.getField("isDefaultOutline").getValue(); if (isDefaultOutline == true) { // ??????????????? originalDefaultOutline = sipConfigService.getDefaultOutlineByDomain(domain); if (originalDefaultOutline != null) { // ? originalDefaultOutline.setIsDefaultOutline(false); sipConfigService.update(originalDefaultOutline); // ??, ?? updatePhoneInQueueMember(outlineName, originalDefaultOutline.getUsername()); // ? updatePhoneInAutoQueueMember(outlineName, originalDefaultOutline.getUsername()); } } } else if (!outlineName.equals(oldSipname)) { // ????, ?? updatePhoneInQueueMember(outlineName, oldSipname); // ? updatePhoneInAutoQueueMember(outlineName, oldSipname); // jrh 2014-02-21 ?????IVRActionAction ?? sipConfigService.checkIvrActionAndUpdate(false, outlineName, domain.getId()); } } 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(false); outlineManagement.getTable().setValue(null); } catch (Exception e) { // ?????? if (isDefaultOutline == true && originalDefaultOutline != null) { 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(), outlineName); } 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 commonQueue : allCommonQueues) { allCommonQueueNames.add(commonQueue.getName()); } // ?? boolean isGlobalRunning = phone2PhoneSettingService.confirmSettingIsRunning(globalSetting); if (isGlobalRunning) { // ???? if (globalSetting.getIsSpecifiedPhones()) { for (String phoneNum : globalSetting.getSpecifiedPhones()) { for (String queueName : allCommonQueueNames) { 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)) { // ?????,???? queueMemberRelationService.removeQueueMemberRelation(userQueue.getQueueName(), phoneNum + "@" + originalOutlineName); queueMemberRelationService.addQueueMemberRelation(userQueue.getQueueName(), phoneNum + "@" + outlineName, 5); } } } /** * ? (ShareData ?Map) * @param outlineName ?username */ private void updateShareData(String outlineName) { // ???? ShareData , ???????? if (!outlineName.equals(oldSipname)) { // 1? List<String> outlines = ShareData.domainToOutlines.get(domain.getId()); if (outlines == null) { outlines = new ArrayList<String>(); } outlines.remove(oldSipname); outlines.add(outlineName); ShareData.domainToOutlines.put(domain.getId(), outlines); // 2?? for (String exten : ShareData.extenToDynamicOutline.keySet()) { String dynOutline = ShareData.extenToDynamicOutline.get(exten); if (dynOutline.equals(oldSipname)) { ShareData.extenToDynamicOutline.put(exten, outlineName); } } // 3??? for (String exten : ShareData.extenToStaticOutline.keySet()) { String staticOutline = ShareData.extenToStaticOutline.get(exten); if (staticOutline.equals(oldSipname)) { ShareData.extenToStaticOutline.put(exten, outlineName); } } // 4? for (Long projectId : ShareData.projectToOutline.keySet()) { String staticOutline = ShareData.projectToOutline.get(projectId); if (staticOutline.equals(oldSipname)) { ShareData.projectToOutline.put(projectId, outlineName); } } // 5? Long projectId = ShareData.outlineToProject.get(oldSipname); if (projectId != null) { ShareData.outlineToProject.remove(oldSipname); ShareData.outlineToProject.put(outlineName, projectId); } } } 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) EditOutline.this); sipType.setNullSelectionAllowed(false); return sipType; } if ("type".equals(propertyId)) { ComboBox comboBox = new ComboBox(); comboBox.setImmediate(true); comboBox.addItem("friend"); comboBox.addItem("user"); comboBox.addItem("peer"); comboBox.setItemCaption("friend", "?IP"); 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.setItemCaption("no", "?"); comboBox.setItemCaption("yes", ""); 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.setItemCaption("no", "?"); comboBox.setItemCaption("yes", ""); comboBox.setNullSelectionAllowed(false); return comboBox; } else if ("belong".equals(propertyId)) { ComboBox comboBox = new ComboBox(); comboBox.setImmediate(true); comboBox.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS); comboBox.setWidth("200px"); 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.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, ""); treeMap.put(false, "?"); 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"); comboBox.setItemCaption("no", "?"); comboBox.setItemCaption("yes", ""); // 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}", "name ??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; } } }