import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.TreeMap; import com.hof.data.RefCodeUtilBean; import com.hof.data.SessionBean; import com.hof.mi.interfaces.CustomFormatter; import com.hof.mi.interfaces.UserInputParameters; import com.hof.util.Const; import com.hof.util.OrgCache; import com.hof.util.UtilString; import com.hof.util.i4RequestRegistry; public class OrgRefCodeFormatter extends CustomFormatter { private Integer ipOrg = null; private UserInputParameters.Parameter heightParameter = new UserInputParameters.Parameter(); private void getIpOrg() { if (this.ipOrg != null) { return; } try { SessionBean localSessionBean = i4RequestRegistry.getInstance().getCurrentSessionBean(); if (localSessionBean == null) { this.ipOrg = Integer.valueOf(1); } else { this.ipOrg = localSessionBean.getPersonSearchIpOrg(); } } catch (Exception localException) {} } public String getName() { return UtilString.getResourceString("mi.text.orgrefcode"); } public boolean acceptsNativeType(int type) { return (type == 2) || (type == 1); } public boolean returnsHtml() { return true; } public void setIpOrg(Integer paramInteger) { this.ipOrg = paramInteger; } public boolean compareConditionalAgainstFormattedValue() { return true; } public void setupParameters() { if (this.ipOrg == null) { getIpOrg(); } UserInputParameters.Parameter parameter = new UserInputParameters.Parameter(); parameter.setUniqueKey("REFTYPECODE"); parameter.setDataType(2); parameter.setDisplayName(UtilString.getResourceString("mi.text.reftype")); parameter.setDescription(UtilString.getResourceString("mi.text.column.format.reftype.desc")); parameter.setDisplayType(6); String str = "EN"; try { SessionBean localSessionBean = i4RequestRegistry.getInstance().getCurrentSessionBean(); if ((localSessionBean != null) && (localSessionBean.getPreferredLanguage() != null) && (localSessionBean.isMultiLanguage())) { str = localSessionBean.getPreferredLanguage().toUpperCase(); } } catch (Exception localException1) {} try { OrgCache localOrgCache = OrgCache.getInstance(); ArrayList localArrayList = localOrgCache.getOrgRefCodes(this.ipOrg, "REPORTREFTYPE", str); for (RefCodeUtilBean localRefCodeUtilBean : localArrayList) { parameter.addOption(localRefCodeUtilBean.getValue2(), localRefCodeUtilBean.getValue3()); } } catch (Exception localException2) {} addParameter(parameter); parameter = new UserInputParameters.Parameter(); parameter.setUniqueKey("DISPLAYTYPE"); parameter.setDataType(2); parameter.setDisplayName("Display As"); parameter.addOption("None","Text","Only the field value will be displayed."); parameter.addOption("ColorText","Color and Text","The field value will be displayed on top of a colored background."); parameter.addOption("Color","Color","Only the reference code color will be displayed as the cell background."); parameter.addOption("Image","Image","The reference code image will be displayed instead of the field value."); parameter.setDefaultValue("None"); parameter.setDisplayType(7); addParameter(parameter); this.heightParameter.setUniqueKey("IMGHEIGHT"); this.heightParameter.setDataType(2); this.heightParameter.setDisplayName("Height"); this.heightParameter.setDescription(""); this.heightParameter.setDisplayType(3); this.heightParameter.setDefaultValue("15"); addParameter(this.heightParameter); } public boolean isParameterRequired(String paramString) { String display=(String)getParameterValue("DISPLAYTYPE"); if (paramString.equals("IMGHEIGHT") && display.equals("Image")){ this.heightParameter.setDescription("Define the height of the image in pixels."); return true; } if (paramString.equals("IMGHEIGHT") && display.equals("Color")){ this.heightParameter.setDescription("Define the height of the background fill in pixels."); return true; } if (paramString.equals("IMGHEIGHT") && display.equals("ColorText")){ this.heightParameter.setDescription("Define the height of the background fill in pixels."); return true; } if (paramString.equals("IMGHEIGHT") && display.equals("None")) { return false; } return true; } public boolean hasDependentParameters(String paramString) { if (paramString.equals("DISPLAYTYPE") ){ return true; } return false; } public String render(Object paramObject, int paramInt) throws Exception { if (paramObject == null) { return null; } if (this.ipOrg == null) { getIpOrg(); } String str1 = "EN"; try { SessionBean localSessionBean = i4RequestRegistry.getInstance().getCurrentSessionBean(); if ((localSessionBean != null) && (localSessionBean.isMultiLanguage()) && (localSessionBean.getPreferredLanguage() != null)) { str1 = localSessionBean.getPreferredLanguage().toUpperCase(); } } catch (Exception localException) {} OrgCache localOrgCache = OrgCache.getInstance(); String refType = (String)getParameterValue("REFTYPECODE"); String refValue = paramObject.toString(); String refColor = ""; String refImage = ""; Object refCodeBean = null; TreeMap refcodes= localOrgCache.getOrgRefCodes(); String refstring = this.ipOrg + "|" + refType + "|" + refValue + "|" + str1; refCodeBean = refcodes.get(refstring); if (refCodeBean != null) { if (((RefCodeUtilBean) refCodeBean).getColour()!=null){ refColor = ((RefCodeUtilBean)refCodeBean).getColour(); } if (((RefCodeUtilBean) refCodeBean).getValue3()!=null){ refValue = ((RefCodeUtilBean)refCodeBean).getValue3(); } if (((RefCodeUtilBean) refCodeBean).getImageId()!=null){ refImage= ((RefCodeUtilBean)refCodeBean).getImageId().toString(); } } if (paramObject == null) return null; if (paramInt == RENDER_LINK) { return paramObject.toString(); } else if (paramInt == RENDER_HTML) { String display = (String)getParameterValue("DISPLAYTYPE"); String height= (String)getParameterValue("IMGHEIGHT"); if (display.equals("ColorText")) { return "
" + refValue + "
"; } else if (display.equals("Color")) { if (refColor.trim().length()==0){ return null; }else{ return "
" + "|" + "
"; } } else if (display.equals("Image")) { if (refImage.trim().length()==0 || refImage.equals("0")){ return null; }else{ return "
"; } } else { return refValue; } } else { return refValue; } } }