/** * Converts the data map to a bracketed string representation * @return */ private String _toString(){ StringBuffer dataString = new StringBuffer(); dataString.append("{"); for (Iterator itr = this.iterator(); itr.hasNext();) { Property p = (Property) itr.next(); dataString.append(p.getKey() + "=" + p.getValue()); if (itr.hasNext()) { dataString.append(", "); } } dataString.append("}"); return dataString.toString(); }
/** * Converts a list represented by DataValue to a list of values as a comma delimited StringValue * * @param dataValue * DataValue representing a list object * @return the list converted to a comma delimited StringValue */ protected String convertDataValueToStringValue(Data data) { StringBuffer sbValue = new StringBuffer(); Iterator<Property> propertyIterator = data.realPropertyIterator(); while (propertyIterator.hasNext()) { Property property = propertyIterator.next(); String propertyValue = property.getValue(); sbValue.append(","); sbValue.append(propertyValue); } if (sbValue.toString().isEmpty()) { return ""; } else { return sbValue.toString().substring(1); } }
/** * Converts a list represented by DataValue to a list of values as a comma delimited StringValue * @param dataValue DataValue representing a list object * @return the list converted to a comma delimited StringValue */ private StringValue convertDataValueToStringValue(DataValue dataValue) { StringBuffer sbValue = new StringBuffer(); Data data = dataValue.get(); Iterator<Property> propertyIterator = data.realPropertyIterator(); while(propertyIterator.hasNext()){ Property property = propertyIterator.next(); String propertyValue = property.getValue(); sbValue.append(","); sbValue.append(propertyValue); } StringValue stringValue = new StringValue(sbValue.toString().substring(1)); return stringValue; }
private void dataToOutlineNodes(Data data, List<OutlineNode<LOPicker>> loOutlineNodes, int identLevel) { if (data != null) { LoDisplayInfoSortedSet sortedDisplayInfos = new LoDisplayInfoSortedSet(); for (Data.Property property : data) { Data loDisplayInfoData = property.getValue(); LoDisplayInfoHelper loDisplayInfoHelper = new LoDisplayInfoHelper(loDisplayInfoData); sortedDisplayInfos.add(loDisplayInfoHelper); } for (LoDisplayInfoHelper loDisplayInfoHelper : sortedDisplayInfos) { LOPicker picker = new LOPicker(LOBuilder.getMessageGroup(), LOBuilder.getType(), LOBuilder.getState(), LOBuilder.getRepoKey(), LOBuilder.getLoListDescLength()); LoInfoHelper loInfoHelper = new LoInfoHelper(loDisplayInfoHelper.getLoInfo()); RichTextHelper descriptionHelper = new RichTextHelper(loInfoHelper.getDescr()); picker.setLOText(descriptionHelper.getPlain()); List<LoCategoryInfo> categories = getCategoryList(loDisplayInfoHelper); picker.setLOCategories(categories); picker.setMetaInfoData(loInfoHelper.getMeta()); OutlineNode<LOPicker> node = new OutlineNode<LOPicker>(); node.setUserObject(picker); node.setOpaque(loInfoHelper.getId()); node.setIndentLevel(identLevel); loOutlineNodes.add(node); // recurse dataToOutlineNodes(loDisplayInfoHelper.getDisplayInfoList(), loOutlineNodes, identLevel + 1); } } }
private void transform(Data loData, StringTreeStructure rootModel) { for (Data.Property property : loData) { Data loDisplayInfoData = property.getValue(); LoDisplayInfoHelper loDisplayInfoHelper = new LoDisplayInfoHelper(loDisplayInfoData); LoInfoHelper loInfoHelper = new LoInfoHelper(loDisplayInfoHelper.getLoInfo()); RichTextHelper descriptionHelper = new RichTextHelper(loInfoHelper.getDescr()); Data categoriesData = loDisplayInfoHelper.getCategoryInfoList(); List<String> categories = new ArrayList<String>(); if (null != categoriesData) { Iterator<Data.Property> itr = categoriesData.realPropertyIterator(); while (itr.hasNext()) { Data.Property catProp = itr.next(); Data catData = catProp.getValue(); LoCategoryInfoHelper category = new LoCategoryInfoHelper(catData); categories.add(category.getName()); } } int index = 0; String sequence = loInfoHelper.getSequence(); if (sequence != null) { index = Integer.parseInt(sequence); } StringTreeStructure childModel = new StringTreeStructure(index, descriptionHelper.getPlain(), categories); transform(loDisplayInfoHelper.getDisplayInfoList(), childModel); rootModel.addChild(childModel); } }
/** * Performs a recursive comparison of the two parameters. * * @return true when all members of the provided hierarchies are equivalent */ private static boolean deepEquals(Data o1, Data o2) { Iterator<Property> iter = o1.iterator(); while (iter.hasNext()) { Property prop = iter.next(); Key key = prop.getWrappedKey(); Object value1 = prop.getValue(); Object value2 = o2.get(key); if (value1 == null ^ value2 == null) { return false; } else if (value1 != null && value1 instanceof Data && value2 instanceof Data) { boolean recursiveResult = deepEquals((Data) value1, (Data) value2); if (!recursiveResult) { return false; } } else if (value1 != value2 && !(value1.equals(value2))) { return false; } } return true; } }
@Override public void setValue(Value value) { clear(); if (value != null) { try { if (value instanceof DataValue) { Data data = ((DataValue) value).get(); Iterator<Property> iter = data.realPropertyIterator(); while (iter.hasNext()) { Property p = iter.next(); setSingleValue(p.getValue()); } } else { setSingleValue(value.get()); } } catch (ClassCastException cce) { String errorMsg = "ClassCastException in KSSelectedList.java::setValue \n " + "Trying to cast Value from: " + value.getClass().getName() + "\n " + "TO DataValue.java. \n Value was of type " + value.getType().getName() + "\n "; try { errorMsg += "Value=[" + value.get().toString() + "]"; } catch (Exception ex) { errorMsg += "Error printing error value: " + ex.getMessage(); } throw new ClassCastException(errorMsg); } } }
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) {
private void showVariationView() { String variationId = context.getAttributes().get(ProgramConstants.VARIATION_ID); if (variationId != null) { final Data variationMap = getDataProperty(ProgramConstants.VARIATIONS); if (variationMap != null) { int row = 0; for (Property p : variationMap) { final Data variationData = p.getValue(); if (variationData != null) { if (variationData.get(ProgramConstants.ID).equals(variationId)) { //FIXME: Find a better way to do this. // We shouldn't be maintaining two separate datamodels for progs and variations Data credData = getDataProperty(ProgramConstants.CREDENTIAL_PROGRAM); variationData.set(ProgramConstants.CREDENTIAL_PROGRAM, credData); ProgramRegistry.setData(variationData); ProgramRegistry.setRow(row); } row++; } } HistoryManager.navigate(AppLocations.Locations.VIEW_VARIATION.getLocation(), context); } } }
@Override public void onClick(ClickEvent event) { Value v = picker.getValue(); if (v instanceof DataValue) { Data d = ((DataValue) picker.getValue()).get(); Iterator<Property> iter = d.realPropertyIterator(); while (iter.hasNext()) { Property p = iter.next(); String s = p.getValue(); KSItemLabel selectedItem = createItem(s, picker.getDisplayValue(), hasDetails); addItem(selectedItem); } } else { String s = v.get(); KSItemLabel selectedItem = createItem(s, picker.getDisplayValue(), hasDetails); addItem(selectedItem); } picker.clear(); addItemButton.setEnabled(false); } });
/** * Handles after save work for specializations. */ private void handleSpecializations() { String newVariationId = null; Data variations = programModel.get(ProgramConstants.VARIATIONS); for (Data.Property prop : variations) { String varId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID); if (!existingVariationIds.contains(varId)) { newVariationId = varId; existingVariationIds.add(newVariationId); break; } } if (newVariationId != null) { eventBus.fireEvent(new SpecializationCreatedEvent(newVariationId)); } else { eventBus.fireEvent(new SpecializationUpdateEvent(variations)); } }
@Override public void onEvent(ModelLoadedEvent event) { DataModel dataModel = event.getModel(); Data variationMap = dataModel.get(ProgramConstants.VARIATIONS); if (variationMap != null) { int row = 0; for (Data.Property property : variationMap) { final Data variationData = property.getValue(); if (variationData.get(ProgramConstants.ID).equals(currentId)) { programModel.setRoot(variationData); ProgramRegistry.setData(variationData); ProgramRegistry.setRow(row); setContentTitle(getProgramName()); row++; return; } } } } };
/** * Handles after save work for specializations. */ private void handleSpecializations() { String newVariationId = null; Data variations = programModel.get(ProgramConstants.VARIATIONS); for (Data.Property prop : variations) { String varId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID); if (!existingVariationIds.contains(varId)) { newVariationId = varId; existingVariationIds.add(newVariationId); break; } } if (newVariationId != null) { eventBus.fireEvent(new SpecializationCreatedEvent(newVariationId)); } else { eventBus.fireEvent(new SpecializationUpdateEvent(variations)); } }
@Override public void onEvent(SpecializationUpdateEvent event) { // update our model to the updated specialization // gotta find it first String currSpecializationId = programModel.getRoot().get(ProgramConstants.ID); for (Data.Property prop : event.getSpecializations()) { String specId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID); if (null != specId && specId.equals(currSpecializationId) && prop.getValueType().equals(Data.class)) { // found it programModel.setRoot((Data) prop.getValue()); showView(getCurrentViewEnum()); } } //update with any new warnings that exist on specialization showWarnings(); } });
@Override public void exec(Widget widget) { ((KSSelectItemWidgetAbstract)widget).clear(); if (value != null){ if (value instanceof String || value instanceof StringValue) { String itemId = (String)(value instanceof String ? value:((StringValue)value).get()); ((KSSelectItemWidgetAbstract)widget).selectItem(itemId); } else if (value instanceof Data || value instanceof DataValue) { Data data = (Data)(value instanceof Data ? value:((DataValue)value).get()); for (Iterator itr = data.iterator(); itr.hasNext();) { Property p = (Property) itr.next(); ((KSSelectItemWidgetAbstract)widget).selectItem((String) p.getValue()); } } } } };
public static Data getVersionData(Data data, String typeName, String id) { Data result = null; Data versions = getVersions(data); if (versions == null) { return null; } for (Data.Property p : versions) { Data v = p.getValue(); if (typeName.equals((String) v.get(VersionProperties.TYPENAME.getKey())) && (id == null || id.equals((String) v.get(VersionProperties.ID.getKey())))) { result = v; break; } } return result; }
@Override public void setWidgetValue(ListOfStringWidget widget, DataModel model, String path) { Data data = model.get(path); ArrayList<String> values = new ArrayList<String>(); if(data!=null){ Iterator<Property> iter = data.realPropertyIterator(); while(iter.hasNext()){ Property prop = iter.next(); String value = prop.getValue(); values.add(value); } } widget.setStringValues(values); }
private List<LoCategoryInfo> getCategoryList(LoDisplayInfoHelper loDisplayInfoHelper) { List<LoCategoryInfo> categoryInfos = new ArrayList<LoCategoryInfo>(); Data categoriesData = loDisplayInfoHelper.getCategoryInfoList(); if (null != categoriesData) { Iterator<Data.Property> itr = categoriesData.realPropertyIterator(); while (itr.hasNext()) { Data.Property catProp = itr.next(); Data catData = catProp.getValue(); LoCategoryInfo catInfo = CategoryDataUtil.toLoCategoryInfo(catData); categoryInfos.add(catInfo); } } return categoryInfos; }
@Override public void exec(Boolean result) { Data program = ((DataModel)model).getRoot().get(ProgramConstants.PROGRAM_REQUIREMENTS); Iterator<Data.Property> realPropertyIterator = program.realPropertyIterator(); ArrayList<String> programRequirementIds = new ArrayList<String>(); while(realPropertyIterator.hasNext()) { programRequirementIds.add((String)realPropertyIterator.next().getValue()); } retrieveStatementTypes(programRequirementIds, onReadyCallback); } });
@Override public void setWidgetValue(VerticalPanel verticalPanel, DataModel model, String path) { verticalPanel.clear(); final Data credentialPrograms = model.get(path); for (final Data.Property property : credentialPrograms) { verticalPanel.add(new KSLabel(property.<String>getValue())); } } }