public void buttonClick(ClickEvent event) { Field name = form.getField("name"); Field prenom = form.getField("prenom"); Field age = form.getField("age"); name.setValue(""); prenom.setValue(""); age.setValue(""); }
private void setEditValue(PrefPanel pp, String name, PersistentBean bean, int mode) { Field fld = pp.getField(name); if (bean == null) fld.setValue(null); else { Object value = bean.getObject(name); fld.setValue(value); } setMode(fld, mode); }
/** {@inheritDoc} */ @Override public Field loadByValue(int nIdEntry, String strValue, Plugin plugin) { DAOUtil daoUtil = new DAOUtil(SQL_QUERY_FIND_BY_VALUE, plugin); daoUtil.setInt(1, nIdEntry); daoUtil.setString(2, strValue); daoUtil.executeQuery(); Field field = null; IEntry entry = null; if (daoUtil.next()) { field = new Field(); field.setIdField(daoUtil.getInt(1)); // parent entry entry = new Entry(); entry.setIdEntry(daoUtil.getInt(2)); field.setEntry(entry); field.setTitle(daoUtil.getString(3)); field.setValue(daoUtil.getString(4)); field.setHeight(daoUtil.getInt(5)); field.setWidth(daoUtil.getInt(6)); field.setDefaultValue(daoUtil.getBoolean(7)); field.setMaxSizeEnter(daoUtil.getInt(8)); field.setPosition(daoUtil.getInt(9)); field.setValueTypeDate(daoUtil.getDate(10)); field.setRoleKey(daoUtil.getString(11)); field.setWorkgroup(daoUtil.getString(12)); field.setShownInResultList(daoUtil.getBoolean(13)); field.setShownInResultRecord(daoUtil.getBoolean(14)); } daoUtil.free(); return field; }
/** * Processes the results of ASR when recognition is successful * * <p>CHANGED WITH RESPECT TO FORMFILLLIB (chapter 5) Changes: - If any of the recognized values * is valid for the field (according to the grammar), it is saved as the current value, and it is * synchronized with the GUI - If not, the field is interpreted again */ @Override public void processAsrResults(ArrayList<String> nBestList, float[] nBestConfidences) { Field currentField = form.getField(currentPosition); int i = 0; Boolean validValue = false; // Search in the n best ASR recognition results for a valid value according to the field's // grammar while (i < nBestList.size() && !validValue) { validValue = currentField.isvalid(nBestList.get(i)); i++; } // If there is a valid value... if (validValue) { currentField.setValue( nBestList.get(i - 1)); // ... it is set as the current value for the field result.put(currentField.getName(), nBestList.get(i - 1)); try { oralToGui(currentField); // and it is synchronized with the GUI } catch (MultimodalException e) { Toast.makeText(this, e.getReason(), Toast.LENGTH_LONG).show(); Log.e(LOGTAG, e.getReason()); } moveToNextField(); } // If not... else { interpretCurrentField(); // ... the field is interpreted again } }
/** * Sets the value of the current field component. * * @param value The value to set */ public void setValue(Object value) { if (fieldComponent != null) { if (fieldComponent instanceof Field) { Field field = ((Field) fieldComponent); field.setValue(value); if (field instanceof Select) { ((Select) fieldComponent).select(value); } } else if (fieldComponent instanceof FilterContainer) { ((FilterContainer) fieldComponent).setValue(value); } } }
private void setEditValueWithInheritence(String name, PersistentBean bean) { Field fld = metadataPP.getField(name); if (bean == null) { fld.setValue(null); return; } Object value = bean.getObject("localMetadata." + name); // local, non inheritable if (value != null) { fld.setValue(value); setMode(fld, 0); } else { value = bean.getObject("localMetadataInheritable." + name); // local, inheritable if (value != null) { fld.setValue(value); setMode(fld, 1); } else { value = bean.getObject(name); // inherited fld.setValue(value); setMode(fld, (value == null) ? 1 : 2); } } }
/** {@inheritDoc} */ @Override public List<Field> selectFieldListByIdEntry(int nIdEntry, Plugin plugin) { List<Field> fieldList = new ArrayList<Field>(); DAOUtil daoUtil = new DAOUtil(SQL_QUERY_SELECT_FIELD_BY_ID_ENTRY, plugin); daoUtil.setInt(1, nIdEntry); daoUtil.executeQuery(); Field field = null; IEntry entry = null; while (daoUtil.next()) { field = new Field(); field.setIdField(daoUtil.getInt(1)); // parent entry entry = new Entry(); entry.setIdEntry(daoUtil.getInt(2)); field.setEntry(entry); field.setTitle(daoUtil.getString(3)); field.setValue(daoUtil.getString(4)); field.setHeight(daoUtil.getInt(5)); field.setWidth(daoUtil.getInt(6)); field.setDefaultValue(daoUtil.getBoolean(7)); field.setMaxSizeEnter(daoUtil.getInt(8)); field.setPosition(daoUtil.getInt(9)); field.setValueTypeDate(daoUtil.getDate(10)); field.setRoleKey(daoUtil.getString(11)); field.setWorkgroup(daoUtil.getString(12)); field.setShownInResultList(daoUtil.getBoolean(13)); field.setShownInResultRecord(daoUtil.getBoolean(14)); fieldList.add(field); } daoUtil.free(); return fieldList; }
private static Entry generateEntry(List<Field> fields) { fields.get(0).setValue("2015/10/15"); int n = 0; for (Field f : fields) f.setValue(String.valueOf(++n)); return new Entry(fields); }
private List<Field> parseFields(List nodes, DocResult outerDoc, Node parent) { List<Field> fields = new ArrayList<Field>(nodes.size()); for (Element node : (List<Element>) nodes) { Field field = new Field(); String name = node.attributeValue("name"); field.setName(name); field.setParent(parent); DocResult docResult = parseDoc(node, field); String type = node.attributeValue("type"); field.setType(type); field.setRequired(!"optional".equals(node.attributeValue("required"))); String index = node.attributeValue("index"); if (index != null) { field.setIndex(Integer.parseInt(index)); } String nodeName = node.getName(); if ("const".equals(nodeName)) { // 常量 field.setValue(node.element("value").getStringValue()); } else if ("item".equals(nodeName)) { // 枚举项 String value = node.attributeValue("value"); field.setIndex(Integer.parseInt(value)); // 设置枚举项的index为对应value field.setValue(value); } else if ("ex".equals(nodeName)) { // 异常 Doc fieldDoc = field.getDoc(); if (fieldDoc == DocResult.NULL) { field.setDoc(fieldDoc = new Doc()); } for (Map.Entry<String, String> entry : docResult.getErrors().entrySet()) { // 将doc中的异常信息写入属性 fieldDoc.putTag(entry.getKey(), entry.getValue()); } if (outerDoc != null) { // 方法文档不为空 String outerEx = outerDoc.getError(name); // 读取方法文档中的异常描述 if (StringUtils.isEmpty(fieldDoc.getDesc()) && outerEx != null) { // 如果自己的文档没有注释,则设置为方法的注释 fieldDoc.setDesc(outerEx); } if ("Type.AnyException" .equals(type)) { // 如果是通用的AnyException,则将外部定义的类似@error 315 无效用户状态写入属性 for (Map.Entry<String, String> entry : outerDoc.getErrors().entrySet()) { String key = entry.getKey(); if (!key.endsWith("Exception")) { // 若果是Exception说明不是一个异常代码 fieldDoc.putTag(entry.getKey(), entry.getValue()); } } } } } else { field.setValue(node.attributeValue("default")); } if (outerDoc != null) { Doc outerFieldDoc = outerDoc.getFidleDoc(field.getName()); // 判断外部是否定义了字段的描述文档 if (outerFieldDoc != null) { Doc fieldDoc = field.getDoc(); if (fieldDoc == DocResult.NULL) { field.setDoc(outerFieldDoc); } else { if (StringUtils.isEmpty(fieldDoc.getDesc())) { fieldDoc.setDesc(outerFieldDoc.getDesc()); } for (Map.Entry<String, String> entry : outerFieldDoc.getTags().entrySet()) { fieldDoc.putTagIfAbsent(entry.getKey(), entry.getValue()); // 默认内部注视优先 } } } } fields.add(field); } return fields; }
public void setField(String fieldName, String value) { logger.debug( "about to set " + fieldName + " with value " + value + " on hash# " + this.hashCode()); Field field = fields.get(fieldName); if (field == null) { logger.debug(fieldName + " not exists on " + this.getClass().getName()); return; } switch (field.getType()) { case DAOutils.STRING_TYPE: field.setValue(value); logger.debug( "set AS STRING " + fieldName + " with value " + value + " on hash# " + this.hashCode()); break; case DAOutils.INT_TYPE: field.setValue(new Integer(value)); logger.debug( "set AS INT " + fieldName + " with value " + value + " on hash# " + this.hashCode()); break; case DAOutils.TIMESTAMP_TYPE: if (value.length() == 13) // unix time field.setValue(new Timestamp(Long.parseLong(value))); else { // date format try { field.setValue(new Timestamp(df.parse(value).getTime())); } catch (ParseException e) { logger.error(e.getMessage(), e); } } logger.debug( "set AS TIMESTAMP " + fieldName + " with value " + value + " on hash# " + this.hashCode()); break; case DAOutils.FLOAT_TYPE: field.setValue(new Float(value)); logger.debug( "set AS FLOAT " + fieldName + " with value " + value + " on hash# " + this.hashCode()); break; case DAOutils.DATE_TYPE: if (value.length() == 13) // unix time field.setValue(new Date(Long.parseLong(value))); else { // date format try { field.setValue(new Date(dfDate.parse(value).getTime())); } catch (ParseException e) { logger.error(e.getMessage(), e); } } logger.debug( "set AS DATE " + fieldName + " with value " + value + " on hash# " + this.hashCode()); break; case DAOutils.PASSWORD_TYPE: field.setValue(value); logger.debug( "set AS STRING " + fieldName + " with value " + value + " on hash# " + this.hashCode()); break; } }
public void load() { SqlConn con = null; logger.debug("dao load method"); try { con = ConnFactory.getConnection(DB); String s = "select * from " + table + " where " + PK + "=:::"; if (fields.get(PK).getType() == DAOutils.INT_TYPE) s = s.replace(":::", String.valueOf(fields.get(PK).getValueAsInt())); if (fields.get(PK).getType() == DAOutils.STRING_TYPE) s = s.replace(":::", "'" + fields.get(PK).getValueAsString() + "'"); ResultSet rs = con.query(s); while (rs.next()) { for (Field field : fields.values()) { // for field names not in the DB that we want to use // programatically, we start the field name with "EMPTY_" if (field.name.startsWith("EMPTY_")) continue; logger.debug("setting field " + field.name + " with value " + rs.getObject(field.name)); switch (field.getType()) { case DAOutils.STRING_TYPE: field.setValue(rs.getString(field.name)); break; case DAOutils.INT_TYPE: field.setValue(-1); field.setValue(rs.getInt(field.name)); break; case DAOutils.TIMESTAMP_TYPE: field.setValue(rs.getTimestamp(field.name)); break; case DAOutils.FLOAT_TYPE: field.setValue(rs.getFloat(field.name)); break; case DAOutils.DATE_TYPE: field.setValue(rs.getDate(field.name)); break; case DAOutils.PASSWORD_TYPE: field.setValue(rs.getString(field.name)); break; case DAOutils.BLOB_TYPE: field.setValue(rs.getBlob(field.name)); break; } } } } catch (SQLException e) { logger.error( "failed to load object " + this.getClass().getName() + " from table " + table + " with id " + fields.get(PK).getValueAsString() + " -- " + e.getMessage(), e); } finally { if (con != null) con.close(); } }