Example usage for java.util TreeMap entrySet

List of usage examples for java.util TreeMap entrySet

Introduction

In this page you can find the example usage for java.util TreeMap entrySet.

Prototype

EntrySet entrySet

To view the source code for java.util TreeMap entrySet.

Click Source Link

Document

Fields initialized to contain an instance of the entry set view the first time this view is requested.

Usage

From source file:net.opentsdb.tsd.HttpJsonSerializer.java

/**
 * Format the running configuration/*  w w w.  j ava  2  s.  c  o  m*/
 * @param config The running config to serialize
 * @return A ChannelBuffer object to pass on to the caller
 * @throws JSONException if serialization failed
 */
public ChannelBuffer formatConfigV1(final Config config) {
    TreeMap<String, String> map = new TreeMap<String, String>(config.getMap());
    for (Map.Entry<String, String> entry : map.entrySet()) {
        if (entry.getKey().toUpperCase().contains("PASS")) {
            map.put(entry.getKey(), "********");
        }
    }
    return serializeJSON(map);
}

From source file:de.mpg.escidoc.services.syndication.feed.Feed.java

/**
 * Populate parameters with the values taken from the certain <code>uri</code> 
 * and populate <code>paramHash</code> with the parameter/value paars.
 * @param uri/*from   ww w . j a  v  a  2s.c  om*/
 * @throws SyndicationException
 */
private void populateParamsFromUri(String uri) throws SyndicationException {
    Utils.checkName(uri, "Uri is empty");

    String um = getUriMatcher();

    Utils.checkName(um, "Uri matcher is empty");

    Matcher m = Pattern.compile(um, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(uri);
    if (m.find()) {
        for (int i = 0; i < m.groupCount(); i++)
            paramHash.put((String) paramList.get(i), m.group(i + 1));
    }

    //special handling of Organizational Unit Feed
    //TODO: should be resolved other way!
    if (getUriMatcher().equals("(.+)?/syndication/feed/(.+)?/publications/organization/(.+)?")) {
        TreeMap<String, String> outm = Utils.getOrganizationUnitTree();
        String oid = (String) paramHash.get("${organizationId}");
        for (Map.Entry<String, String> entry : outm.entrySet()) {
            if (entry.getValue().equals(oid)) {
                paramHash.put("${organizationName}", entry.getKey());
            }
        }
    }

    logger.info("parameters: " + paramHash);

}

From source file:org.pentaho.platform.uifoundation.component.xml.PropertiesPanelUIComponent.java

protected Document showInputPage(final ISolutionFile file) {
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement(PropertiesPanelUIComponent.INPUT_PAGE_NODE_NAME)
            .addText(file.getFullPath());

    // Add the info for the file we're working on
    root.addElement(PropertiesPanelUIComponent.FILE_PATH_NODE_NAME).addText(file.getFullPath());
    root.addElement(PropertiesPanelUIComponent.DISPLAY_PATH_NODE_NAME)
            .addText(file.getFullPath()/*from   www  .  j  av a2s . c o  m*/
                    .replaceFirst(repository.getRepositoryName(), PropertiesPanelUIComponent.EMPTY_STRING)
                    .replaceFirst("//", "/")); //$NON-NLS-1$//$NON-NLS-2$
    root.addElement(PropertiesPanelUIComponent.IS_DIR_NODE_NAME)
            .addText(file.isDirectory() ? PropertiesPanelUIComponent.TRUE : PropertiesPanelUIComponent.FALSE);
    Element recipients = root.addElement(PropertiesPanelUIComponent.RECIPIENTS_NODE_NAME);

    Iterator iter = null;
    if (includeRoles) {
        // Add all the possible roles
        List rList = getAllRolesList();
        if (rList != null) {
            iter = rList.iterator();
            while (iter.hasNext()) {
                recipients.addElement(PropertiesPanelUIComponent.ROLE_NODE_NAME)
                        .addText(iter.next().toString());
            }
        }
    }
    if (includeUsers) {
        // Add all the possible users
        List uList = getAllUsersList();
        if (uList != null) {
            iter = uList.iterator();
            while (iter.hasNext()) {
                recipients.addElement(PropertiesPanelUIComponent.USER_NODE_NAME)
                        .addText(iter.next().toString());
            }
        }
    }
    // Add the names of all the permissions
    Map permissionsMap = PentahoAclEntry.getValidPermissionsNameMap();
    // permissionsMap.remove(Messages.getString("PentahoAclEntry.USER_SUBSCRIBE")); //$NON-NLS-1$
    Iterator keyIter = permissionsMap.keySet().iterator();
    Element permNames = root.addElement(PropertiesPanelUIComponent.PERMISSION_NAMES_NODE_NAME);
    while (keyIter.hasNext()) {
        permNames.addElement(PropertiesPanelUIComponent.NAME_NODE_NAME).addText(keyIter.next().toString());
    }

    Element acListNode = root.addElement(PropertiesPanelUIComponent.ACCESS_CONTROL_LIST_NODE_NAME);
    TreeMap<IPermissionRecipient, IPermissionMask> sortedMap = new TreeMap<IPermissionRecipient, IPermissionMask>(
            new Comparator<IPermissionRecipient>() {
                public int compare(IPermissionRecipient arg0, IPermissionRecipient arg1) {
                    return arg0.getName().compareTo(arg1.getName());
                }
            });
    sortedMap.putAll(repository.getPermissions(file));
    for (Map.Entry<IPermissionRecipient, IPermissionMask> mapEntry : sortedMap.entrySet()) {
        IPermissionRecipient permissionRecipient = mapEntry.getKey();
        Element acNode = acListNode.addElement(PropertiesPanelUIComponent.ACCESS_CONTROL_NODE_NAME);
        Element recipientNode = acNode.addElement(PropertiesPanelUIComponent.RECIPIENT_NODE_NAME);
        recipientNode.setText(permissionRecipient.getName());
        recipientNode.addAttribute(PropertiesPanelUIComponent.TYPE_PARAM,
                (permissionRecipient instanceof SimpleRole) ? PropertiesPanelUIComponent.ROLE_TYPE
                        : PropertiesPanelUIComponent.USER_TYPE);
        // Add individual permissions for this group
        for (Iterator keyIterator = permissionsMap.keySet().iterator(); keyIterator.hasNext();) {
            Element aPermission = acNode.addElement(PropertiesPanelUIComponent.PERMISSION_NODE_NAME);
            String permName = keyIterator.next().toString();
            aPermission.addElement(PropertiesPanelUIComponent.NAME_NODE_NAME).setText(permName);
            int permMask = ((Integer) permissionsMap.get(permName)).intValue();
            //        boolean isPermitted = repository.hasAccess(permissionRecipient, file, permMask);
            //        broken on purpose
            boolean isPermitted = false;
            aPermission.addElement(PropertiesPanelUIComponent.PERMITTED_NODE_NAME)
                    .addText(isPermitted ? PropertiesPanelUIComponent.TRUE : PropertiesPanelUIComponent.FALSE);
        }
    }
    return document;
}

From source file:playground.pieter.singapore.demand.InputDataCollection.java

private void loadSubDGPLocationSamplers() {
    inputLog.info("Loading locationsamplers for each subdgp and work activity type");
    String facilityToSubDGPTable = diverseScriptProperties.getProperty("workFacilitiesToSubDGP");
    HashMap<String, Integer> facilityToSubDGP = new HashMap<>();
    HashMap<Integer, HashMap<String, Tuple<ArrayList<String>, ArrayList<Double>>>> subDGPActivityMapping = new HashMap<>();
    HashMap<Integer, HashMap<String, LocationSampler>> subDGPActivityLocationSamplers = new HashMap<>();
    try {/*from   ww  w  .  j a  v  a 2s  .  c  o  m*/
        //      start by mapping facilities to subdgps
        inputLog.info("\tMapping facilities to subdgps");
        ResultSet rs = dba.executeQuery(String.format("select * from %s", facilityToSubDGPTable));
        while (rs.next()) {
            facilityToSubDGP.put(rs.getString("id"), rs.getInt("subdgp"));
        }
        //         initialize the hashmaps
        inputLog.info("\tInitializing hashmaps");
        rs = dba.executeQuery(
                String.format("select distinct subdgp  from %s order by subdgp", facilityToSubDGPTable));
        while (rs.next()) {
            subDGPActivityMapping.put(rs.getInt("subdgp"),
                    new HashMap<String, Tuple<ArrayList<String>, ArrayList<Double>>>());
            subDGPActivityLocationSamplers.put(rs.getInt("subdgp"), new HashMap<String, LocationSampler>());
        }
        //         further initialization of the hashmaps
        for (String activityType : this.mainActivityTypes) {
            if (!activityType.startsWith("w_"))
                continue;
            rs = dba.executeQuery(
                    String.format("select distinct subdgp  from %s order by subdgp", facilityToSubDGPTable));
            while (rs.next()) {
                subDGPActivityMapping.get(rs.getInt("subdgp")).put(activityType,
                        new Tuple<>(new ArrayList<String>(), new ArrayList<Double>()));

            }
        }
    } catch (SQLException | NoConnectionException e) {
        e.printStackTrace();
    }
    //      then, go through the facilities for each work activity, find the subdgp theyre in
    //      put a reference to them in that subdgp's activity type map
    inputLog.info("\tFilling capacities");
    for (String activityType : this.mainActivityTypes) {
        //         only look at work activities
        if (!activityType.startsWith("w_"))
            continue;
        TreeMap<Id<ActivityFacility>, ? extends ActivityFacility> facilities = this.scenario
                .getActivityFacilities().getFacilitiesForActivityType(activityType);
        for (Entry<Id<ActivityFacility>, ? extends ActivityFacility> e : facilities.entrySet()) {
            String currid = e.getKey().toString();
            double currcap = e.getValue().getActivityOptions().get(activityType).getCapacity();
            //            TODO: check spatial join of facilities to subdgps
            //            there are a few facilities that  havent spatially joined properly, skip over them
            try {
                int subDGP = facilityToSubDGP.get(currid);
                subDGPActivityMapping.get(subDGP).get(activityType).getFirst().add(currid);
                subDGPActivityMapping.get(subDGP).get(activityType).getSecond().add(currcap);

            } catch (NullPointerException ne) {
            }
        }
    }
    //      now, convert all the arraylists to arrays, and create location samplers
    inputLog.info("\tConverting to arrays");
    for (int subdgp : subDGPActivityMapping.keySet()) {
        for (String acttype : subDGPActivityMapping.get(subdgp).keySet()) {
            ArrayList ids = subDGPActivityMapping.get(subdgp).get(acttype).getFirst();
            ArrayList caps = subDGPActivityMapping.get(subdgp).get(acttype).getSecond();
            String[] idsA = (String[]) ids.toArray(new String[ids.size()]);
            double[] capsA = ArrayUtils.toPrimitive((Double[]) caps.toArray(new Double[caps.size()]));
            subDGPActivityLocationSamplers.get(subdgp).put(acttype, new LocationSampler(acttype, idsA, capsA));
        }
    }
    this.subDGPActivityLocationSamplers = subDGPActivityLocationSamplers;
    this.facilityToSubDGP = facilityToSubDGP;
    inputLog.info("DONE: Loading locationsamplers for each subdgp and work activity type");
}

From source file:interactivespaces.activity.impl.BaseActivity.java

/**
 * Log the activity configuration information to an activity config log file.
 *
 * @param logFile//w w w .ja  va2 s .  com
 *          file to write the log into
 */
private void logConfiguration(String logFile) {
    try {
        StringBuilder logBuilder = new StringBuilder();
        getLog().info("Logging activity configuration to " + logFile);
        Configuration configuration = getConfiguration();
        Map<String, String> configMap = configuration.getCollapsedMap();
        TreeMap<String, String> sortedMap = new TreeMap<String, String>(configMap);
        for (Map.Entry<String, String> entry : sortedMap.entrySet()) {
            String value;
            try {
                value = configuration.evaluate(entry.getValue());
            } catch (Throwable e) {
                value = e.toString();
            }
            logBuilder.append(String.format("%s=%s\n", entry.getKey(), value));
        }
        File configLog = new File(getActivityFilesystem().getLogDirectory(), logFile);
        fileSupport.writeFile(configLog, logBuilder.toString());
    } catch (Throwable e) {
        logException("While logging activity configuration", e);
    }
}

From source file:edu.fullerton.ldvw.ImageHistory.java

/**
 * Add a table of buttons/links and info to control display and deletion
 *
 * @param imgCnt total number of records in selection
 *//*from  w  w  w .  ja v a  2 s. c  om*/
private PageItemList getNavBar(int imgCnt, boolean isBottom, String frmName)
        throws WebUtilException, LdvTableException, SQLException {
    PageItemList ret = new PageItemList();
    PageTable navBar = new PageTable();
    PageTableRow cmds = new PageTableRow();

    // add next/prev buttons if applicable
    PageFormButton prevBtn = new PageFormButton("submitAct", "<", "Prev");
    prevBtn.setEnabled(strt > 0);
    cmds.add(prevBtn);

    String botSuffix = isBottom ? "2" : "";

    int curPage = strt / cnt + 1;
    int nPage = (imgCnt + cnt - 1) / cnt;
    PageItemList pageSel = new PageItemList();
    pageSel.add("Page: ");
    PageFormText pageNum = new PageFormText("pageNum" + botSuffix, String.format("%1$,d", curPage));
    pageNum.setSize(3);
    pageNum.setMaxLen(6);
    pageNum.addEvent("onchange", "historySubmit('Go" + botSuffix + "', this);");
    pageSel.add(pageNum);
    pageSel.add(String.format(" of %d ", nPage));
    cmds.add(pageSel);

    PageFormButton nextBtn = new PageFormButton("submitAct", ">", "Next");
    nextBtn.setEnabled(curPage < nPage);
    cmds.add(nextBtn);

    int stop = Math.min(strt + cnt, imgCnt);
    String showing = String.format("Showing %1$d-%2$d for:", strt + 1, stop);
    cmds.add(showing);

    // add selection by user
    String cn = vuser.getCn();

    TreeMap<String, Integer> ucounts = imgTbl.getCountByUser();
    String[] usrs = new String[ucounts.size() + 1];
    String sel = "All";
    usrs[0] = "All";
    int i = 1;
    for (Map.Entry<String, Integer> entry : ucounts.entrySet()) {
        String u = entry.getKey();
        Integer cnts = entry.getValue();
        String opt = String.format("%1$s (%2$d)", u, cnts);
        if (userWanted.equalsIgnoreCase(u)) {
            sel = opt;
        }
        usrs[i] = opt;
        i++;
    }
    if (!isBottom) {
        // allow them to select another user (or all)
        PageFormSelect usrSel = new PageFormSelect("usrSel", usrs);
        usrSel.setSelected(sel);
        usrSel.addEvent("onchange", "this.form.submit()");
        PageItemList owner = new PageItemList();
        owner.add(new PageItemString("Owner:&nbsp;", false));
        owner.add(usrSel);
        cmds.add(owner);

        // Group selector
        TreeSet<String> groups = imgGrpTbl.getGroups(userWanted);
        if (!groups.isEmpty()) {
            PageItemList grpPIL = new PageItemList();
            grpPIL.add(new PageItemString("Group:&nbsp;", false));
            groups.add("All");
            PageFormSelect grpSel = new PageFormSelect("group");
            grpSel.add(groups);
            String curGroup = request.getParameter("group");
            if (curGroup != null && !curGroup.isEmpty() && groups.contains(curGroup)) {
                grpSel.setSelected(curGroup);
            } else {
                grpSel.setSelected("All");
            }
            grpSel.addEvent("onchange", "document." + frmName + ".submit()");
            grpPIL.add(grpSel);
            cmds.add(grpPIL);
        }
    }
    cmds.setClassAll("noborder");
    navBar.addRow(cmds);
    ret.add(navBar);

    if (!isBottom) {
        // New table because this one has fewer columns and we want to hide it by default
        navBar = new PageTable();
        navBar.setClassName("hidable");
        navBar.addStyle("display", "none");

        // allow them to change image size
        PageTableRow cmd2 = new PageTableRow();
        String[] sizes = { "original", "small", "med" };
        PageFormSelect sizeSel = new PageFormSelect("size", sizes);
        String curSize = request.getParameter("size");
        if (curSize != null && !curSize.isEmpty() && ArrayUtils.contains(sizes, curSize)) {
            sizeSel.setSelected(curSize);
        }
        sizeSel.addEvent("onchange", "document." + frmName + ".submit()");
        PageItemString lbl;
        lbl = new PageItemString("Size:&nbsp;", false);
        lbl.setAlign(PageItem.Alignment.RIGHT);
        cmd2.add(lbl);
        PageTableColumn col;
        col = new PageTableColumn(sizeSel);
        cmd2.add(col);
        cmd2.add();
        cmd2.add();
        cmd2.setClassAll("noborder");
        navBar.addRow(cmd2);

        cmd2 = new PageTableRow();
        lbl = new PageItemString("Selections:&nbsp;", false);
        lbl.setAlign(PageItem.Alignment.RIGHT);
        cmd2.add(lbl);

        PageFormButton selAll = new PageFormButton("selAll", "Select all", "selall");
        selAll.setType("button");
        selAll.addEvent("onclick", "setChkBoxByClass('selBox',true)");
        cmd2.add(selAll);

        PageFormButton clrAll = new PageFormButton("selAll", "Clear all", "clrall");
        clrAll.setType("button");
        clrAll.addEvent("onclick", "setChkBoxByClass('selBox', false)");
        cmd2.add(clrAll);
        cmd2.add();
        cmd2.setClassAll("noborder");
        navBar.addRow(cmd2);

        if (userWanted.equalsIgnoreCase(vuser.getCn()) || vuser.isAdmin()) {
            cmd2 = new PageTableRow();
            lbl = new PageItemString("Delete images:&nbsp;", false);
            lbl.setAlign(PageItem.Alignment.RIGHT);
            cmd2.add(lbl);

            col = new PageTableColumn(new PageFormSubmit("submitAct", "Delete Selected"));
            cmd2.add(col);
            cmd2.add();
            cmd2.add();
            cmd2.setClassAll("noborder");
            navBar.addRow(cmd2);
        }

        PageTableRow grpRow = new PageTableRow();
        lbl = new PageItemString("My groups:&nbsp;", false);
        lbl.setAlign(PageItem.Alignment.RIGHT);
        grpRow.add(lbl);

        TreeSet<String> myGroup = imgGrpTbl.getGroups(curUser);
        if (!myGroup.contains("Favorites")) {
            myGroup.add("Favorites");
        }
        myGroup.remove("Last result");
        PageFormSelect grpSel = new PageFormSelect("op_group");
        grpSel.add(myGroup);
        String curGroup = request.getParameter("groupSel");
        if (curGroup != null && !curGroup.isEmpty() && myGroup.contains(curGroup)) {
            grpSel.setSelected(curGroup);
        } else {
            grpSel.setSelected("Favorites");
        }
        grpRow.add(grpSel);

        grpRow.add(new PageFormSubmit("submitAct", "Add to grp"));
        grpRow.add(new PageFormSubmit("submitAct", "Del from grp"));
        grpRow.setClassAll("noborder");
        navBar.addRow(grpRow);
        grpRow = new PageTableRow();
        lbl = new PageItemString("New Group:&nbsp;", false);
        lbl.setAlign(PageItem.Alignment.RIGHT);
        grpRow.add(lbl);
        PageFormText grpNameTxt = new PageFormText("newGrpName", "<new group name>");
        grpNameTxt.addEvent("onfocus", "if(this.value == '<new group name>'){ this.value = ''; }");
        grpNameTxt.addEvent("onblur", "if(this.value == ''){ this.value = '<new group name>'; }");
        grpRow.add(grpNameTxt);
        PageFormSubmit newGrpBtn = new PageFormSubmit("submitAct", "New grp");
        grpRow.add(newGrpBtn);
        grpRow.add();
        grpRow.setClassAll("noborder");
        navBar.addRow(grpRow);
        ret.add(navBar);

        PageItemString optBtn = new PageItemString("+More options");
        optBtn.addEvent("onclick", "showByClass('hidable',this)");
        optBtn.setClassName("showCmd");
        ret.addBlankLines(1);
        ret.add(optBtn);
    }
    vpage.includeJS("showByClass.js");
    return ret;
}

From source file:org.rti.zcore.dar.utils.WidgetUtils.java

/**
 * @param conn/*from  w  w w. j  a  v  a 2 s. c om*/
 * @param pageItem
 * @param widgetType
* @param currentFieldNameIdentifier - If this is one of the special patient bridge forms, this value helps the system locate the correct field to render the widget.
* @param bridgeId - id of the record from the patient bridge table.
 * @return String used to render the widget
 */
public static String getOne(Connection conn, PageItem pageItem, String value, Long formId, Long encounterId,
        String widgetType, String currentFieldNameIdentifier, Long bridgeId) {

    String item = null;
    FormField formField = pageItem.getForm_field();
    Long formFieldId = formField.getId();
    Long pageItemId = pageItem.getId();
    StringBuffer sbuf = new StringBuffer();
    String inputType = pageItem.getInputType();
    value = value.trim();
    Set multiEnumList = null;

    // multiselect enums require special handling, since their enums come from their parent.
    if (inputType.equals("multiselect_item")) {
        Integer enumValue = null;
        String colName = formField.getStarSchemaName();
        if (!value.equals("")) {
            // Fetch the actual enum id
            try {
                enumValue = (Integer) EncountersDAO.getValue(conn, encounterId, formId, colName);
            } catch (ServletException e) {
                log.error(e);
            } catch (SQLException e) {
                log.error(e);
            }
            FieldEnumeration enumeration = (FieldEnumeration) DynaSiteObjects.getFieldEnumerations()
                    .get(Long.valueOf(enumValue));
            Long enumFormFieldId = enumeration.getFieldId();
            TreeMap enumMap = (TreeMap) DynaSiteObjects.getFieldEnumerationsByField().get(enumFormFieldId);
            if (enumMap.size() != 0) {
                Set fieldEnumSet = enumMap.entrySet();
                Set enumSet = new TreeSet(new DisplayOrderComparator());
                for (Iterator iterator = fieldEnumSet.iterator(); iterator.hasNext();) {
                    Map.Entry entry = (Map.Entry) iterator.next();
                    FieldEnumeration fieldEnumeration = (FieldEnumeration) entry.getValue();
                    enumSet.add(fieldEnumeration);
                }
                formField.setEnumerations(enumSet);
            }
        } else {
            Long masterId = Long.valueOf(pageItem.getVisibleDependencies1());
            if (masterId != null && masterId.intValue() > 0) {
                TreeMap enumMap = (TreeMap) DynaSiteObjects.getFieldEnumerationsByField().get(masterId);
                try {
                    if (enumMap.size() != 0) {
                        Set fieldEnumSet = enumMap.entrySet();
                        Set enumSet = new TreeSet(new DisplayOrderComparator());
                        for (Iterator iterator = fieldEnumSet.iterator(); iterator.hasNext();) {
                            Map.Entry entry = (Map.Entry) iterator.next();
                            FieldEnumeration fieldEnumeration = (FieldEnumeration) entry.getValue();
                            enumSet.add(fieldEnumeration);
                        }
                        formField.setEnumerations(enumSet);
                    }
                } catch (NullPointerException e) {
                    log.error("Error getting multiselect_item enum by pageItemId: masterId: " + masterId
                            + " pageItemId -  " + pageItemId + " field id: " + formFieldId);
                }
            } else {
                log.error("Error getting multiselect_item enum by pageItemId: masterId: " + masterId
                        + " pageItemId -  " + pageItemId + " field id: " + formFieldId);
            }
        }

        // it's a bit of a process to get the correct formfield - please bare w/ me...
        //HashMap map = (HashMap) DynaSiteObjects.getFieldToPageItem().get(formId);   // get map of pageItems to formfield
        //Long enumPageItemId =  (Long) map.get(enumFormFieldId);
        //PageItem enumPageItem = (PageItem) DynaSiteObjects.getPageItems().get(enumPageItemId);
        // we may just need the fieldenum from dynasite....
        //FormField enumFormfield =  (FormField) map.get(enumFormFieldId);
    }

    String visibleEnumIdTrigger1 = null;
    if (pageItem.getVisibleEnumIdTrigger1() != null) {
        if (pageItem.getVisibleEnumIdTrigger1().equals("")) {
            visibleEnumIdTrigger1 = "0";
        } else {
            visibleEnumIdTrigger1 = pageItem.getVisibleEnumIdTrigger1();
        }
    } else {
        visibleEnumIdTrigger1 = "0";
    }

    String visibleEnumIdTrigger2 = null;
    if (pageItem.getVisibleEnumIdTrigger2() != null) {
        if (pageItem.getVisibleEnumIdTrigger2().equals("")) {
            visibleEnumIdTrigger2 = "0";
        } else {
            visibleEnumIdTrigger2 = pageItem.getVisibleEnumIdTrigger2();
        }
    } else {
        visibleEnumIdTrigger2 = "0";
    }

    // some of the inputTypes are not stored properly - we'll get them from formField
    if (formField.getType() != null) {
        if (formField.getType().equals("Yes/No")) {
            inputType = "Yes/No";
        } else if (formField.getType().equals("sex")) {
            inputType = "sex";
        }
    }

    // some widgets are shared
    if (inputType.equals("radio")) {
        inputType = "select";
    }

    String dep = null;
    String update = null;

    String formProperty = null;
    String widgetName = null;
    if (widgetType.equals("Chart")) {
        formProperty = "field" + String.valueOf(encounterId) + "." + String.valueOf(formFieldId);
        widgetName = "inputWidget" + String.valueOf(encounterId) + "." + String.valueOf(formFieldId);
    } else if (widgetType.equals("Metadata")) {
        formProperty = "field" + inputType;
        widgetName = "inputWidget" + inputType;
    } else {
        formProperty = "field" + String.valueOf(formFieldId);
        widgetName = "inputWidget" + String.valueOf(formFieldId);
    }

    String updateRecord = null;
    Form encounterForm = (Form) DynaSiteObjects.getForms().get(formId);

    if (encounterForm.getFormTypeId() == 6) { // patient bridge table form
        if (bridgeId == 0) {
            updateRecord = "createRecord('" + inputType + "', " + formFieldId + " ," + pageItemId + " ,"
                    + formId + ", " + encounterId + " , '" + widgetType + "', '" + currentFieldNameIdentifier
                    + "');";
        } else {
            updateRecord = "updateRecord('" + inputType + "', " + formFieldId + " ," + pageItemId + " ,"
                    + formId + ", " + encounterId + " , '" + widgetType + "', " + bridgeId + " , '"
                    + currentFieldNameIdentifier + "');";
        }
    } else {
        updateRecord = "updateRecord('" + inputType + "', " + formFieldId + " ," + pageItemId + " ," + formId
                + ", " + encounterId + " , '" + widgetType + "');";
    }

    if (widgetType.equals("Chart")) {
        /* if (formFieldId.intValue() == 1563) {
        updateRecord = "updateRecordChart('" + inputType + "', "
                + formFieldId + " ," + pageItemId + " ," + formId + ", " + encounterId + " , '" + widgetType + "','');";
         } else {*/
        updateRecord = "updateRecordChart('" + inputType + "', " + formFieldId + " ," + pageItemId + " ,"
                + formId + ", " + encounterId + " , '" + widgetType + "','');";
        //  }
    } else if (widgetType.equals("patientid")) {
        updateRecord = "updateRecord('" + inputType + "', " + formFieldId + " ," + pageItemId + " ," + formId
                + ", " + encounterId + " , 'patient');";
    } else if (widgetType.equals("Metadata")) {
        updateRecord = "updateRecordMetadata('" + inputType + "', " + encounterId + ");";
    }

    String updateRecordIdNameY = "updateRecordIdName('" + inputType + "', " + formFieldId + " ," + pageItemId
            + " ," + formId + ", " + encounterId + ", 'Y', '" + widgetType + "');";
    String updateRecordIdNameN = "updateRecordIdName('" + inputType + "', " + formFieldId + " ," + pageItemId
            + " ," + formId + ", " + encounterId + ", 'N', '" + widgetType + "');";
    // Choices for update are "onclick, onmouseout, onchange"

    String dep1 = "toggleField('dropdown', " + visibleEnumIdTrigger1 + ", '"
            + pageItem.getVisibleDependencies1() + "','" + formField.getId() + "');";
    String dep2 = "toggleField2DepsChoice('dropdown', " + visibleEnumIdTrigger1 + ", '"
            + pageItem.getVisibleDependencies1() + "'," + visibleEnumIdTrigger2 + ", '"
            + pageItem.getVisibleDependencies2() + "', '" + formField.getId() + "');";
    String depSm = "toggleFieldSafeMotherhood('dropdown', " + visibleEnumIdTrigger1 + ", '"
            + pageItem.getVisibleDependencies1() + "'," + visibleEnumIdTrigger2 + ", '"
            + pageItem.getVisibleDependencies2() + "', '" + formField.getId() + "');";

    if ((inputType.equals("emptyDate")) || (inputType.equals("birthdate")) || (inputType.equals("dateToday"))
            || (inputType.equals("dateOneMonthFuture"))) {
        String month = DateUtils.getMonth();
        String day = DateUtils.getDay();
        String year = DateUtils.getYear();
        String lastTwoYears = String.valueOf(new Integer(year).intValue() - 2);
        String eightyYears = String.valueOf(new Integer(year).intValue() - 80);
        String twoYears = String.valueOf(new Integer(year).intValue() + 2);
        String startYear;
        String endYear;
        if (inputType.equals("birthdate")) {
            startYear = eightyYears;
            endYear = year;
        } else {
            startYear = lastTwoYears;
            endYear = twoYears;
        }
        sbuf.append("<span onclick=\"showCalendar('" + year + "','" + month + "','" + day
                + "','dd/MM/yyyy','form" + formId + "','" + formProperty + "',event," + startYear + ","
                + endYear + ");\">"
                + "<img alt=\"Select Date\" border=\"0\" src=\"/dar/images/calendar.gif\" align=\"middle\">"
                + "</span>\n");
        sbuf.append("<span id=\"span" + formProperty + "\" onclick=\"showCalendar('" + year + "','" + month
                + "','" + day + "','dd/MM/yyyy','form" + formId + "','" + formProperty + "',event," + startYear
                + "," + endYear + ");\"></span>\n");
        sbuf.append("<span style=\"display:none;\">\n" + "   <input type=\"text\" id=\"" + widgetName
                + "\" name=\"field" + formFieldId + "\"/>\n" + "</span>\n");
        sbuf.append("<input type=\"button\" name=\"_add\" value=\"Change\""
                + getEventHandler("onclick", updateRecord, encounterId) + ">\n");
        item = sbuf.toString();

    } else if (inputType.equals("select") || inputType.equals("select-dwr")
            || inputType.equals("select-multitoggle")) {
        Set enumList = formField.getEnumerations();
        renderSelect(visibleEnumIdTrigger1, sbuf, widgetName, formFieldId, updateRecord, dep1, encounterId,
                pageItem, visibleEnumIdTrigger2, dep2, value, enumList);
        item = sbuf.toString();
    } else if (inputType.equals("dropdown")) {
        // Process the dynamic dropdown lists
        List<DropdownItem> dropdownItems = null;
        if (pageItem.getInputType().equals("dropdown")) {
            try {
                dropdownItems = WidgetUtils.getList(conn, pageItem.getDropdownTable(),
                        pageItem.getDropdownColumn(), pageItem.getDropdownConstraint(),
                        pageItem.getDropdownOrderByClause(), DropdownItem.class);
            } catch (SQLException e) {
                log.error(e);
            } catch (ServletException e) {
                log.error(e);
            }
        }
        renderSelect(visibleEnumIdTrigger1, sbuf, widgetName, formFieldId, updateRecord, dep1, encounterId,
                pageItem, visibleEnumIdTrigger2, dep2, value, dropdownItems, bridgeId,
                currentFieldNameIdentifier);
        item = sbuf.toString();
    } else if (inputType.equals("multiselect_item")) {
        Set enumList = formField.getEnumerations();
        renderSelect(visibleEnumIdTrigger1, sbuf, widgetName, formFieldId, updateRecord, dep1, encounterId,
                pageItem, visibleEnumIdTrigger2, dep2, value, enumList);
        item = sbuf.toString();
    } else if (inputType.equals("multiselect_enum")) {
        item = "Please make a selection from one of the following choices below.";
    } else if (inputType.equals("patientid_districts")) {
        List districts = DynaSiteObjects.getDistricts();
        sbuf.append("<select id=\"" + widgetName + "\" name=\"field" + formFieldId + "\""
                + getEventHandler("onchange", updateRecord, encounterId) + ">\n");
        sbuf.append("   <option value=\"\">No Information</option>\n");
        for (int i = 0; i < districts.size(); i++) {
            District district = (District) districts.get(i);
            if (value.equals(district.getDistrictId())) {
                sbuf.append("   <option value=\"" + district.getDistrictId() + "\" selected>"
                        + district.getDistrictName() + " (" + district.getDistrictId() + ")" + "</option>\n");
            } else {
                sbuf.append("   <option value=\"" + district.getDistrictId() + "\">"
                        + district.getDistrictName() + " (" + district.getDistrictId() + ")" + "</option>\n");
            }
        }
        sbuf.append("</select>\n");
        item = sbuf.toString();
    } else if (inputType.equals("patientid_sites") || inputType.equals("sites")
            || inputType.equals("sites_not_selected")) {
        List sites = null;
        sites = DynaSiteObjects.getClinics();
        sbuf.append("<select id=\"" + widgetName + "\" name=\"field" + formFieldId + "\""
                + getEventHandler("onchange", updateRecord, encounterId) + ">\n");
        sbuf.append("   <option value=\"\">No Information</option>\n");
        for (int i = 0; i < sites.size(); i++) {
            Site site = (Site) sites.get(i);
            if (site.getInactive() == null) {
                String siteId = null;
                String abbrev = null;
                if (inputType.equals("patientid_sites")) {
                    //siteId = site.getSiteAlphaId().substring(0, 2);
                    siteId = site.getSiteAlphaId();
                    abbrev = " (" + siteId + ")";
                } else {
                    siteId = site.getId().toString();
                    abbrev = "";
                }
                if (value.equals(site.getSiteAlphaId())) {
                    sbuf.append("   <option value=\"" + siteId + "\" selected>" + site.getName() + abbrev
                            + "</option>\n");
                } else {
                    sbuf.append(
                            "   <option value=\"" + siteId + "\">" + site.getName() + abbrev + "</option>\n");
                }
            }
        }
        sbuf.append("</select>\n");
        item = sbuf.toString();
    } else if (inputType.equals("patientid")) {
        //ExecutionContext exec = ExecutionContext.get();
        WebContext exec = WebContextFactory.get();
        SessionUtil zeprs_session = null;
        String patientSiteId = null;
        try {
            zeprs_session = (SessionUtil) exec.getSession().getAttribute("zeprs_session");
            patientSiteId = zeprs_session.getClientSettings().getSiteId().toString();
        } catch (Exception e) {
            // unit testing - it's ok...
        }
        Site site = (Site) DynaSiteObjects.getClinicMap().get(new Long(patientSiteId));
        String siteAlphaId = site.getSiteAlphaId().substring(0, 2);
        String clinicId = site.getSiteAlphaId().substring(2, 3);
        ArrayList uthSubsites = new ArrayList();
        uthSubsites.add("A");
        uthSubsites.add("B");
        uthSubsites.add("C");
        uthSubsites.add("D");

        sbuf.append("<input type=\"hidden\" id=\"district\" value=\"5040\">\n");
        //sbuf.append("<input type=\"text\" id=\"site\" value=\"" + siteAlphaId + "\">\n");
        sbuf.append("<input type=\"hidden\" id=\"site\" value=\"\">\n");
        sbuf.append(
                "<br/>Select Subsite: <select id=\"subsite\" onchange=\"calcPatientId();\"><option> -- </option>\n");
        if (clinicId.equals("A") || clinicId.equals("B") || clinicId.equals("C") || clinicId.equals("D")) {
            for (int i = 0; i < uthSubsites.size(); i++) {
                String subsite = (String) uthSubsites.get(i);
                if (clinicId.equals(subsite)) {
                    sbuf.append("<option value=\"" + subsite + "\" selected=\"selected\">* " + subsite
                            + " *</option>\n");
                } else {
                    sbuf.append("<option value=\"" + subsite + "\"> " + subsite + " </option>\n");
                }
            }
        } else {
            int subsite = 0;
            while (subsite <= 10) {
                int clinicIdInt = new Integer(clinicId);
                if (clinicIdInt == subsite) {
                    sbuf.append("<option value=\"" + subsite + "\" selected=\"selected\">* " + subsite
                            + " *</option>\n");
                } else {
                    sbuf.append("<option value=\"" + subsite + "\"> " + subsite + " </option>\n");
                }
                subsite++;
            }
        }
        sbuf.append("</select>\n");
        sbuf.append(
                "<input class=\"ibutton\" onclick=\"copySite();setPatientID('patient','Please select District and clinic fields.','patientid');\" value=\"Get New ID\" title=\"Get New ID\" type=\"button\">\n");
        sbuf.append("<span id=\"spanpatient\"></span>");
        sbuf.append(
                "<div id=\"patientIdRow\"><br/> -- or -- <br/><br/>If patient already has an ID please enter the last five digits:");
        sbuf.append("<span id=\"patientIdFields\">\n"
                + "                <input id=\"patientid\" name=\"patientid\" size=\"4\" maxlength=\"5\" onchange=\"copySite();calcPatientId()\" type=\"text\">\n"
                + "                <input id=\"checksum\" name=\"checksum\" onchange=\"calcPatientId()\" type=\"hidden\">\n"
                + "                <input id=\"checkPatientId\" class=\"ibutton\" onclick='copySite();checkPatientID(\"patient\",\"Please select/enter all of the Patient ID fields.\",\"patientid\");' value=\"Check ID\" title=\"Check ID\" type=\"button\">\n"
                + "            </span>\n</div>\n");
        sbuf.append("<span id=\"d1\" class=\"reply\"></span>\n");
        sbuf.append("<input id=\"patient\" type=\"hidden\" name=\"field" + formFieldId
                + "\" size=\"20\" maxlength=\"255\"" + "\" value=\"" + value + "\"/>\n");
        // sbuf.append("<input id=\"" + widgetName + "\" type=\"text\" name=\"field" + formFieldId + "\" size=\"20\" maxlength=\"255\"" + "\" value=\"" + value + "\"" + getEventHandler("onchange", updateRecord, encounterId) + "/>\n");
        sbuf.append("<input id=\"siteId\" type=\"hidden\" name=\"field" + formFieldId + "\"/>\n");

        /*if ((pageItem.getSize() != null) && (pageItem.getSize().intValue() > 0)) {
        sbuf.append("<input id=\"" + widgetName + "\" type=\"text\" name=\"field" + formFieldId + "\" size=\"" + pageItem.getSize() + "\" maxlength=\"" + pageItem.getMaxlength() + "\" value=\"" + value + "\"" + getEventHandler("onchange", updateRecord, encounterId) + "/>\n");
        } else {
        }*/
        item = sbuf.toString();
    } else if (inputType.equals("currentMedicine")) {
        List drugs = null;
        // drugs = DrugsDAO.getAll();
        drugs = DynaSiteObjects.getDrugs();
        sbuf.append("<select id=\"" + widgetName + "\" name=\"field" + formFieldId + "\""
                + getEventHandler("onchange", updateRecord, encounterId) + ">\n");
        sbuf.append("   <option value=\"\">No Information</option>\n");
        for (int i = 0; i < drugs.size(); i++) {
            Drugs drug = (Drugs) drugs.get(i);
            //if (value.equals(drug.getName())) {
            Pattern pattern = Pattern.compile(drug.getName());
            Matcher matcher = pattern.matcher(value);
            if (matcher.find() == true) {
                if (drug.getTeratogenic() != null) {
                    sbuf.append(
                            "   <option value=\"" + drug.getId() + "\" selected  class=\"teratogenicAlert\">"
                                    + drug.getName() + " *" + drug.getTeratogenic() + "*</option>\n");
                } else {
                    sbuf.append("   <option value=\"" + drug.getId() + "\" selected>" + drug.getName()
                            + "</option>\n");
                }
            } else {
                if (drug.getTeratogenic() != null) {
                    sbuf.append("   <option value=\"" + drug.getId() + "\" class=\"teratogenicAlert\">"
                            + drug.getName() + " *" + drug.getTeratogenic() + "*</option>\n");
                } else {
                    sbuf.append("   <option value=\"" + drug.getId() + "\">" + drug.getName() + "</option>\n");
                }
            }
        }
        sbuf.append("</select>\n");
        item = sbuf.toString();

    } else if (inputType.equals("firm")) {
        sbuf.append("<select id=\"" + widgetName + "\" name=\"field" + formFieldId + "\""
                + getEventHandler("onchange", updateRecord, encounterId) + ">\n");
        sbuf.append("   <option value=\"\">No Information</option>\n");
        ArrayList firms = new ArrayList();
        firms.add("A");
        firms.add("B");
        firms.add("C");
        firms.add("D");
        firms.add("E");
        for (int i = 0; i < firms.size(); i++) {
            String firm = (String) firms.get(i);
            sbuf.append("   <option value=\"" + firm + "\">" + firm + "</option>\n");
        }
        sbuf.append("</select>\n");
        item = sbuf.toString();

    } else if (inputType.equals("ega") || inputType.equals("ega_pregnancyDating")) {

        sbuf.append("<select id=\"" + widgetName + "\" name=\"field" + formFieldId + "\""
                + getEventHandler("onchange", updateRecord, encounterId) + ">\n");
        sbuf.append("   <option value=\"\">No Information</option>\n");
        for (int i = 0; i < 350; i++) {

            int days = i % 7;
            int weeks = i / 7;
            String thisEga = weeks + ", " + days + "/7";
            if (value.equals(thisEga)) {
                sbuf.append("   <option value=\"" + i + "\" selected>" + weeks + " weeks, " + days + "/ 7 days"
                        + "</option>\n");
            } else {
                sbuf.append("   <option value=\"" + i + "\">" + weeks + " weeks, " + days + "/ 7 days"
                        + "</option>\n");
            }
        }
        sbuf.append("</select>\n");
        item = sbuf.toString();
    } else if (inputType.equals("textarea")) {
        Integer cols = pageItem.getCols();
        Integer rows = pageItem.getRows();
        if (cols == 0) {
            cols = 32;
        }
        if (rows == 0) {
            rows = 2;
        }
        if (!value.trim().equals("")) {
            sbuf.append("<textarea id=\"" + widgetName + "\" name=\"" + widgetName + "\" cols=\"" + cols
                    + "\" rows=\"" + rows + "\"" + getEventHandler("onchange", updateRecord, encounterId) + ">"
                    + value + "</textarea>\n");
        } else {
            sbuf.append("<textarea id=\"" + widgetName + "\" name=\"" + widgetName + "\" cols=\"" + cols
                    + "\" rows=\"" + rows + "\"" + getEventHandler("onchange", updateRecord, encounterId)
                    + "/>\n");
        }
        item = sbuf.toString();

    } else if (inputType.equals("checkbox") || inputType.equals("checkbox_dwr")) {
        if (value.equals("Yes")) {
            sbuf.append("<input type=\"checkbox\" checked id=\"" + widgetName + "\" name=\"field" + formFieldId
                    + "\" " + getEventHandler("onchange", updateRecord, encounterId) + ">" + "\n");
        } else if (value.equals("1")) {
            sbuf.append("<input type=\"checkbox\" checked id=\"" + widgetName + "\" name=\"field" + formFieldId
                    + "\" " + getEventHandler("onchange", updateRecord, encounterId) + ">" + "\n");
        } else {
            sbuf.append("<input type=\"checkbox\" id=\"" + widgetName + "\" name=\"field" + formFieldId + "\" "
                    + getEventHandler("onchange", updateRecord, encounterId) + ">" + "\n");
        }
        item = sbuf.toString();

    } else if (inputType.equals("text") || inputType.equals("text-dwr")) {
        if ((pageItem.getSize() != null) && (pageItem.getSize().intValue() > 0)) {
            sbuf.append(
                    "<input id=\"" + widgetName + "\" type=\"text\" name=\"field" + formFieldId + "\" size=\""
                            + pageItem.getSize() + "\" maxlength=\"" + pageItem.getMaxlength() + "\" value=\""
                            + value + "\"" + getEventHandler("onchange", updateRecord, encounterId) + "/>\n");
        } else {
            sbuf.append("<input id=\"" + widgetName + "\" type=\"text\" name=\"field" + formFieldId
                    + "\" size=\"20\" maxlength=\"255\" value=\"" + value + "\""
                    + getEventHandler("onchange", updateRecord, encounterId) + "/>\n");
        }
        // sbuf.append("<input type=\"button\" name=\"_add\" value=\"Change\"" + onClick + ">\n");
        item = sbuf.toString();

    } else if (inputType.equals("month_no_label")) {
        if ((pageItem.getSize() != null) && (pageItem.getSize().intValue() > 0)) {
            sbuf.append("<input id=\"" + widgetName + "\" type=\"text\" name=\"field" + formFieldId
                    + "\" size=\"" + pageItem.getSize() + "\" maxlength=\"" + pageItem.getMaxlength() + "\""
                    + getEventHandler("onchange", updateRecord, encounterId) + "/>\n");
        } else {
            sbuf.append("<input id=\"" + widgetName + "\" type=\"text\" name=\"field" + formFieldId
                    + "\" size=\"20\" maxlength=\"255\""
                    + getEventHandler("onchange", updateRecord, encounterId) + "/>\n");
        }
        // sbuf.append("<input type=\"button\" name=\"_add\" value=\"Change\"" + onClick + ">\n");
        item = sbuf.toString();

    } else if (inputType.equals("Yes/No")) {
        if (value.equals("true")) {
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldY" + formFieldId
                    + "\" value=\"1\" checked " + getEventHandler("onclick", updateRecordIdNameY, encounterId)
                    + "/><label for=\"" + formFieldId + "\">Yes</label>\n");
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldN" + formFieldId
                    + "\" value=\"0\" " + getEventHandler("onclick", updateRecordIdNameN, encounterId)
                    + "/><label for=\"" + formFieldId + "\">No</label>\n");
        } else if (value.equals("Yes")) {
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldY" + formFieldId
                    + "\" value=\"1\" checked " + getEventHandler("onclick", updateRecordIdNameY, encounterId)
                    + "/><label for=\"" + formFieldId + "\">Yes</label>\n");
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldN" + formFieldId
                    + "\" value=\"0\" " + getEventHandler("onclick", updateRecordIdNameN, encounterId)
                    + "/><label for=\"" + formFieldId + "\">No</label>\n");
        } else if (value.equals("false")) {
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldY" + formFieldId
                    + "\" value=\"1\" " + getEventHandler("onclick", updateRecordIdNameY, encounterId)
                    + "/><label for=\"" + formFieldId + "\">Yes</label>\n");
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldN" + formFieldId
                    + "\" value=\"0\" checked " + getEventHandler("onclick", updateRecordIdNameN, encounterId)
                    + "/><label for=\"" + formFieldId + "\">No</label>\n");
        } else if (value.equals("No")) {
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldY" + formFieldId
                    + "\" value=\"1\" " + getEventHandler("onclick", updateRecordIdNameY, encounterId)
                    + "/><label for=\"" + formFieldId + "\">Yes</label>\n");
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldN" + formFieldId
                    + "\" value=\"0\" checked " + getEventHandler("onclick", updateRecordIdNameN, encounterId)
                    + "/><label for=\"" + formFieldId + "\">No</label>\n");
        } else {
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldY" + formFieldId
                    + "\" value=\"1\" " + getEventHandler("onclick", updateRecordIdNameY, encounterId)
                    + "/><label for=\"" + formFieldId + "\">Yes</label>\n");
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldN" + formFieldId
                    + "\" value=\"0\" " + getEventHandler("onclick", updateRecordIdNameN, encounterId)
                    + "/><label for=\"" + formFieldId + "\">No</label>\n");
        }
        item = sbuf.toString();
    } else if (inputType.equals("sex")) {
        if (value.equals("Female")) {
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldY" + formFieldId
                    + "\" value=\"1\" checked " + getEventHandler("onclick", updateRecordIdNameY, encounterId)
                    + "/><label for=\"" + formFieldId + "\">Female</label>\n");
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldN" + formFieldId
                    + "\" value=\"2\" " + getEventHandler("onclick", updateRecordIdNameN, encounterId)
                    + "/><label for=\"" + formFieldId + "\">Male</label>\n");
        } else if (value.equals("Male")) {
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldY" + formFieldId
                    + "\" value=\"1\" " + getEventHandler("onclick", updateRecordIdNameY, encounterId)
                    + "/><label for=\"" + formFieldId + "\">Female</label>\n");
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldN" + formFieldId
                    + "\" value=\"2\" checked " + getEventHandler("onclick", updateRecordIdNameN, encounterId)
                    + "/><label for=\"" + formFieldId + "\">Male</label>\n");
        } else {
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldY" + formFieldId
                    + "\" value=\"1\" " + getEventHandler("onclick", updateRecordIdNameY, encounterId)
                    + "/><label for=\"" + formFieldId + "\">Female</label>\n");
            sbuf.append("<input type=\"radio\" name=\"field" + formFieldId + "\" id=\"fieldN" + formFieldId
                    + "\" value=\"2\" " + getEventHandler("onclick", updateRecordIdNameN, encounterId)
                    + "/><label for=\"" + formFieldId + "\">Male</label>\n");
        }
        item = sbuf.toString();
    } else if (inputType.equals("apgar")) {
        sbuf.append("<p>Click a value from each row to calculate the Apgar score.</p>");
        sbuf.append("<table border=1 cellspacing=\"0\" cellpadding=2 id=\"" + formFieldId + "apgar\">\n"
                + "\t<tr bgcolor=\"#99ccff\" id=\"" + formFieldId + "min\">\n" + "\t\t<th>Signs</th>\n"
                + "\t\t<th>0</th>\n" + "\t\t<th>1</th>\n" + "\n" + "\t\t<th>2</th>\n" + "\t\t<th id=\""
                + formFieldId
                + "1min\" style=\"background-color: #0033cc; color: White;\" onMouseOver=\"this.style.cursor='pointer'\" onClick=\"whatMin(this.id);\"><br>score</th>\n"
                + "\t</tr>\n" + "\n" + "\t<tr id=\"" + formFieldId + "h\">\n"
                + "\t\t<th align=right>Heart Rate</th>\n" + "\n" + "\t\t<td align=center id=\"" + formFieldId
                + "h0\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">Absent</td>\n" + "\t\t<td align=center id=\"" + formFieldId
                + "h1\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">Below 100</td>\n" + "\t\t<td align=center id=\"" + formFieldId
                + "h2\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">Above 100</td>\n" + "\t\t<td class=\"score\" id=\"" + formFieldId
                + "1h\" onClick=\"whatMin(this.id," + formFieldId + ");\">&nbsp;</td>\n" + "\t</tr>\n" + "\n"
                + "\t<tr id=\"" + formFieldId + "r\">\n" + "\t\t<th align=right>Respiratory Effort</th>\n"
                + "\t\t<td align=center id=\"" + formFieldId
                + "r0\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">Absent</td>\n" + "\n" + "\t\t<td align=center id=\"" + formFieldId
                + "r1\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">Slow, irregular</td>\n" + "\t\t<td align=center id=\"" + formFieldId
                + "r2\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">Good, crying</td>\n" + "\t\t<td class=\"score\" id=\"" + formFieldId
                + "1r\" onClick=\"whatMin(this.id," + formFieldId + ");\">&nbsp;</td>\n" + "\t</tr>\n" + "\n"
                + "\t<tr id=\"" + formFieldId + "m\">\n" + "\t\t<th align=right>Muscle Tone</th>\n"
                + "\t\t<td align=center id=\"" + formFieldId
                + "m0\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">Nil (Limp)</td>\n" + "\t\t<td align=center id=\"" + formFieldId
                + "m1\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">Some flexion<br>of extremities</td>\n" + "\n"
                + "\t\t<td align=center id=\"" + formFieldId
                + "m2\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">Active motion</td>\n" + "\t\t<td class=\"score\" id=\"" + formFieldId
                + "1m\" onClick=\"whatMin(this.id," + formFieldId + ");\">&nbsp;</td>\n" + "\n" + "\t</tr>\n"
                + "\n" + "\t<tr id=\"" + formFieldId + "x\">\n"
                + "\t\t<th align=right>Reflex irritability</th>\n" + "\t\t<td align=center id=\"" + formFieldId
                + "x0\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">No response</td>\n" + "\n" + "\t\t<td align=center id=\"" + formFieldId
                + "x1\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">Grimace</td>\n" + "\t\t<td align=center id=\"" + formFieldId
                + "x2\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">Vigorous Cry</td>\n" + "\t\t<td class=\"score\" id=\"" + formFieldId
                + "1x\" onClick=\"whatMin(this.id," + formFieldId + ");\">&nbsp;</td>\n" + "\t</tr>\n" + "\n"
                + "\t<tr id=\"" + formFieldId + "c\">\n" + "\t\t<th align=right>Color</th>\n"
                + "\t\t<td align=center id=\"" + formFieldId
                + "c0\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">Blue, pale</td>\n" + "\t\t<td align=center id=\"" + formFieldId
                + "c1\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">Body pink,<br>extremities blue</td>\n" + "\n"
                + "\t\t<td align=center id=\"" + formFieldId
                + "c2\" onMouseOver=\"bgclr(this,1); this.style.cursor='pointer'\" onMouseOut=\"bgclr(this,0);\" onClick=\"bgclr(this,2,"
                + formFieldId + ");\">Completely pink</td>\n" + "\t\t<td class=\"score\" id=\"" + formFieldId
                + "1c\" onClick=\"whatMin(this.id," + formFieldId + ");\">&nbsp;</td>\n" + "\t</tr>\n" + "\n"
                + "\t<tr id=\"" + formFieldId + "total\">\n"
                + "\t\t<th height=\"44px\" colspan=4 align=right>\n" + "\t\t\tTOTAL SCORE :&nbsp;\n"
                + "\t\t</th>\n" + "\t\t<td class=\"score\" id=\"" + formFieldId
                + "1score\" onClick=\"whatMin(this.id," + formFieldId + ");\">&nbsp;</td>\n" + "\t</tr>\n"
                + "</table>");
        sbuf.append("<input type=\"button\" name=\"_add\" value=\"Change\""
                + getEventHandler("onclick", updateRecord, encounterId) + ">\n");
        sbuf.append("<input id=\"inputWidget" + formFieldId + "\" type=\"text\" name=\"field" + formFieldId
                + "\" size=\"20\" maxlength=\"255\"/>\n");
        // sbuf.append("<input type=\"button\" name=\"_add\" value=\"Change\"" + onClick + ">\n");
        item = sbuf.toString();
    } else if (inputType.equals("fundal_height")) {
        sbuf.append("<select id=\"" + widgetName + "\" name=\"field" + formFieldId + "\""
                + getEventHandler("onchange", updateRecord, encounterId) + ">\n");
        sbuf.append("   <option value=\"\"> -- </option>\n"); // routine ante chart - use " -- " for not recorded.
        if (value.equals("6")) {
            sbuf.append("   <option value=\"6\" selected><12</option>\n");
        } else {
            sbuf.append("   <option value=\"6\"><12</option>\n");
        }

        for (int i = 12; i < 55; i++) {
            if (value.equals(String.valueOf(i))) {
                sbuf.append("   <option value=\"" + i + "\" selected>" + i + "</option>\n");
            } else {
                sbuf.append("   <option value=\"" + i + "\">" + i + "</option>\n");
            }
        }
        sbuf.append("</select>\n");
        item = sbuf.toString();

        //    sbuf.append("<input id=\"" + widgetName + "\" type=\"text\" name=\"field" + formFieldId + "\" size=\"3\" maxlength=\"3\" value=\"" + value + "\"" + getEventHandler("onchange", updateRecord, encounterId) + "/>\n");
        //  item = sbuf.toString();
    } else if (inputType.equals("hidden-no-edit")) {
        sbuf.append("Editing forbidden for this value.\n");
        item = sbuf.toString();
    } else if (inputType.equals("hidden-no-listing")) {
        sbuf.append("Editing forbidden for this value.\n");
        item = sbuf.toString();
    } else {
        if (inputType.startsWith("SiteId")) { //Encounter record metadata
            List sites = null;
            sites = DynaSiteObjects.getClinics();
            sbuf.append("<select id=\"" + widgetName + "\" name=\"field" + inputType + "\""
                    + getEventHandler("onchange", updateRecord, encounterId) + ">\n");
            sbuf.append("   <option value=\"\">No Information</option>\n");
            for (int i = 0; i < sites.size(); i++) {
                Site site = (Site) sites.get(i);
                if (site.getInactive() == null) {
                    String siteId = site.getId().toString();
                    if (value.equals(site.getSiteAlphaId())) {
                        sbuf.append("   <option value=\"" + siteId + "\" selected>" + site.getName()
                                + "</option>\n");
                    } else {
                        sbuf.append("   <option value=\"" + siteId + "\">" + site.getName() + "</option>\n");
                    }
                }
            }
            sbuf.append("</select>\n");
            item = sbuf.toString();
        } else {
            sbuf.append("*tbd* " + inputType + "\n");
            item = sbuf.toString();
        }
    }
    return item;
}

From source file:emily.command.administrative.GuildStatsCommand.java

@Override
public String execute(DiscordBot bot, String[] args, MessageChannel channel, User author,
        Message inputMessage) {/*from w ww .j  av a  2  s.  c  o  m*/
    if (!bot.getContainer().allShardsReady()) {
        return "Not fully loaded yet!";
    }
    if (args.length == 0) {
        return "Statistics! \n" + getTotalTable(bot, false) + "\nYou are on shard # " + bot.getShardId();
    }
    SimpleRank userrank = bot.security.getSimpleRank(author, channel);
    switch (args[0].toLowerCase()) {
    case "mini":
        return "Statistics! \n" + getTotalTable(bot, true);
    case "music":
        return DebugUtil
                .sendToHastebin(getPlayingOn(bot.getContainer(), userrank.isAtLeast(SimpleRank.BOT_ADMIN)
                        || (args.length >= 2 && args[1].equalsIgnoreCase("guilds"))));
    case "activity":
        return lastShardActivity(bot.getContainer());
    case "users":
        if (!(channel instanceof TextChannel)) {
            return Templates.invalid_use.formatGuild(channel);
        }
        TreeMap<Date, Integer> map = new TreeMap<>();
        Guild guild = ((TextChannel) channel).getGuild();
        List<Member> joins = new ArrayList<>(guild.getMembers());
        for (Member join : joins) {
            Date time = DateUtils.round(new Date(join.getJoinDate().toInstant().toEpochMilli()),
                    Calendar.DAY_OF_MONTH);
            if (!map.containsKey(time)) {
                map.put(time, 0);
            }
            map.put(time, map.get(time) + 1);
        }
        List<Date> xData = new ArrayList<>();
        List<Integer> yData = new ArrayList<>();
        int total = 0;
        for (Map.Entry<Date, Integer> entry : map.entrySet()) {
            total += entry.getValue();
            xData.add(entry.getKey());
            yData.add(total);
        }
        XYChart chart = new XYChart(1024, 600);
        chart.setTitle("Users over time for " + guild.getName());
        chart.setXAxisTitle("Date");
        chart.setYAxisTitle("Users");
        chart.getStyler().setTheme(new GGPlot2Theme());
        XYSeries series = chart.addSeries("Users", xData, yData);
        series.setMarker(SeriesMarkers.CIRCLE);
        try {
            File f = new File("./Sample_Chart.png");
            BitmapEncoder.saveBitmap(chart, f.getAbsolutePath(), BitmapEncoder.BitmapFormat.PNG);
            bot.queue.add(channel.sendFile(f), message -> f.delete());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    return "Statistics! \n" + getTotalTable(bot, false);
}

From source file:com.rapidminer.gui.plotter.charts.DistributionPlotter.java

private CategoryDataset createNominalDataSet() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (Integer classIndex : model.getClassIndices()) {
        DiscreteDistribution distribution = (DiscreteDistribution) model.getDistribution(classIndex,
                translateToModelColumn(plotColumn));
        String labelName = model.getClassName(classIndex);

        // sort values by name
        TreeMap<String, Double> valueMap = new TreeMap<String, Double>();
        for (Double value : distribution.getValues()) {
            String valueName;//ww  w.  j  av  a  2 s.  c o  m
            if (Double.isNaN(value)) {
                valueName = "Unknown";
            } else {
                valueName = distribution.mapValue(value);
            }
            valueMap.put(valueName, value);
        }
        for (Entry<String, Double> entry : valueMap.entrySet()) {
            dataset.addValue(distribution.getProbability(entry.getValue()), labelName, entry.getKey());
        }
    }
    return dataset;
}

From source file:com.aliyun.odps.mapred.bridge.streaming.StreamJob.java

/**
 * Prints out the jobconf properties on stdout
 * when verbose is specified./*from  ww w.  j a  va  2 s .c o  m*/
 */
protected void listJobConfProperties() {
    msg("==== JobConf properties:");
    TreeMap<String, String> sorted = new TreeMap<String, String>();
    for (final Map.Entry<String, String> en : jobConf_) {
        sorted.put(en.getKey(), en.getValue());
    }
    for (final Map.Entry<String, String> en : sorted.entrySet()) {
        msg(en.getKey() + "=" + en.getValue());
    }
    msg("====");
}