use of org.jboss.hal.dmr.ModelDescriptionConstants.STRING 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();
}
});
}
}
Aggregations