use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class OtherSettingsPresenter method addNewItemTemplate.
void addNewItemTemplate(String ldapKeyStore) {
Metadata metadata = metadataRegistry.lookup(AddressTemplates.LDAP_KEY_STORE_TEMPLATE).forComplexAttribute(NEW_ITEM_TEMPLATE);
String id = Ids.build(Ids.ELYTRON_LDAP_KEY_STORE, NEW_ITEM_TEMPLATE, Ids.ADD);
Form<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).include(NEW_ITEM_PATH, NEW_ITEM_RDN, NEW_ITEM_ATTRIBUTES).customFormItem(NEW_ITEM_ATTRIBUTES, (attributeDescription) -> new MultiValueListItem(NEW_ITEM_ATTRIBUTES)).unsorted().addOnly().build();
String type = new LabelBuilder().label(NEW_ITEM_TEMPLATE);
new AddResourceDialog(resources.messages().addResourceTitle(type), form, (name, model) -> ca.add(ldapKeyStore, NEW_ITEM_TEMPLATE, Names.NEW_ITEM_TEMPLATE, AddressTemplates.LDAP_KEY_STORE_TEMPLATE, model, this::reloadLdapKeyStores)).show();
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class OtherSettingsPresenter method addServerSslSniContext.
// -------------------------------------------- server ssl sni context
void addServerSslSniContext() {
Metadata metadata = metadataRegistry.lookup(AddressTemplates.SERVER_SSL_SNI_CONTEXT_TEMPLATE);
String id = Ids.build(Ids.ELYTRON_SERVER_SSL_SNI_CONTEXT, Ids.ADD);
Form<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).unboundFormItem(new NameItem(), 0).unsorted().addOnly().build();
// "host-context-map" is not required in r-r-d for "add" operation
// but the resource fails to add without this parameter, see https://issues.jboss.org/browse/WFCORE-4223
form.getFormItem("host-context-map").setRequired(true);
String type = new LabelBuilder().label(SERVER_SSL_SNI_CONTEXT);
new AddResourceDialog(resources.messages().addResourceTitle(type), form, (name, model) -> {
crud.add(type, name, AddressTemplates.SERVER_SSL_SNI_CONTEXT_TEMPLATE, model, (name1, address) -> reload(SERVER_SSL_SNI_CONTEXT, nodes -> getView().updateResourceElement(SERVER_SSL_SNI_CONTEXT, nodes)));
}).show();
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class RealmsPresenter method resetKeyMapper.
void resetKeyMapper(String jdbcRealm, int pqIndex, String keyMapper, Form<ModelNode> form) {
String type = new LabelBuilder().label(keyMapper);
Metadata metadata = metadataRegistry.lookup(JDBC_REALM_TEMPLATE).forComplexAttribute(PRINCIPAL_QUERY).forComplexAttribute(keyMapper);
ca.reset(jdbcRealm, keyMapperAttribute(pqIndex, keyMapper), type, JDBC_REALM_TEMPLATE, metadata, form, new Form.FinishReset<ModelNode>(form) {
@Override
public void afterReset(Form<ModelNode> form) {
reloadJdbcRealms();
}
});
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class CredentialReference method form.
/**
* Creates a form for the {@code credential-reference} complex attribute of a resource. The form is setup as a singleton
* form to add, save, reset and remove the complex attribute.
*
* @param baseId base ID used for the generated form and add resource dialog
* @param metadata the metadata of the resource which contains the {@code credential-reference} attribute
* @param crName the name of the credential-reference complex attribute
* @param alternativeName the name of the alternative attribute
* @param alternativeValue the value of the alternative attribute
* @param address the fully qualified address of the resource used for the CRUD actions
* @param callback the callback executed after the {@code credential-reference} attributes has been added, saved, reset or
* removed
*/
public Form<ModelNode> form(String baseId, Metadata metadata, String crName, String alternativeName, Supplier<String> alternativeValue, Supplier<ResourceAddress> address, Callback callback) {
String credentialReferenceName = crName == null ? CREDENTIAL_REFERENCE : crName;
Metadata crMetadata = metadata.forComplexAttribute(credentialReferenceName);
EmptyState.Builder emptyStateBuilder = new EmptyState.Builder(Ids.build(baseId, credentialReferenceName, Ids.FORM, Ids.EMPTY), resources.constants().noResource());
if (crMetadata.getSecurityContext().isWritable()) {
emptyStateBuilder.primaryAction(resources.constants().add(), () -> {
if (alternativeName != null && alternativeValue != null && !Strings.isNullOrEmpty(alternativeValue.get())) {
String alternativeLabel = new LabelBuilder().label(alternativeName);
DialogFactory.showConfirmation(resources.messages().addResourceTitle(Names.CREDENTIAL_REFERENCE), resources.messages().credentialReferenceAddConfirmation(alternativeLabel), () -> setTimeout(o -> addCredentialReference(baseId, crMetadata, credentialReferenceName, alternativeName, address, callback), SHORT_TIMEOUT));
} else {
addCredentialReference(baseId, crMetadata, credentialReferenceName, null, address, callback);
}
}, Constraint.executable(metadata.getTemplate(), ADD)).description(resources.messages().noResource());
} else {
emptyStateBuilder.description(resources.constants().restricted());
}
EmptyState noCredentialReference = emptyStateBuilder.build();
ModelNodeForm.Builder<ModelNode> formBuilder = new ModelNodeForm.Builder<>(Ids.build(baseId, credentialReferenceName, Ids.FORM), crMetadata).include(STORE, ALIAS, CLEAR_TEXT, TYPE).unsorted().singleton(() -> {
ResourceAddress fqAddress = address.get();
Operation operation = null;
if (fqAddress != null && crMetadata.getSecurityContext().isReadable()) {
operation = new Operation.Builder(address.get(), READ_ATTRIBUTE_OPERATION).param(NAME, credentialReferenceName).build();
}
return operation;
}, noCredentialReference).onSave(((f, changedValues) -> {
ResourceAddress fqa = address.get();
if (fqa != null) {
if (changedValues.isEmpty()) {
MessageEvent.fire(eventBus, Message.warning(resources.messages().noChanges()));
callback.execute();
} else {
ca.save(credentialReferenceName, Names.CREDENTIAL_REFERENCE, fqa, f.getModel(), callback);
}
} else {
MessageEvent.fire(eventBus, Message.error(resources.messages().credentialReferenceAddressError()));
}
}));
// some credential-reference attributes are nillable=false, so only nillable=true may be removed
if (crMetadata.getDescription().get(NILLABLE).asBoolean()) {
formBuilder.prepareRemove(f -> {
ResourceAddress fqAddress = address.get();
if (fqAddress != null) {
ca.remove(credentialReferenceName, Names.CREDENTIAL_REFERENCE, fqAddress, new Form.FinishRemove<ModelNode>(f) {
@Override
public void afterRemove(Form<ModelNode> form) {
callback.execute();
}
});
} else {
MessageEvent.fire(eventBus, Message.error(resources.messages().credentialReferenceAddressError()));
}
});
}
Form<ModelNode> form = formBuilder.build();
form.addFormValidation(new CrFormValidation(alternativeName, alternativeValue, resources));
form.addFormValidation(new CrFormValuesValidation(resources));
return form;
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class FormProcessor method process.
@Override
public void process(VariableElement field, Element element, String selector, MbuiViewContext context) {
String title = element.getAttributeValue(XmlTags.TITLE);
boolean autoSave = Boolean.parseBoolean(element.getAttributeValue(XmlTags.AUTO_SAVE));
String addHandler = element.getAttributeValue(XmlTags.ADD_HANDLER);
boolean reset = Boolean.parseBoolean(element.getAttributeValue(XmlTags.RESET));
boolean includeRuntime = Boolean.parseBoolean(element.getAttributeValue(XmlTags.INCLUDE_RUNTIME));
boolean singleton = XmlTags.SINGLETON_FORM.equalsIgnoreCase(element.getName());
String onSave = element.getAttributeValue(XmlTags.ON_SAVE);
String prepareReset = element.getAttributeValue(XmlTags.PREPARE_RESET);
String nameResolver = element.getAttributeValue(XmlTags.NAME_RESOLVER);
MetadataInfo metadata = findMetadata(field, element, context);
AddressTemplate template = AddressTemplate.of(metadata.getTemplate());
if (autoSave && !Strings.isNullOrEmpty(onSave)) {
processor.error(field, "Please choose either auto-save or on-save not both.");
} else if (autoSave) {
if (title == null) {
title = new LabelBuilder().label(template.lastName());
}
if (nameResolver != null && !ExpressionParser.isExpression(nameResolver)) {
processor.error(field, "Name resolver in form#%s has to be an expression.", selector);
}
if ("*".equals(template.lastValue()) && nameResolver == null) {
processor.error(field, "Auto save is enabled for form#%s and related metadata address ends in \"*\", " + "but no name resolver is is provided.", selector);
}
} else if (!Strings.isNullOrEmpty(onSave)) {
if (!ExpressionParser.isExpression(onSave)) {
processor.error(field, "on-save handler in form#%s has to be an expression.", selector);
}
}
FormInfo formInfo = new FormInfo(field.getSimpleName().toString(), selector, getTypeParameter(field), metadata, title, addHandler, autoSave, onSave, reset, prepareReset, nameResolver, includeRuntime, singleton);
context.addFormInfo(formInfo);
org.jdom2.Element attributesContainer = element.getChild(XmlTags.ATTRIBUTES);
if (attributesContainer != null) {
List<Element> groupElements = attributesContainer.getChildren(XmlTags.GROUP);
if (groupElements.isEmpty()) {
processAttributes(field, attributesContainer).forEach(formInfo::addAttribute);
} else {
Map<String, Element> excludes = new HashMap<>();
Map<String, FormInfo.Group> groupsById = new HashMap<>();
// round one: process groups
for (Element groupElement : groupElements) {
String id = groupElement.getAttributeValue(XmlTags.ID);
String name = groupElement.getAttributeValue(XmlTags.NAME);
String groupTitle = groupElement.getAttributeValue(XmlTags.TITLE);
FormInfo.Group group = new FormInfo.Group(id, name, groupTitle);
groupElement.getChildren(XmlTags.ATTRIBUTE).forEach(attributeElement -> group.addAttribute(processAttribute(field, attributeElement)));
formInfo.addGroup(group);
if (id != null) {
groupsById.put(id, group);
}
Element excludeElement = groupElement.getChild(XmlTags.EXCLUDE);
if (id != null && excludeElement != null) {
excludes.put(id, excludeElement);
}
}
// round two: process group excludes (which might reference other groups)
excludes.forEach((id, excludeElement) -> {
FormInfo.Group group = groupsById.get(id);
if (group != null) {
excludeElement.getChildren(XmlTags.ATTRIBUTE).forEach(attributeElement -> {
String name = attributeElement.getAttributeValue(XmlTags.NAME);
if (name != null) {
group.exclude(name);
}
});
excludeElement.getChildren(XmlTags.GROUP).forEach(groupElement -> {
String excludedGroupId = groupElement.getAttributeValue(XmlTags.ID);
if (excludedGroupId != null && groupsById.get(excludedGroupId) != null) {
FormInfo.Group excludedGroup = groupsById.get(excludedGroupId);
group.exclude(excludedGroup);
}
});
}
});
}
}
}
Aggregations