use of org.jdom.Element in project OpenClinica by OpenClinica.
the class CellFactory method createCellContents.
/**
* Take an Element object and add various types of input tags to it as
* element content.
*
* @param td
* A JDOM Element object representing the td cell
* @param responseName
* a String reprsenting the type of XHTML input as in text,
* textarea, or select
* @param displayBean
* The DisplayItemBean associated with the input element.
* @param tabIndex
* The tab index to use for the input element.
* @param hasDiscrepancyMgt
* Specifies whether the discrepancy icon should be displayed in
* the form cell.
* @param hasSavedData
* A boolean value specifying whether the input elements should
* be pre-filled with database values.
* @param forPrinting
* A boolean value indicating whether CRF printing is involved
* (if true, then discrepancy note icons are not clickable).
* @return The altered td Element with its XHTML content.
*/
public Element createCellContents(Element td, String responseName, DisplayItemBean displayBean, Integer tabIndex, boolean hasDiscrepancyMgt, boolean hasSavedData, boolean forPrinting) {
/*
* if(!
* "".equalsIgnoreCase(displayBean.getMetadata().getQuestionNumberLabel())) {
* td.addContent(displayBean.getMetadata().getQuestionNumberLabel()+"
* "); }
*/
if (responseName.equalsIgnoreCase("text")) {
td = inputGenerator.createTextInputTag(td, displayBean.getItem().getId(), tabIndex, displayBean.getMetadata().getDefaultValue(), displayBean.getItem().getItemDataTypeId() == 9, displayBean.getData().getValue(), hasSavedData);
} else if (responseName.equalsIgnoreCase("textarea")) {
td = inputGenerator.createTextareaTag(td, displayBean.getItem().getId(), tabIndex, displayBean.getData().getValue(), displayBean.getMetadata().getDefaultValue(), hasSavedData);
} else if (responseName.equalsIgnoreCase("checkbox")) {
td = inputGenerator.createCheckboxTag(td, displayBean.getItem().getId(), displayBean.getMetadata().getResponseSet().getOptions(), tabIndex, true, displayBean.getData().getValue(), displayBean.getMetadata().getDefaultValue(), "horizontal".equalsIgnoreCase(displayBean.getMetadata().getResponseLayout()), hasSavedData);
} else if (responseName.equalsIgnoreCase("radio")) {
td = inputGenerator.createRadioButtonTag(td, displayBean.getItem().getId(), displayBean.getMetadata().getResponseSet().getOptions(), tabIndex, true, displayBean.getData().getValue(), displayBean.getMetadata().getDefaultValue(), "horizontal".equalsIgnoreCase(displayBean.getMetadata().getResponseLayout()), hasSavedData);
} else if (responseName.equalsIgnoreCase("single-select")) {
// YW 08-14-2007 <<combine default_value with options
td = inputGenerator.createSingleSelectTag(td, displayBean.getItem().getId(), displayBean.getMetadata().getResponseSet().getOptions(), tabIndex, displayBean.getMetadata().getDefaultValue(), displayBean.getData().getValue(), hasSavedData);
} else if (responseName.equalsIgnoreCase("multi-select")) {
td = inputGenerator.createMultiSelectTag(td, displayBean.getItem().getId(), displayBean.getMetadata().getResponseSet().getOptions(), tabIndex, displayBean.getData().getValue(), displayBean.getMetadata().getDefaultValue(), hasSavedData);
} else if (responseName.equalsIgnoreCase("calculation") || responseName.equalsIgnoreCase("group-calculation")) {
td = inputGenerator.createCaculationTag(td, displayBean.getItem().getId(), displayBean.getMetadata().getResponseSet(), displayBean.getItem().getItemDataTypeId() == 9, displayBean.getData().getValue(), hasSavedData);
} else if (responseName.equalsIgnoreCase("file")) {
td = inputGenerator.createFileTag(td, displayBean.getData().getValue(), forPrinting);
} else if (responseName.equalsIgnoreCase("instant-calculation")) {
td = inputGenerator.createInstantTag(td, displayBean.getItem().getId(), tabIndex, displayBean.getData().getValue(), hasSavedData);
}
String rightSideTxt = displayBean.getMetadata().getRightItemText();
if (rightSideTxt != null && !"".equalsIgnoreCase(rightSideTxt)) {
addTextToCell(td, rightSideTxt, CellFactory.RIGHT);
}
if (displayBean.getMetadata().isRequired()) {
td = inputGenerator.createRequiredAlert(td);
}
if (hasDiscrepancyMgt) {
Element href;
href = inputGenerator.createDiscrepancyNoteSymbol(displayBean.getNumDiscrepancyNotes(), tabIndex, displayBean.getData().getId(), displayBean.getItem().getId(), forPrinting);
if (href != null)
td.addContent(href);
}
// cell
if (responseName.equalsIgnoreCase("text") || responseName.equalsIgnoreCase("textarea") || responseName.equalsIgnoreCase("single-select") || responseName.equalsIgnoreCase("multi-select") || responseName.equalsIgnoreCase("calculation")) {
td = this.addUnits(td, displayBean);
// td = this.addRightItemText(td,displayBean);
}
if (responseName.equalsIgnoreCase("radio") || responseName.equalsIgnoreCase("checkbox")) {
String grLabel = displayBean.getMetadata().getGroupLabel();
boolean grouped = grLabel != null && !"".equalsIgnoreCase(grLabel) && !grLabel.equalsIgnoreCase("ungrouped");
if (!grouped) {
td = this.addUnits(td, displayBean);
} else {
// Do not add units if the layout is horizontal
if (!displayBean.getMetadata().getResponseLayout().equalsIgnoreCase("Horizontal")) {
td = this.addUnits(td, displayBean);
}
}
}
return td;
}
use of org.jdom.Element in project OpenClinica by OpenClinica.
the class CellFactory method createCellContentsForChecks.
public Element[] createCellContentsForChecks(String responseName, DisplayItemBean displayBean, Integer optionsLength, Integer tabIndex, boolean hasDBValues, boolean forPrinting) {
// In this HTML design, so far, we do not include discrepancy note
// symbols
// or icons for horizontal layouts
Element[] tdElements = new Element[optionsLength];
Element td;
List<ResponseOptionBean> list = new ArrayList<ResponseOptionBean>();
int indx = 0;
ResponseOptionBean reOptBean;
for (Iterator iter = displayBean.getMetadata().getResponseSet().getOptions().iterator(); iter.hasNext(); ) {
reOptBean = (ResponseOptionBean) iter.next();
list.add(reOptBean);
td = new Element("td");
if (responseName.equalsIgnoreCase("checkbox")) {
td = inputGenerator.createCheckboxTag(td, displayBean.getItem().getId(), list, tabIndex, false, displayBean.getData().getValue(), displayBean.getMetadata().getDefaultValue(), true, hasDBValues);
} else {
// Second to last true parameter is for horizontal radios
td = inputGenerator.createRadioButtonTag(td, displayBean.getItem().getId(), list, tabIndex, false, displayBean.getData().getValue(), displayBean.getMetadata().getDefaultValue(), true, hasDBValues);
}
tdElements[indx] = td;
indx++;
list.clear();
}
return tdElements;
}
use of org.jdom.Element in project OpenClinica by OpenClinica.
the class CellFactoryPrintDecorator method createCellContentsForVerticalLayout.
/**
* Create checkbox or radio buttons in a vertical layout, in ungrouped
* tables.
*
* @param td
* @param responseName
* The type of input such as "radio."
* @param displayBean
* The DisplayItemBean that provides the content for the table
* cell. *
* @param tabIndex
* The tab index number, not relevant for printing.
* @param hasDiscrepancyMgt
* True if discrepancy note icons should be displayed.
* @param hasSavedData
* A boolean value indicating whether the input element is
* prefilled with database data.
* @param forPrinting
* A boolean value indicating whether CRF printing is involved
* (if true, then discrepancy note icons are not clickable).
* @return The HTML TD cell with the input cell and other elements as its
* contents.
*/
public Element createCellContentsForVerticalLayout(Element td, String responseName, DisplayItemBean displayBean, Integer tabIndex, boolean hasDiscrepancyMgt, boolean hasSavedData, boolean forPrinting) {
if (responseName.equalsIgnoreCase("checkbox")) {
td = dataEntryDecorator.createCheckboxTag(td, displayBean.getItem().getId(), displayBean.getMetadata().getResponseSet().getOptions(), tabIndex, true, displayBean.getData().getValue(), displayBean.getMetadata().getDefaultValue(), false, hasSavedData);
} else if (responseName.equalsIgnoreCase("radio")) {
td = dataEntryDecorator.createRadioButtonTag(td, displayBean.getItem().getId(), displayBean.getMetadata().getResponseSet().getOptions(), tabIndex, true, displayBean.getData().getValue(), displayBean.getMetadata().getDefaultValue(), false, hasSavedData);
}
if (displayBean.getMetadata().isRequired()) {
td = dataEntryDecorator.createRequiredAlert(td);
}
if (hasDiscrepancyMgt) {
Element href;
href = dataEntryDecorator.createDiscrepancyNoteSymbol(displayBean.getNumDiscrepancyNotes(), tabIndex, displayBean.getData().getId(), displayBean.getItem().getId(), forPrinting);
if (href != null)
td.addContent(href);
}
// Add any units or right item text
td = this.addUnits(td, displayBean);
return td;
}
use of org.jdom.Element in project OpenClinica by OpenClinica.
the class CellFactoryPrintDecorator method addUnits.
public Element addUnits(Element tdCell, DisplayItemBean displayBean) {
if (displayBean == null) {
return tdCell;
}
ItemBean itemBean = displayBean.getItem();
if (itemBean == null) {
return tdCell;
}
StringBuilder units = new StringBuilder(displayBean.getItem().getUnits());
if (units.length() < 1) {
return tdCell;
}
Element spanElement = new Element("span");
spanElement.setAttribute("style", "float:left;clear:both");
// surround units with parentheses
units = units.insert(0, "(");
units = units.append(")");
spanElement.addContent(" " + units.toString());
tdCell.addContent(spanElement);
return tdCell;
}
use of org.jdom.Element in project OpenClinica by OpenClinica.
the class DataEntryDecorator method createCheckboxTag.
public Element createCheckboxTag(Element tdCell, Integer itemId, List options, Integer tabNumber, boolean includeLabel, String dbValue, String defaultValue, boolean isHorizontal, boolean hasSavedData) {
// The input element
Element element;
// the span element that contains the input element
Element spanElement;
String[] arrayOfValues = new String[] {};
int count = 0;
// Handles lone Strings, or Strings separated by commas
if (dbValue != null && dbValue.length() > 0) {
synchronized (inputGenerator) {
arrayOfValues = inputGenerator.handleSplitString(dbValue);
}
} else if (!hasSavedData && defaultValue != null && defaultValue.length() > 0) {
synchronized (inputGenerator) {
arrayOfValues = inputGenerator.handleSplitString(defaultValue);
}
}
for (Object responseOptBean : options) {
spanElement = new Element("span");
spanElement.setAttribute("style", "float:left;clear:both");
synchronized (inputGenerator) {
element = inputGenerator.initializeInputElement("checkbox", itemId, tabNumber);
}
spanElement.addContent(element);
String value = ((ResponseOptionBean) responseOptBean).getValue();
String forDefVal = ((ResponseOptionBean) responseOptBean).getText();
element.setAttribute("value", value);
// It's checked if its value equals the DB value
if (dbValue != null && dbValue.length() > 0) {
// && value.equalsIgnoreCase(dbValue)
for (String string : arrayOfValues) {
if (value.equalsIgnoreCase(string)) {
element.setAttribute("checked", "checked");
}
}
} else if (!hasSavedData && defaultValue != null && defaultValue.length() > 0) {
// && value.equalsIgnoreCase(dbValue)
for (String string : arrayOfValues) {
if (forDefVal.equalsIgnoreCase(string) || value.equalsIgnoreCase(string)) {
element.setAttribute("checked", "checked");
}
}
}
tdCell.addContent(spanElement);
if (includeLabel) {
spanElement.addContent(((ResponseOptionBean) responseOptBean).getText());
}
}
return tdCell;
}
Aggregations