use of org.jboss.hal.ballroom.EmptyState 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.EmptyState in project console by hal.
the class SecurityManagerView method createPermissionUI.
private void createPermissionUI(Permission permission) {
Metadata metadata = metadataRegistry.lookup(DEPLOYMENT_PERMISSIONS_TEMPLATE).forComplexAttribute(permission.resource);
Constraint constraint = Constraint.writable(DEPLOYMENT_PERMISSIONS_TEMPLATE, permission.resource);
EmptyState emptyState = new EmptyState.Builder(Ids.DEPLOYMENT_PERMISSIONS_EMPTY, Names.DEPLOYMENT_PERMISSIONS).description(resources.messages().noDeploymentPermissions()).primaryAction(resources.constants().add(), () -> presenter.addDeploymentPermissions(), constraint).build();
emptyState.element().classList.add(marginTopLarge);
emptyStates.put(permission, emptyState);
Table<ModelNode> table = new ModelNodeTable.Builder<>(Ids.build(permission.baseId, Ids.TABLE), metadata).button(resources.constants().add(), t -> presenter.addPermission(permission), constraint).button(resources.constants().remove(), t -> presenter.removePermission(permission, t.selectedRow().get(HAL_INDEX).asInt()), Scope.SELECTED, constraint).column(CLASS).build();
tables.put(permission, table);
registerAttachable(table);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(permission.baseId, Ids.FORM), metadata).onSave((f, changedValues) -> presenter.savePermission(permission, f.getModel().get(HAL_INDEX).asInt(), changedValues)).build();
forms.put(permission, form);
registerAttachable(form);
HTMLElement masterDetail;
HTMLElement section = section().add(emptyState).add(masterDetail = div().add(h(1).textContent(permission.type)).add(p().textContent(metadata.getDescription().getDescription())).add(table).add(form).element()).element();
masterDetails.put(permission, masterDetail);
navigation.addPrimary(Ids.build(permission.baseId, Ids.ITEM), permission.type, permission.icon, section);
}
Aggregations