public void initialise(RandomiserInstance ri) { LinkedHashMap hashmap; String sMax, sFromDate, sDateTo, sPercent, sNull, sSelectedDays; int iMax; Object objValues[] = new Object[3]; txtName.setText(ri.getName()); txtDescription.setText(ri.getDescription()); hashmap = ri.getProperties(); sMax = (String) hashmap.get("rangesNum"); try { iMax = Integer.parseInt(sMax); for (int i = 0; i < iMax; i++) { sFromDate = (String) hashmap.get("fromField" + i); objValues[0] = Date.valueOf(sFromDate); sDateTo = (String) hashmap.get("toField" + i); objValues[1] = Date.valueOf(sDateTo); sPercent = (String) hashmap.get("percentField" + i); objValues[2] = Integer.valueOf(sPercent); newModelDates.addRow(objValues); } sNull = (String) hashmap.get("nullField"); spinNull.setValue(Integer.parseInt(sNull)); } catch (Exception e) { logger.warn("Error while setting properties:", e); } sSelectedDays = (String) hashmap.get("selectedDays"); }
public RandomiserInstance getRandomiserInstance() { RandomiserInstance ri = new RandomiserInstance(); LinkedHashMap hashmap = new LinkedHashMap(); String name, sDateFrom, sDateTo, sPercent, sDays; Date dateFrom, dateTo; Object objValues[] = new Object[3]; int rowCount, error, percent; ri.setName(txtName.getText()); ri.setDescription(txtDescription.getText()); ri.setRandomiserType("DateRandomiser"); error = 0; rowCount = tblDateRanges.getRowCount(); hashmap.put("rangesNum", "" + rowCount); for (int i = 0; i < rowCount; i++) { try { objValues[0] = (Object) newModelDates.getValueAt(i, 0); objValues[1] = (Object) newModelDates.getValueAt(i, 1); objValues[2] = (Object) newModelDates.getValueAt(i, 2); sDateFrom = objValues[0].toString(); sDateTo = objValues[1].toString(); sPercent = objValues[2].toString(); dateFrom = Date.valueOf(sDateFrom); dateTo = Date.valueOf(sDateTo); if (dateFrom.getTime() > dateTo.getTime()) { logger.warn("Problem retrieving table values, From date is higher than To date"); error = i; return null; } percent = Integer.valueOf(sPercent); hashmap.put("fromField" + i, sDateFrom); hashmap.put("toField" + i, sDateTo); hashmap.put("percentField" + i, "" + percent); } catch (Exception e) { logger.warn("Problem retrieving table values", e); error = i; } } hashmap.put("nullField", "" + spinNull.getValue()); ri.setProperties(hashmap); return ri; }