@Override public String getContributionId(WidgetDefinition contrib) { return contrib.getName(); }
@Override public WidgetDefinition getWidgetDefinition(WidgetDefinition widgetDef, LayoutConversionContext ctx) { String wType = widgetDef.getType(); if (isDirectoryWidget(wType)) { String dirName = (String) widgetDef.getProperties(BuiltinModes.ANY, BuiltinModes.ANY).get(DIR_NAME_PROPERTY); if (dirName == null) { dirName = (String) widgetDef.getProperties(BuiltinModes.ANY, BuiltinWidgetModes.EDIT).get( DIR_NAME_PROPERTY); } if (dirName == null) { dirName = (String) widgetDef.getProperties(BuiltinModes.ANY, BuiltinWidgetModes.VIEW).get( DIR_NAME_PROPERTY); } if (dirName != null) { WidgetDefinition clone = getClonedWidget(widgetDef); // change select options on new widget WidgetSelectOption[] selectOptions = VocabularyHelper.getVocabularySelectOptions(dirName, ctx.getLanguage()).toArray(new WidgetSelectOption[] {}); clone.setSelectOptions(selectOptions); return clone; } } return widgetDef; } }
@Override public WidgetDefinition getWidgetDefinition(WidgetDefinition orig, LayoutConversionContext ctx) { String lang = ctx.getLanguage(); if (orig.isTranslated() && lang != null) { // translate widget labels WidgetDefinition clone = getClonedWidget(orig); Map<String, String> labels = TranslationHelper.getTranslatedLabels(clone.getLabels(), lang); Map<String, String> helpLabels = TranslationHelper.getTranslatedLabels(clone.getHelpLabels(), lang); clone.setLabels(labels); clone.setHelpLabels(helpLabels); return clone; } return orig; } }
builder.append(widgetDef.getName()).append(";"); builder.append(widgetDef.getType()).append(";"); builder.append(widgetDef.getTypeCategory()).append(";"); FieldDefinition[] fieldDefinitions = widgetDef.getFieldDefinitions(); if (fieldDefinitions != null) { for (FieldDefinition fieldDef : fieldDefinitions) { Map<String, String> labels = widgetDef.getLabels(); if (labels != null) { builder.append(labels.toString()); Map<String, String> helpLabels = widgetDef.getHelpLabels(); if (helpLabels != null) { builder.append(helpLabels.toString()); WidgetDefinition[] subWidgets = widgetDef.getSubWidgetDefinitions(); if (subWidgets != null) { for (WidgetDefinition widget : subWidgets) { WidgetReference[] subWidgetRefs = widgetDef.getSubWidgetReferences(); if (subWidgetRefs != null) { for (WidgetReference widget : subWidgetRefs) { Map<String, Map<String, Serializable>> properties = widgetDef.getProperties(); if (properties != null) { builder.append(properties.toString()); Map<String, Map<String, Serializable>> widgetModeProperties = widgetDef.getWidgetModeProperties();
@Override public WidgetDefinition getWidgetDefinition(WidgetDefinition widgetDef, LayoutConversionContext ctx) { String wType = widgetDef.getType(); String wName = widgetDef.getName(); if (getAcceptedWidgetNames().contains(wName) && isAccepted(wType)) { WidgetDefinition clone = getClonedWidget(widgetDef); // change select options on new widget WidgetSelectOption[] selectOptions = VocabularyHelper.getChainSelectVocabularySelectOptions( getParentDirectoryName(), getChildDirectoryName(), ctx.getLanguage()).toArray( new WidgetSelectOption[] {}); clone.setSelectOptions(selectOptions); return clone; } return widgetDef; } }
protected WidgetDefinition lookupWidget(LayoutDefinition layoutDef, WidgetReference widgetRef) { String widgetName = widgetRef.getName(); WidgetDefinition wDef = null; if (layoutDef != null) { wDef = layoutDef.getWidgetDefinition(widgetName); if (wDef != null && wDef.getType() == null) { // consider it's a reference for a global widget wDef = null; } } if (wDef == null) { // try in global registry wDef = lookupWidget(widgetRef); } return wDef; }
@Override // overridden to handle aliases public synchronized void addContribution(WidgetDefinition contrib) { super.addContribution(contrib); List<String> aliases = contrib.getAliases(); if (aliases != null) { for (String alias : aliases) { FragmentList<WidgetDefinition> head = addFragment(alias, contrib); contributionUpdated(alias, head.merge(this), contrib); } } }
@Override public void write(WidgetDefinition entity, JsonGenerator jg) throws IOException { jg.writeStartObject(); jg.writeStringField("name", entity.getName()); jg.writeStringField("type", entity.getType()); String typeCategory = entity.getTypeCategory(); if (StringUtils.isNotBlank(typeCategory)) { jg.writeStringField("typeCategory", typeCategory); Map<String, String> labels = entity.getLabels(); if (MapUtils.isNotEmpty(labels)) { writeSerializableMapField("labels", new TreeMap<>(labels), jg); Map<String, String> helpLabels = entity.getHelpLabels(); if (MapUtils.isNotEmpty(helpLabels)) { writeSerializableMapField("helpLabels", new TreeMap<>(helpLabels), jg); jg.writeBooleanField("translated", entity.isTranslated()); jg.writeBooleanField("handlingLabels", entity.isHandlingLabels()); Map<String, String> widgetModes = entity.getModes(); if (MapUtils.isNotEmpty(widgetModes)) { writeSerializableMapField("widgetModes", new TreeMap<>(widgetModes), jg); FieldDefinition[] fieldDefinitions = entity.getFieldDefinitions(); if (ArrayUtils.isNotEmpty(fieldDefinitions)) { jg.writeArrayFieldStart("fields"); WidgetDefinition[] subWidgetDefinitions = entity.getSubWidgetDefinitions(); if (ArrayUtils.isNotEmpty(subWidgetDefinitions)) {
@Override // overridden to handle aliases public synchronized void removeContribution(WidgetDefinition contrib, boolean useEqualsMethod) { super.removeContribution(contrib, useEqualsMethod); List<String> aliases = contrib.getAliases(); if (aliases != null) { for (String alias : aliases) { FragmentList<WidgetDefinition> head = removeFragment(alias, contrib, useEqualsMethod); if (head != null) { WidgetDefinition result = head.merge(this); if (result != null) { contributionUpdated(alias, result, contrib); } else { contributionRemoved(alias, contrib); } } } } }
public LayoutDefinitionImpl(String name, Map<String, Map<String, Serializable>> properties, Map<String, String> templates, List<LayoutRowDefinition> rows, List<WidgetDefinition> widgetDefinitions) { super(); this.name = name; this.properties = properties; this.templates = templates; if (rows == null) { this.rows = new LayoutRowDefinition[0]; } else { this.rows = rows.toArray(new LayoutRowDefinition[0]); } this.widgets = new HashMap<String, WidgetDefinition>(); if (widgetDefinitions != null) { for (WidgetDefinition widgetDef : widgetDefinitions) { this.widgets.put(widgetDef.getName(), widgetDef); } } }
public void unregisterWidget(String category, WidgetDefinition widgetDef) { WidgetDefinitionRegistry reg = widgetsByCat.get(category); if (reg != null) { reg.removeContribution(widgetDef); log.info(String.format("Unregistered widget '%s' for category '%s' ", widgetDef.getName(), category)); } }
public LayoutDefinitionImpl(String name, String template, WidgetDefinition widgetDefinition) { super(); this.name = name; this.properties = null; this.templates = new HashMap<String, String>(); if (template != null) { this.templates.put(BuiltinModes.ANY, template); } this.widgets = new HashMap<String, WidgetDefinition>(); if (widgetDefinition != null) { this.widgets.put(widgetDefinition.getName(), widgetDefinition); this.rows = new LayoutRowDefinition[] { new LayoutRowDefinitionImpl(null, widgetDefinition.getName()) }; } else { this.rows = new LayoutRowDefinition[0]; } }
public void registerWidget(String category, WidgetDefinition widgetDef) { WidgetDefinitionRegistry reg = widgetsByCat.get(category); if (reg == null) { reg = new WidgetDefinitionRegistry(category); widgetsByCat.put(category, reg); } reg.addContribution(widgetDef); log.info(String.format("Registered widget '%s' for category '%s' ", widgetDef.getName(), category)); }