use of org.jboss.hal.ballroom.form.FormItem in project console by hal.
the class ModelNodeMapping method populateFormItems.
@Override
@SuppressWarnings("unchecked")
public void populateFormItems(T model, Form<T> form) {
String id = id(form);
for (FormItem formItem : form.getBoundFormItems()) {
formItem.clearError();
String name = formItem.getName();
if (model.hasDefined(name)) {
ModelNode attributeDescription = findAttribute(name);
if (attributeDescription == null) {
logger.error("{}: Unable to populate form item '{}': No attribute description found in\n{}", id, name, attributeDescriptions);
continue;
}
ModelNode value = model.get(name);
ModelType valueType = value.getType();
if (valueType == EXPRESSION) {
if (formItem.supportsExpressions()) {
formItem.setExpressionValue(value.asString());
formItem.setUndefined(false);
} else {
logger.error("{}: Unable to populate form item '{}': Value is an expression, but form item does not support expressions", id, name);
continue;
}
} else if (formItem instanceof ModelNodeItem) {
formItem.setValue(value);
} else {
populateFormItem(id, name, attributeDescription, value, formItem);
}
formItem.setUndefined(false);
} else {
formItem.clearValue();
formItem.setUndefined(true);
}
}
}
use of org.jboss.hal.ballroom.form.FormItem in project console by hal.
the class DriverStep method assignFromJdbcDriverOrTemplate.
@SuppressWarnings("unchecked")
private void assignFromJdbcDriverOrTemplate(String driverName, String propName) {
FormItem formItem = form.getFormItem(propName);
if (formItem != null) {
JdbcDriver driver = driversByName.get(driverName);
DataSourceTemplate template = this.wizard().getContext().template;
if (driver != null && driver.hasDefined(propName) && !driver.get(propName).asString().isEmpty()) {
// assign the value inside the driver
formItem.setModified(true);
formItem.setValue(driver.get(propName).asString());
} else if (template != null && template.getDriver() != null && template.getDriver().hasDefined(propName) && !template.getDriver().get(propName).asString().isEmpty()) {
// assign the value in the template
formItem.setModified(true);
formItem.setValue(this.wizard().getContext().template.getDriver().get(propName).asString());
}
// let the current value at it is now
}
}
use of org.jboss.hal.ballroom.form.FormItem in project console by hal.
the class OtherSettingsPresenter method addCredentialStore.
// -------------------------------------------- Credential Store
void addCredentialStore() {
Metadata metadata = metadataRegistry.lookup(CREDENTIAL_STORE_TEMPLATE);
SafeHtml typeHelp = SafeHtmlUtils.fromString(metadata.getDescription().get(ATTRIBUTES).get(TYPE).get(DESCRIPTION).asString());
Metadata crMetadata = metadata.forComplexAttribute(CREDENTIAL_REFERENCE, true);
crMetadata.copyComplexAttributeAttributes(asList(STORE, ALIAS, TYPE, CLEAR_TEXT), metadata);
TextBoxItem typeItem = new TextBoxItem("type-", resources.constants().type());
String id = Ids.build(Ids.ELYTRON_CREDENTIAL_STORE, Ids.ADD);
NameItem nameItem = new NameItem();
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).addOnly().unboundFormItem(nameItem, 0).include(CREATE, PATH, RELATIVE_TO, STORE, ALIAS, TYPE, CLEAR_TEXT).unboundFormItem(typeItem, 3, typeHelp).unsorted().build();
form.getFormItem(RELATIVE_TO).registerSuggestHandler(new PathsAutoComplete());
form.addFormValidation(new RequireAtLeastOneAttributeValidation<>(asList(STORE, CLEAR_TEXT), resources));
form.addFormValidation(form1 -> {
ValidationResult result = ValidationResult.OK;
String typeValue = typeItem.getValue();
FormItem<String> locationAttr = form1.getFormItem(PATH);
boolean invalidLocation = locationAttr.isEmpty() && (typeItem.isEmpty() || Collections.binarySearch(FILE_BASED_CS, typeValue) > -1);
if (invalidLocation) {
form1.getFormItem(PATH).showError(resources.constants().requiredField());
result = ValidationResult.invalid(resources.messages().pathRequired());
}
return result;
});
new AddResourceDialog(resources.messages().addResourceTitle(Names.CREDENTIAL_STORE), form, (name, model) -> {
if (model != null) {
move(model, STORE, CREDENTIAL_REFERENCE + "/" + STORE);
move(model, ALIAS, CREDENTIAL_REFERENCE + "/" + ALIAS);
move(model, TYPE, CREDENTIAL_REFERENCE + "/" + TYPE);
move(model, CLEAR_TEXT, CREDENTIAL_REFERENCE + "/" + CLEAR_TEXT);
}
if (!typeItem.isEmpty()) {
model.get(TYPE).set(typeItem.getValue());
}
ResourceAddress address = CREDENTIAL_STORE_TEMPLATE.resolve(statementContext, nameItem.getValue());
crud.add(Names.CREDENTIAL_STORE, name, address, model, (n, a) -> reload(CREDENTIAL_STORE, nodes -> getView().updateResourceElement(CREDENTIAL_STORE, nodes)));
}).show();
}
use of org.jboss.hal.ballroom.form.FormItem in project console by hal.
the class JmsQueuePresenter method changePriority.
void changePriority(List<JmsMessage> messages) {
if (messages.isEmpty()) {
noMessagesSelected();
} else {
Metadata metadata = metadataRegistry.lookup(MESSAGING_CORE_QUEUE_TEMPLATE);
Form<ModelNode> form = new OperationFormBuilder<>(Ids.JMS_MESSAGE_CHANGE_PRIORITY_FORM, metadata, CHANGE_MESSAGE_PRIORITY).build();
Dialog dialog = new Dialog.Builder(resources.constants().changePriority()).add(form.element()).cancel().primary(resources.constants().ok(), () -> {
boolean valid = form.save();
if (valid) {
Operation operation;
int priority = form.getModel().get(NEW_PRIORITY).asInt();
if (messages.size() == 1) {
operation = new Operation.Builder(queueAddress(), CHANGE_MESSAGE_PRIORITY).param(MESSAGE_ID, messages.get(0).getMessageId()).param(NEW_PRIORITY, priority).build();
} else {
operation = new Operation.Builder(queueAddress(), CHANGE_MESSAGES_PRIORITY).param(FILTER, filter(messages)).param(NEW_PRIORITY, priority).build();
}
dispatcher.execute(operation, result -> {
reload();
MessageEvent.fire(getEventBus(), Message.success(resources.messages().changePrioritySuccess(priority)));
});
}
return valid;
}).build();
dialog.registerAttachable(form);
dialog.show();
ModelNode model = new ModelNode();
form.edit(model);
FormItem<Number> messageId = form.getFormItem(MESSAGE_ID);
messageId.setValue(42L);
Elements.setVisible(messageId.element(Form.State.EDITING), false);
FormItem<Number> priorityItem = form.getFormItem(NEW_PRIORITY);
if (messages.size() == 1) {
priorityItem.setValue(messages.get(0).get(JMS_PRIORITY).asLong());
}
priorityItem.setFocus(true);
}
}
use of org.jboss.hal.ballroom.form.FormItem in project console by hal.
the class JmsQueuePresenter method move.
void move(List<JmsMessage> messages) {
if (messages.isEmpty()) {
noMessagesSelected();
} else {
Metadata metadata = metadataRegistry.lookup(MESSAGING_CORE_QUEUE_TEMPLATE);
Form<ModelNode> form = new OperationFormBuilder<>(Ids.JMS_MESSAGE_MOVE_FORM, metadata, MOVE_MESSAGE).build();
Dialog dialog = new Dialog.Builder(resources.constants().move()).add(form.element()).cancel().primary(resources.constants().ok(), () -> {
boolean valid = form.save();
if (valid) {
Operation operation;
String destination = form.getModel().get(OTHER_QUEUE_NAME).asString();
boolean rejectDuplicates = failSafeBoolean(form.getModel(), REJECT_DUPLICATES);
if (messages.size() == 1) {
operation = new Operation.Builder(queueAddress(), MOVE_MESSAGE).param(MESSAGE_ID, messages.get(0).getMessageId()).param(OTHER_QUEUE_NAME, destination).param(REJECT_DUPLICATES, rejectDuplicates).build();
} else {
operation = new Operation.Builder(queueAddress(), MOVE_MESSAGES).param(FILTER, filter(messages)).param(OTHER_QUEUE_NAME, destination).param(REJECT_DUPLICATES, rejectDuplicates).build();
}
dispatcher.execute(operation, result -> {
reload();
MessageEvent.fire(getEventBus(), Message.success(resources.messages().moveMessageSuccess(destination)));
});
}
return valid;
}).build();
dialog.registerAttachable(form);
dialog.show();
ModelNode model = new ModelNode();
form.edit(model);
FormItem<Number> messageId = form.getFormItem(MESSAGE_ID);
messageId.setValue(42L);
Elements.setVisible(messageId.element(Form.State.EDITING), false);
form.getFormItem(OTHER_QUEUE_NAME).setFocus(true);
}
}
Aggregations