use of org.jboss.hal.core.mbui.form.ModelNodeForm in project console by hal.
the class JGroupsPresenter method addStack.
// stack resources
@SuppressWarnings("ConstantConditions")
void addStack() {
Metadata metadata = metadataRegistry.lookup(STACK_TEMPLATE);
Metadata transportMetadata = metadataRegistry.lookup(TRANSPORT_TEMPLATE).forOperation(ADD);
transportMetadata.copyAttribute(SOCKET_BINDING, metadata);
metadata.makeWritable(SOCKET_BINDING);
NameItem nameItem = new NameItem();
String transportLabel = new LabelBuilder().label(TRANSPORT);
TextBoxItem transportItem = new TextBoxItem(TRANSPORT, transportLabel);
transportItem.setRequired(true);
String id = Ids.build(Ids.JGROUPS_STACK_CONFIG, Ids.ADD);
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).unboundFormItem(nameItem, 0).unboundFormItem(transportItem, 2).unsorted().requiredOnly().build();
AddResourceDialog dialog = new AddResourceDialog(Names.STACK, form, (name, model) -> {
ResourceAddress stackAddress = STACK_TEMPLATE.resolve(filterStatementContext, name);
String transport = transportItem.getValue();
ResourceAddress transportAddress = TRANSPORT_TEMPLATE.resolve(filterStatementContext, name, transport);
Operation addStackOperation = new Operation.Builder(stackAddress, ADD).build();
Operation addTransportOperation = new Operation.Builder(transportAddress, ADD).payload(model).build();
Composite composite = new Composite(addStackOperation, addTransportOperation);
dispatcher.execute(composite, (CompositeResult result) -> {
MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(Names.STACK, name)));
reload();
});
});
dialog.show();
}
use of org.jboss.hal.core.mbui.form.ModelNodeForm in project console by hal.
the class ServerActions method copyServer.
// ------------------------------------------------------ server operations
public void copyServer(Server server, Callback callback) {
Operation operation = new Operation.Builder(ResourceAddress.root(), READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, HOST).build();
dispatcher.execute(operation, result -> {
List<String> hosts = new ArrayList<>();
result.asList().forEach(m -> hosts.add(m.asString()));
// get the first host only to retrieve the r-r-d for server-config
// as /host=*/server-config=*:read-operation-description(name=add) does not work
AddressTemplate template = AddressTemplate.of("/host=" + hosts.get(0) + "/server-config=*");
metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {
@Override
public void onMetadata(Metadata metadata) {
String id = Ids.build(SERVER_GROUP, statementContext.selectedServerGroup(), SERVER, FORM);
SingleSelectBoxItem hostFormItem = new SingleSelectBoxItem(HOST, Names.HOST, hosts, false);
hostFormItem.setRequired(true);
NameItem nameItem = new NameItem();
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).fromRequestProperties().unboundFormItem(nameItem, 0).unboundFormItem(hostFormItem, 1, resources.messages().addServerHostHelp()).exclude(AUTO_START, SOCKET_BINDING_DEFAULT_INTERFACE, SOCKET_BINDING_GROUP, UPDATE_AUTO_START_WITH_SERVER_STATUS).build();
AddResourceDialog dialog = new AddResourceDialog(resources.messages().copyServerTitle(), form, (resource, payload) -> {
// read server-config recursively to retrieve nested resources
ModelNode serverConfigModel = new ModelNode();
serverConfigModel.get(HOST).set(server.getHost());
serverConfigModel.get(SERVER_CONFIG).set(server.getName());
ResourceAddress serverAddress = new ResourceAddress(serverConfigModel);
Operation opReadServer = new Operation.Builder(serverAddress, READ_RESOURCE_OPERATION).param(RECURSIVE, true).build();
dispatcher.execute(opReadServer, new Consumer<ModelNode>() {
@Override
public void accept(ModelNode newServerModel) {
String newServerName = nameItem.getValue();
// set the chosen group in the model
newServerModel.get(GROUP).set(payload.get(GROUP).asString());
if (payload.hasDefined(SOCKET_BINDING_PORT_OFFSET)) {
newServerModel.get(SOCKET_BINDING_PORT_OFFSET).set(payload.get(SOCKET_BINDING_PORT_OFFSET).asLong());
}
newServerModel.get(NAME).set(newServerName);
ModelNode newServerModelAddress = new ModelNode();
newServerModelAddress.get(HOST).set(hostFormItem.getValue());
newServerModelAddress.get(SERVER_CONFIG).set(newServerName);
Operation opAddServer = new Operation.Builder(new ResourceAddress(newServerModelAddress), ADD).payload(newServerModel).build();
Composite comp = new Composite();
comp.add(opAddServer);
// create operation for each nested resource of the source server
createOperation(comp, JVM, newServerModel, newServerModelAddress);
createOperation(comp, INTERFACE, newServerModel, newServerModelAddress);
createOperation(comp, PATH, newServerModel, newServerModelAddress);
createOperation(comp, SYSTEM_PROPERTY, newServerModel, newServerModelAddress);
createOperation(comp, SSL, newServerModel, newServerModelAddress);
dispatcher.execute(comp, (CompositeResult result) -> {
MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(Names.SERVER, newServerName)));
callback.execute();
}, (operation1, failure) -> {
MessageEvent.fire(eventBus, Message.error(resources.messages().addResourceError(newServerName, failure)));
callback.execute();
}, (operation1, exception) -> {
MessageEvent.fire(eventBus, Message.error(resources.messages().addResourceError(newServerName, exception.getMessage())));
callback.execute();
});
}
private void createOperation(Composite composite, String resource, ModelNode model, ModelNode baseAddress) {
if (model.hasDefined(resource)) {
List<Property> props = model.get(resource).asPropertyList();
props.forEach(p -> {
String propname = p.getName();
ModelNode _address = baseAddress.clone();
_address.get(resource).set(propname);
Operation operation = new Operation.Builder(new ResourceAddress(_address), ADD).payload(p.getValue()).build();
composite.add(operation);
});
}
}
});
});
dialog.show();
}
});
});
}
use of org.jboss.hal.core.mbui.form.ModelNodeForm in project console by hal.
the class OtherSettingsPresenter method addSecurityDomain.
// -------------------------------------------- Security Domain
void addSecurityDomain() {
Metadata metadata = metadataRegistry.lookup(SECURITY_DOMAIN_TEMPLATE);
// emulate capability-reference on default-realm
String capabilityReference = metadata.getDescription().findAttribute(ATTRIBUTES + "/" + REALMS + "/" + VALUE_TYPE, REALM).getValue().get(CAPABILITY_REFERENCE).asString();
String id = Ids.build(Ids.ELYTRON_SECURITY_DOMAIN, Ids.ADD);
NameItem nameItem = new NameItem();
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).addOnly().unboundFormItem(nameItem, 0).include(DEFAULT_REALM).unsorted().build();
form.getFormItem(DEFAULT_REALM).setRequired(true);
form.getFormItem(DEFAULT_REALM).registerSuggestHandler(new SuggestCapabilitiesAutoComplete(dispatcher, statementContext, capabilityReference, metadata.getTemplate()));
new AddResourceDialog(resources.messages().addResourceTitle(Names.SECURITY_DOMAIN), form, (name, model) -> {
if (model != null) {
// add the default-realm in the list of realms
ModelNode realm = new ModelNode();
realm.get(REALM).set(model.get(DEFAULT_REALM).asString());
model.get(REALMS).add(realm);
}
ResourceAddress address = SECURITY_DOMAIN_TEMPLATE.resolve(statementContext, nameItem.getValue());
crud.add(Names.SECURITY_DOMAIN, name, address, model, (n, a) -> reload(SECURITY_DOMAIN, nodes -> getView().updateResourceElement(SECURITY_DOMAIN, nodes)));
}).show();
}
use of org.jboss.hal.core.mbui.form.ModelNodeForm in project console by hal.
the class OtherSettingsPresenter method addKeyManager.
// ------------------------------------------------------ key manager
void addKeyManager() {
Metadata metadata = metadataRegistry.lookup(KEY_MANAGER_TEMPLATE);
Metadata crMetadata = metadata.forComplexAttribute(CREDENTIAL_REFERENCE, true);
crMetadata.copyComplexAttributeAttributes(asList(STORE, ALIAS, TYPE, CLEAR_TEXT), metadata);
String id = Ids.build(Ids.ELYTRON_KEY_MANAGER, Ids.ADD);
NameItem nameItem = new NameItem();
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).addOnly().unboundFormItem(nameItem, 0).include(STORE, ALIAS, TYPE, CLEAR_TEXT).unsorted().build();
form.addFormValidation(new RequireAtLeastOneAttributeValidation<>(asList(STORE, CLEAR_TEXT), resources));
new AddResourceDialog(resources.messages().addResourceTitle(Names.KEY_MANAGER), 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);
}
ResourceAddress address = KEY_MANAGER_TEMPLATE.resolve(statementContext, nameItem.getValue());
crud.add(Names.KEY_MANAGER, name, address, model, (n, a) -> reload(KEY_MANAGER, nodes -> getView().updateResourceElement(KEY_MANAGER, nodes)));
}).show();
}
use of org.jboss.hal.core.mbui.form.ModelNodeForm in project console by hal.
the class ResourcePanel method update.
void update(Node<Context> node, ResourceAddress address, Metadata metadata) {
SafeHtml safeHtml = SafeHtmlUtils.fromSafeConstant(metadata.getDescription().getDescription());
Elements.innerHtml(this.description, safeHtml);
tabs.setContent(dataId, PLACE_HOLDER_ELEMENT);
tabs.setContent(attributesId, PLACE_HOLDER_ELEMENT);
tabs.setContent(operationsId, PLACE_HOLDER_ELEMENT);
Elements.setVisible(tabs.element(), description.hasAttributes());
Elements.setVisible(empty, !description.hasAttributes());
if (description.hasAttributes()) {
Operation operation = new Operation.Builder(address, READ_RESOURCE_OPERATION).param(INCLUDE_RUNTIME, true).build();
dispatcher.execute(operation, result -> {
List<String> plainObjects = new ArrayList<>();
flattenDescription(metadata.getDescription().get(ATTRIBUTES), plainObjects);
flattenModel(result, plainObjects);
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(Ids.MODEL_BROWSER, node.id, Ids.FORM), metadata).includeRuntime().showDeprecated().onSave((f, changedValues) -> modelBrowser.save(address, changedValues, metadata)).prepareReset(f -> modelBrowser.reset(address, f, metadata)).build();
tabs.setContent(dataId, form.element());
PatternFly.initComponents();
form.attach();
form.view(result);
});
tabs.setContent(attributesId, new AttributesTable(metadata.getDescription().getAttributes(ATTRIBUTES), resources).element());
if (!metadata.getDescription().getOperations().isEmpty()) {
tabs.setContent(operationsId, new OperationsTable(metadata.getDescription().getOperations(), resources).element());
}
}
}
Aggregations