/** * @param selection a splittable which this function assumes is a list of {@link SelectionItem}s */ public void setSelection(Splittable selection) { selectionItemsEditor.setSuppressEvent(true); AppTemplateAutoBeanFactory factory = GWT.create(AppTemplateAutoBeanFactory.class); SelectionItemList siList = AutoBeanCodex.decode( factory, SelectionItemList.class, "{\"selectionItems\": " + selection.getPayload() + "}") .as(); List<SelectionItem> items = siList.getSelectionItems(); tree.setSelection(items); selectionItemsEditor.setSuppressEvent(false); }
@Override public void setValue(Argument value) { if ((value == null) || !value.getType().equals(ArgumentType.TreeSelection)) { return; } List<SelectionItem> toBeRemoved = AutoBeanUtils.getAutoBean(value).getTag(SelectionItem.TO_BE_REMOVED); if (toBeRemoved != null) { selectionItemsEditor.setSuppressEvent(true); for (SelectionItem si : toBeRemoved) { tree.getStore().remove(si); } selectionItemsEditor.setSuppressEvent(false); } AutoBeanUtils.getAutoBean(value).setTag(SelectionItem.TO_BE_REMOVED, null); this.model = value; boolean restoreSelectionsFromDefaultValue = (value.getDefaultValue() != null) && (value.getDefaultValue().isIndexed()) && (value.getDefaultValue().size() > 0); tree.setRestoreCheckedSelectionFromTree(!restoreSelectionsFromDefaultValue); selectionItemsEditor.setValue(value.getSelectionItems()); if (restoreSelectionsFromDefaultValue) { /* * JDS If we're not in editing mode, and there is a list of items in the defaultValue field. * This should only happen when an app is being re-launched from the Analysis window, and * there were values selected for the Tree. */ Splittable defValCopy = value.getDefaultValue().deepCopy(); setSelection(defValCopy); /* * JDS Clear default value so future selections can be made (since they are made through * value.getSelectionItems() and not value.defaultValue() */ value.setDefaultValue(null); } }