use of org.jboss.hal.core.mbui.dialog.NameItem in project console by hal.
the class ServerPresenter method addFilterRef.
void addFilterRef() {
Metadata metadata = metadataRegistry.lookup(FILTER_REF_TEMPLATE);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.UNDERTOW_HOST_FILTER_REF_ADD, metadata).unboundFormItem(new NameItem(), 0).fromRequestProperties().build();
form.getFormItem(NAME).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, FILTER_SUGGESTIONS));
AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(resources.constants().filter()), form, (name, model) -> {
ResourceAddress address = SELECTED_HOST_TEMPLATE.append(FILTER_REF + EQUALS + name).resolve(statementContext);
crud.add(resources.constants().filter(), name, address, model, (n, a) -> reloadFilterRef());
});
dialog.show();
}
use of org.jboss.hal.core.mbui.dialog.NameItem in project console by hal.
the class ModelBrowser method add.
void add(Node<Context> parent, List<String> children) {
if (parent.data.hasSingletons()) {
if (parent.data.getSingletons().size() == children.size()) {
MessageEvent.fire(eventBus, Message.warning(resources.messages().allSingletonsExist()));
} else if (parent.data.getSingletons().size() - children.size() == 1) {
// no need to show a wizard - find the missing singleton
HashSet<String> singletons = Sets.newHashSet(parent.data.getSingletons());
singletons.removeAll(children);
String singleton = singletons.iterator().next();
ResourceAddress singletonAddress = parent.data.getAddress().getParent().add(parent.text, singleton);
AddressTemplate template = asGenericTemplate(parent, singletonAddress);
String id = Ids.build(parent.id, "singleton", Ids.ADD);
crud.addSingleton(id, singleton, template, address -> refresh(parent));
} else {
// open wizard to choose the singleton
Wizard<SingletonContext, SingletonState> wizard = new Wizard.Builder<SingletonContext, SingletonState>(resources.messages().addResourceTitle(parent.text), new SingletonContext(parent, children)).addStep(CHOOSE, new ChooseSingletonStep(parent, children, resources)).addStep(CREATE, new CreateSingletonStep(parent, metadataProcessor, progress, eventBus, resources)).onBack((context, currentState) -> currentState == CREATE ? CHOOSE : null).onNext((context, currentState) -> currentState == CHOOSE ? CREATE : null).onFinish((wzrd, context) -> {
Operation.Builder builder = new Operation.Builder(fqAddress(parent, context.singleton), ADD);
if (context.modelNode != null) {
builder.payload(context.modelNode);
}
dispatcher.execute(builder.build(), result -> {
MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(parent.text, context.singleton)));
refresh(parent);
});
}).build();
wizard.show();
}
} else {
AddressTemplate template = asGenericTemplate(parent, parent.data.getAddress());
metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {
@Override
public void onMetadata(Metadata metadata) {
flattenDescription(metadata.getDescription().get(OPERATIONS).get(ADD).get(REQUEST_PROPERTIES));
String title = new LabelBuilder().label(parent.text);
NameItem nameItem = new NameItem();
String id = Ids.build(parent.id, "add");
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).unboundFormItem(nameItem, 0).fromRequestProperties().panelForOptionalAttributes().build();
AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(title), form, (name1, model) -> {
unflattenModel(model);
crud.add(title, nameItem.getValue(), fqAddress(parent, nameItem.getValue()), model, (n, a) -> refresh(parent));
});
dialog.show();
}
});
}
}
use of org.jboss.hal.core.mbui.dialog.NameItem in project console by hal.
the class RoleColumn method editStandardRole.
// ------------------------------------------------------ modify roles
private void editStandardRole(Role role) {
Metadata metadata = metadataRegistry.lookup(ROLE_MAPPING_TEMPLATE);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.ROLE_MAPPING_FORM, metadata).unboundFormItem(new NameItem(), 0).include(INCLUDE_ALL).build();
form.getFormItem(NAME).setEnabled(false);
form.getFormItem(NAME).setRequired(false);
ModelNode modelNode = new ModelNode();
modelNode.get(INCLUDE_ALL).set(role.isIncludeAll());
new ModifyResourceDialog(resources.messages().modifyResourceTitle(resources.constants().role()), form, (frm, changedValues) -> series(new FlowContext(progress.get()), new CheckRoleMapping(dispatcher, role), new AddRoleMapping(dispatcher, role, status -> status == 404), new ModifyIncludeAll(dispatcher, role, frm.getModel().get(INCLUDE_ALL).asBoolean())).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext context) {
MessageEvent.fire(eventBus, Message.success(resources.messages().modifyResourceSuccess(resources.constants().role(), role.getName())));
accessControl.reload(() -> {
refresh(role.getId());
eventBus.fireEvent(new RolesChangedEvent());
});
}
})).show(modelNode);
form.getFormItem(NAME).setValue(role.getName());
}
use of org.jboss.hal.core.mbui.dialog.NameItem in project console by hal.
the class RoleColumn method addScopedRole.
// ------------------------------------------------------ add roles
@SuppressWarnings("ConstantConditions")
private void addScopedRole(Role.Type type, String typeName, AddressTemplate template, AddressTemplate typeaheadTemplate, String formId, String scopeAttribute) {
Metadata metadata = metadataRegistry.lookup(template);
Form<ModelNode> form = new ModelNodeForm.Builder<>(formId, metadata).addOnly().unboundFormItem(new NameItem(), 0).unboundFormItem(new SwitchItem(INCLUDE_ALL, new LabelBuilder().label(INCLUDE_ALL)), 3, resources.messages().includeAllHelpText()).include(BASE_ROLE, scopeAttribute).customFormItem(BASE_ROLE, attributeDescription -> {
SingleSelectBoxItem item = new SingleSelectBoxItem(BASE_ROLE, new LabelBuilder().label(BASE_ROLE), standardRoleNames, false);
item.setRequired(true);
return item;
}).build();
form.getFormItem(scopeAttribute).setRequired(true);
form.getFormItem(scopeAttribute).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, typeaheadTemplate));
form.attach();
AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(typeName), form, (name, model) -> {
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(new AddScopedRole(dispatcher, type, name, model));
Boolean includeAll = form.<Boolean>getFormItem(INCLUDE_ALL).getValue();
Role transientRole = new Role(name, null, type, null);
// We only need the role name in the functions,
// so it's ok to setup a transient role w/o the other attributes.
tasks.add(new CheckRoleMapping(dispatcher, transientRole));
tasks.add(new AddRoleMapping(dispatcher, transientRole, status -> status == 404));
if (includeAll != null && includeAll) {
tasks.add(new ModifyIncludeAll(dispatcher, transientRole, includeAll));
}
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext context) {
MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(typeName, name)));
accessControl.reload(() -> {
refresh(Ids.role(name));
eventBus.fireEvent(new RolesChangedEvent());
});
}
});
});
dialog.getForm().<String>getFormItem(NAME).addValidationHandler(createUniqueValidation());
dialog.show();
}
use of org.jboss.hal.core.mbui.dialog.NameItem in project console by hal.
the class MapperDecoderPresenter method addMappedRoleMapper.
// -------------------------------------------- Mapped Role Mapper
void addMappedRoleMapper() {
Metadata metadata = metadataRegistry.lookup(MAPPED_ROLE_MAPPER_TEMPLATE);
String id = Ids.build(Ids.ELYTRON_MAPPED_ROLE_MAPPER, Ids.ADD);
Form<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).unboundFormItem(new NameItem(), 0).customFormItem(ROLE_MAP, desc -> new RoleMapListItem(ROLE_MAP, new LabelBuilder().label(ROLE_MAP))).addOnly().build();
String title = new LabelBuilder().label(MAPPED_ROLE_MAPPER);
new AddResourceDialog(title, form, (name, payload) -> {
// :add(role-map=[role1 => [role2,role3],role2 => [mane,m2n3]])
crud.add(title, name, MAPPED_ROLE_MAPPER_TEMPLATE, payload, (name1, address) -> reload());
}).show();
}
Aggregations