/** * @param path The path in the data model * @return A map containing the path/value pairs for all matching elements, or an empty * map if no matching values found. */ public Map<QueryPath, Object> query(final String path) { return query(QueryPath.parse(path)); }
private FieldDescriptor getFieldDescriptor( String fieldKey, MessageKeyInfo messageKey, Widget widget, String parentPath) { QueryPath path = QueryPath.concat(parentPath, fieldKey); Metadata meta = modelDefinition.getMetadata(path); FieldDescriptor fd; if (widget != null) { fd = new FieldDescriptor(path.toString(), messageKey, meta, widget); } else{ fd = new FieldDescriptor(path.toString(), messageKey, meta); } return fd; }
QueryPath parentPath = QueryPath.parse(path); int i = parentPath.size(); QueryPath translatedPath = fullPath.subPath(0, fullPath.size()-1); translatedPath.add(new Data.StringKey("_runtimeData")); translatedPath.add(new Data.StringKey((String)fullPath.get(fullPath.size() - 1).get())); translatedPath.add(new Data.StringKey("id-translation")); fieldPath = translatedPath.subPath(i, translatedPath.size()); fieldPath = fullPath.subPath(i, fullPath.size()); fieldPath = fullPath.subPath(i, fullPath.size()); if (fieldPath.get(0).toString().equals(QueryPath.getWildCard())) { fieldPath.remove(0);
public String translatePath(String path, String parentPath, int num) { String fieldPath; if (parentPath != null) { QueryPath parent = QueryPath.concat(parentPath); int i = parent.size(); QueryPath subPath = QueryPath.concat(path); String itemPath = subPath.subPath(i, subPath.size()).toString(); QueryPath qp = QueryPath.concat(parentPath, itemPath); fieldPath = qp.toString(); } else { fieldPath = path; } fieldPath = fieldPath.replace("*", "" + num); return fieldPath; }
hasChildElements = false; for (Map.Entry<QueryPath, Object> e : values.entrySet()) { QueryPath listPath = QueryPath.parse(e.getKey().toString()); listPath.add(Data.WILDCARD_KEY); values = model.query(listPath); if (hasChildElements || path.toString().isEmpty()) { String basePath = path.toString(); if (meta.getProperties() != null) { Object[] keys = meta.getProperties().keySet().toArray(); String element = (String) keys[keyIndex]; if (!element.contains("runtimeData")) { QueryPath childPath = QueryPath.concat(basePath, element); Map<QueryPath, Object> childValues = model.query(childPath); if (!childValues.isEmpty()) { for (int childKeyIndex = 0; childKeyIndex < childKeys.length; childKeyIndex++) { QueryPath childElement = (QueryPath) childKeys[childKeyIndex]; QueryPath childElementDeletePath = QueryPath.parse(childElement.toString() + QueryPath.getPathSeparator() + RUNTIME_DELETED_KEY); try { Boolean childDeletedObject = model.get(childElementDeletePath);
for (int i = 0; i < path.size(); i++) { if (d == null) { final Key key = path.get(i); if (key.equals(Data.WILDCARD_KEY)) { final QueryPath relative = path.subPath(i + 1, path.size()); if (!relative.isEmpty()) { for (Key wildcardKey : keys) { if (!("_runtimeData".equals(wildcardKey.get()))) { QueryPath wildcardPath = path.subPath(0, path.size() - 1); wildcardPath.add(wildcardKey); result.put(wildcardPath, d.get(wildcardKey)); } else if (i < path.size() - 1) { d = d.get(key); } else { final QueryPath resultPath = d.getQueryPath(); resultPath.add(key); String relativePath = resultPath.toString(); if (relativePath.contains("/")) { relativePath = relativePath.substring(parentPath.length()); result.put(QueryPath.parse(relativePath), resultValue); }else{ result.put(resultPath, resultValue);
@Override public void setWidgetValue(HasDataValue widget, DataModel model, String path) { QueryPath qPath = QueryPath.parse(path); Object value = null; if(model!=null){ Property p = iter.next(); if(!"_runtimeData".equals(p.getKey())){ QueryPath translationPath = new QueryPath(); translationPath.add(new Data.StringKey(qPath.toString())); translationPath.add(new Data.StringKey("_runtimeData")); translationPath.add(new Data.IntegerKey((Integer)p.getKey())); translationPath.add(new Data.StringKey("id-translation")); String translation = model.get(translationPath.toString()); String id = p.getValue().toString(); translations.put(id, translation); QueryPath translationPath = qPath.subPath(0, qPath.size()-1); translationPath.add(new Data.StringKey("_runtimeData")); translationPath.add(new Data.StringKey((String)qPath.get(qPath.size() - 1).get())); translationPath.add(new Data.StringKey("id-translation")); String translation = model.get(translationPath.toString()); if(translation != null && !translation.isEmpty()) { ((TranslatableValueWidget)widget).setValue((String)value, translation);
private Object getCrossFieldMinValue(DataModel model, QueryPath path, Metadata meta) { Object v = null; List<ConstraintMetadata> constraints = meta.getConstraints(); for (int i = 0; i < constraints.size(); i++) { ConstraintMetadata cons = constraints.get(i); if (cons.getMinValue() != null && cons.getMinValue().contains("../")) { QueryPath crossFieldPath = QueryPath.parse(path.toString()); String crossFieldKey = cons.getMinValue().substring(3); crossFieldPath.remove(crossFieldPath.size() - 1); crossFieldPath.add(new StringKey(crossFieldKey)); v = model.get(crossFieldPath); } } return v; }
/** * Flags the data at the provided path as dirty * * @param model * the DataModel containing the dirty data * @param qPath * the path to the dirty data */ protected void setDirtyFlag(DataModel model, QueryPath qPath) { QueryPath parent = qPath.subPath(0, qPath.size() - 1); QueryPath qPathDirty = new QueryPath(); qPathDirty.addAll(parent); qPathDirty.add(RUNTIME_ROOT); qPathDirty.add(DIRTY_PATH); ensureDirtyFlagPath(model.getRoot(), qPathDirty); Data flags = model.get(qPathDirty); flags.set(qPath.get(qPath.size() - 1), Boolean.TRUE); }
private void dirtyCheckField(FieldDescriptor fieldDescriptor, DataModel model){ QueryPath fieldPath = QueryPath.parse(fieldDescriptor.getFieldKey()); QueryPath qPathDirty = fieldPath.subPath(0, fieldPath.size() - 1); qPathDirty.add(ModelWidgetBindingSupport.RUNTIME_ROOT); qPathDirty.add(ModelWidgetBindingSupport.DIRTY_PATH); qPathDirty.add(fieldPath.get(fieldPath.size()-1)); Boolean dirty = false; if(ensureDirtyFlagPath(model.getRoot(), qPathDirty)){ dirty = model.get(qPathDirty); } if(dirty){ setIsDirty(true); fieldDescriptor.setDirty(true); } }
private static Metadata get(Metadata metadata, QueryPath frame, DataType type){ if(type == DataType.LIST){ return get(metadata.getProperties().get(QueryPath.getWildCard()), frame.subPath(1, frame.size())); } else{ return get(metadata.getProperties().get(frame.get(0).get()), frame.subPath(1, frame.size())); } } }
/** * Includes this field on the current line at the next horizontal position * * Will use default widget and binding. For more complex fields create your own * FieldDescriptor and pass it in using the other addField method * * @param fieldKey * @param messageKey * @param parentPath * @param meta */ public void addField(String fieldKey, String messageKey, String parentPath, Metadata meta) { QueryPath path = QueryPath.concat(parentPath, QueryPath.getWildCard(), fieldKey); MultiplicityFieldConfiguration fieldConfig = new MultiplicityFieldConfiguration(path.toString(), new MessageKeyInfo(messageKey), meta, null); fieldConfig.setRequired(false); addFieldConfiguration(fieldConfig); }
@Override public Metadata getMetadata(String path) { QueryPath queryPath = QueryPath.concat(path); return getMetadata(queryPath); }
/** * Checks to see if data exists for the path passed in * @param sPath * @return */ public boolean isValidPath(String sPath) { QueryPath path = QueryPath.parse(sPath); boolean result = false; Data root = this.getRoot(); for (int i = 0; i < path.size(); i++) { Data.Key key = path.get(i); if (!root.containsKey(key)) { result = false; break; } else if (i < path.size() - 1) { root = (Data) root.get(key); } else { result = true; break; } } return result; }
public void remove(final QueryPath path) { QueryPath parent = null; QueryPath leavePath = null; if (path != null && path.size() >= 2) { parent = path.subPath(0, path.size() - 1); leavePath = path.subPath(path.size() - 1, path.size()); Object parentData = this.get(parent); if (parentData != null && parentData instanceof Data) { ((Data) parentData).remove( new Data.StringKey(leavePath.toString())); } } else if (path != null) { root.remove(new Data.StringKey(path.toString())); } }
public void set(final QueryPath path, final Value value) { definition.ensurePath(root, path, value instanceof DataValue); if (path.size() > 1) { final QueryPath q = path.subPath(0, path.size() - 1); final Data d = root.query(q); d.set(path.get(path.size() - 1), value); } else { root.set(path.get(0), value); } }
@Override public void setWidgetValue(RichTextEditor object, DataModel model, String path) { String richTextRoot = path + QueryPath.getPathSeparator(); QueryPath qPath = QueryPath.parse(richTextRoot + "plain"); String formatted = model.get(qPath); qPath = QueryPath.parse(richTextRoot + "formatted"); String plain = model.get(qPath); if (formatted != null) { object.setHTML(formatted); } else if (plain != null) { object.setText(plain); } else { object.setHTML(""); } }
private static void _findDirtyElements(Data data, List<QueryPath> results, QueryPath currentFrame) { if (data == null) { return; } Data flags = getDirtyFlags(data); if (flags != null && flags.size() > 0) { for (Data.Property p : flags) { QueryPath q = new QueryPath(); q.addAll(currentFrame); Key key = p.getWrappedKey(); q.add(key); results.add(q); } } for (Data.Property p : data) { if (p.getValueType().equals(Data.class) && p.getValue() != null) { QueryPath q = new QueryPath(); q.addAll(currentFrame); Key key = p.getWrappedKey(); q.add(key); _findDirtyElements((Data) p.getValue(), results, q); } } } public static Data getDirtyFlags(Data data) {