private void prepareForm(MetaAsset ma) { GWT.log("Preparing form for " + ma.getName(), null); form.removeAll(); currentFields = ma.getSearchableFields(); formFields = new ArrayList<Field<?>>(); enabledFields.clear(); for (MetaField metaField : currentFields) { Field newField = EditorFactory.createSearchField(metaField); if (newField == null) { logFieldNotSupported(metaField); continue; } newField.addKeyListener( new KeyListener() { @Override public void componentKeyPress(ComponentEvent event) { if (event.getKeyCode() == 13) { submitSearch(); } } }); formFields.add(newField); FieldSet fs = wrapField(newField, metaField, form); form.add(fs, new FormData("90%")); } layout(); }
private void submitSearch() { List<ModelData> query = new ArrayList<ModelData>(); for (Field<?> field : formFields) { ModelData md = new BaseModelData(); MetaField mf = findField(field.getName()); if (mf == null || !enabledFields.containsKey(mf.getName()) || field.getValue() == null || field.getValue().toString().length() == 0 || !field.isValid()) { GWT.log("Will not submit field " + field.getName() + ".", null); continue; } md.set("field", mf); md.set("value", field.getValue()); query.add(md); } GWT.log("Submitting search with " + query.size() + " query elements.", null); AppEvent evt = new AppEvent(ApplicationEvents.SUBMIT_ADVANCED_SEARCH, query); evt.setData("asset", combo.getValue().getBean()); Dispatcher.forwardEvent(evt); }