private ToolStrip mainTableTools() { ToolStrip tools = new ToolStrip(); ToolButton addButton = new ToolButton( Console.CONSTANTS.common_label_add(), event -> { ModelNodeFormBuilder.FormAssets addFormAssets = new ModelNodeFormBuilder() .setResourceDescription(resourceDescription) .setCreateMode(true) .unsorted() .setCreateNameAttribute(false) .setSecurityContext(securityContext) .build(); addFormAssets.getForm().setEnabled(true); addFormAssets .getForm() .addFormValidator( (formItems, formValidation) -> { // at least one field is necessary to fill boolean allEmpty = true; for (FormItem formItem : formItems) { if (!formItem.isUndefined()) { allEmpty = false; break; } } if (allEmpty) { formValidation.addError("match-abstract-type"); FormItem mechanismNameFormItem = formItem(formItems, "match-abstract-type"); mechanismNameFormItem.setErrMessage( "At least one field must contain valid values."); mechanismNameFormItem.setErroneous(true); } }); DefaultWindow dialog = new DefaultWindow(Console.MESSAGES.newTitle("Match Rule")); AddResourceDialog.Callback callback = new AddResourceDialog.Callback() { @Override public void onAdd(ModelNode payload) { for (Property node : payload.asPropertyList()) { // remove undefined attributes if (!node.getValue().isDefined()) { payload.remove(node.getName()); } } circuit.dispatch( new AddListAttribute( ElytronStore.AUTHENTICATION_CONTEXT_ADDRESS, MATCH_RULES, authContextName, payload)); dialog.hide(); } @Override public void onCancel() { dialog.hide(); } }; AddResourceDialog addDialog = new AddResourceDialog(addFormAssets, resourceDescription, callback); dialog.setWidth(480); dialog.setHeight(510); dialog.setWidget(addDialog); dialog.setGlassEnabled(true); dialog.center(); }); ToolButton removeButton = new ToolButton( Console.CONSTANTS.common_label_delete(), event -> { final ModelNode selection = selectionModel.getSelectedObject(); if (selection != null) { Feedback.confirm( "Match Rule", Console.MESSAGES.deleteConfirm("Match Rule " + selection.asString()), isConfirmed -> { if (isConfirmed) { circuit.dispatch( new RemoveListAttribute( ElytronStore.AUTHENTICATION_CONTEXT_ADDRESS, authContextName, MATCH_RULES, selection)); } }); } }); tools.addToolButtonRight(addButton); tools.addToolButtonRight(removeButton); return tools; }
@Override public void setErroneous(boolean b) { super.setErroneous(b); wrapper.setErroneous(b); }