List of usage examples for org.apache.wicket.markup.html.form Form getDefaultModelObject
public final Object getDefaultModelObject()
From source file:de.inren.frontend.user.EditOrCreateUserPanel.java
License:Apache License
@Override protected void initGui() { Form<User> form = new Form<User>("form", new CompoundPropertyModel<User>(user)); StringResourceModel lEmail = new StringResourceModel("email.label", EditOrCreateUserPanel.this, null); form.add(new Label("email.label", lEmail)); form.add(new TextField<String>("email", String.class).setRequired(true).setLabel(lEmail) .add(RfcCompliantEmailAddressValidator.getInstance())); StringResourceModel lPwd = new StringResourceModel("password.label", EditOrCreateUserPanel.this, null); form.add(new Label("password.label", lPwd)); PasswordTextField password = new PasswordTextField("password"); password.setModel(passwordModel);//from w ww .j a v a 2 s. c o m password.setRequired(false).setLabel(lPwd); form.add(password); StringResourceModel lPwdrep = new StringResourceModel("passwordrepeat.label", EditOrCreateUserPanel.this, null); form.add(new Label("passwordrepeat.label", lPwdrep)); PasswordTextField passwordrepeat = new PasswordTextField("passwordrepeat"); passwordrepeat.setModel(password.getModel()); passwordrepeat.setRequired(false).setLabel(lPwdrep); form.add(passwordrepeat); form.add(new EqualPasswordInputValidator(password, passwordrepeat)); StringResourceModel lFname = new StringResourceModel("firstname.label", EditOrCreateUserPanel.this, null); form.add(new Label("firstname.label", lFname)); form.add(new TextField<String>("firstname", String.class).setRequired(true).setLabel(lFname)); StringResourceModel lLname = new StringResourceModel("lastname.label", EditOrCreateUserPanel.this, null); form.add(new Label("lastname.label", lLname)); form.add(new TextField<String>("lastname", String.class).setRequired(true).setLabel(lLname)); // TODO die Boolean Werte StringResourceModel lLaccountNonExpired = new StringResourceModel("accountNonExpired.label", EditOrCreateUserPanel.this, null); form.add(new Label("accountNonExpired.label", lLaccountNonExpired)); form.add(new CheckBox("accountNonExpired").setLabel(lLaccountNonExpired)); StringResourceModel laccountNonLocked = new StringResourceModel("accountNonLocked.label", EditOrCreateUserPanel.this, null); form.add(new Label("accountNonLocked.label", laccountNonLocked)); form.add(new CheckBox("accountNonLocked").setLabel(laccountNonLocked)); StringResourceModel lLcredentialsNonExpired = new StringResourceModel("credentialsNonExpired.label", EditOrCreateUserPanel.this, null); form.add(new Label("credentialsNonExpired.label", lLcredentialsNonExpired)); form.add(new CheckBox("credentialsNonExpired").setLabel(lLcredentialsNonExpired)); List<Role> allRoles = new ArrayList<Role>(); try { allRoles = roleService.loadAllRoles(); } catch (RuntimeException e1) { e1.printStackTrace(); } StringResourceModel lRoles = new StringResourceModel("roles.label", EditOrCreateUserPanel.this, null); form.add(new Label("roles.label", lRoles)); form.add(new Palette<Role>("roles", new ListModel<Role>(allRoles), new ChoiceRenderer<Role>("name", "id"), 5, false)); form.add(new AjaxLink<Void>("cancel") { @Override public void onClick(AjaxRequestTarget target) { getSession().getFeedbackMessages().clear(); delegate.switchToComponent(target, delegate.getManagePanel()); } }); form.add(new AjaxButton("submit") { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { try { String password = passwordModel.getObject(); if (!"".equals(password)) { ((User) form.getDefaultModelObject()).setPassword(password); } User u = userService.save((User) form.getModelObject()); form.info(new StringResourceModel("feedback.success", EditOrCreateUserPanel.this, null) .getString()); delegate.switchToComponent(target, delegate.getManagePanel()); } catch (RuntimeException e) { form.error(new StringResourceModel("TODO", EditOrCreateUserPanel.this, null).getString()); target.add(getFeedback()); } } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { FeedbackPanel f = getFeedback(); if (target != null && f != null) { target.add(f); } } }); add(form); }
From source file:org.apache.syncope.client.console.pages.DerSchemaModalPage.java
License:Apache License
@Override public void setSchemaModalPage(final PageReference pageRef, final ModalWindow window, DerSchemaTO schema, final boolean createFlag) { if (schema == null) { schema = new DerSchemaTO(); }/*from ww w. j a v a 2s.c o m*/ final Form<DerSchemaTO> schemaForm = new Form<>(FORM); schemaForm.setModel(new CompoundPropertyModel<>(schema)); final AjaxTextFieldPanel name = new AjaxTextFieldPanel("key", getString("key"), new PropertyModel<String>(schema, "key")); name.addRequiredLabel(); final AjaxTextFieldPanel expression = new AjaxTextFieldPanel("expression", getString("expression"), new PropertyModel<String>(schema, "expression")); expression.addRequiredLabel(); final WebMarkupContainer jexlHelp = JexlHelpUtils.getJexlHelpWebContainer("jexlHelp"); final AjaxLink<Void> questionMarkJexlHelp = JexlHelpUtils.getAjaxLink(jexlHelp, "questionMarkJexlHelp"); schemaForm.add(questionMarkJexlHelp); questionMarkJexlHelp.add(jexlHelp); name.setEnabled(createFlag); final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(SUBMIT)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form form) { DerSchemaTO schemaTO = (DerSchemaTO) form.getDefaultModelObject(); try { if (createFlag) { schemaRestClient.createDerSchema(kind, schemaTO); } else { schemaRestClient.updateDerSchema(kind, schemaTO); } if (pageRef.getPage() instanceof BasePage) { ((BasePage) pageRef.getPage()).setModalResult(true); } window.close(target); } catch (SyncopeClientException e) { error(getString(Constants.ERROR) + ": " + e.getMessage()); feedbackPanel.refresh(target); } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { window.close(target); } }; cancel.setDefaultFormProcessing(false); String allowedRoles = createFlag ? xmlRolesReader.getEntitlement("Schema", "create") : xmlRolesReader.getEntitlement("Schema", "update"); MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, allowedRoles); schemaForm.add(name); schemaForm.add(expression); schemaForm.add(submit); schemaForm.add(cancel); add(schemaForm); }
From source file:org.apache.syncope.client.console.pages.GroupModalPage.java
License:Apache License
protected void submitAction(final AjaxRequestTarget target, final Form<?> form) { final GroupTO groupTO = (GroupTO) form.getDefaultModelObject(); final List<String> entitlementList = new ArrayList<String>(groupPanel.getSelectedEntitlements()); groupTO.getEntitlements().clear();//from w ww .ja v a 2 s. c o m groupTO.getEntitlements().addAll(entitlementList); GroupTO result; if (createFlag) { result = groupRestClient.create(groupTO); } else { GroupMod groupMod = AttributableOperations.diff(groupTO, originalGroupTO); // update group just if it is changed if (groupMod.isEmpty()) { result = groupTO; } else { result = groupRestClient.update(originalGroupTO.getETagValue(), groupMod); } } setResponsePage(new ResultStatusModalPage.Builder(window, result).build()); }
From source file:org.apache.syncope.client.console.pages.PlainSchemaModalPage.java
License:Apache License
@Override public void setSchemaModalPage(final PageReference pageRef, final ModalWindow window, final PlainSchemaTO schemaTO, final boolean createFlag) { final PlainSchemaTO schema = schemaTO == null ? new PlainSchemaTO() : schemaTO; final Form<PlainSchemaTO> schemaForm = new Form<>(FORM); schemaForm.setModel(new CompoundPropertyModel<>(schema)); schemaForm.setOutputMarkupId(true);/* w ww . j a v a2s . co m*/ final AjaxTextFieldPanel name = new AjaxTextFieldPanel("key", getString("key"), new PropertyModel<String>(schema, "key")); name.addRequiredLabel(); name.setEnabled(createFlag); schemaForm.add(name); final AjaxDropDownChoicePanel<AttrSchemaType> type = new AjaxDropDownChoicePanel<>("type", getString("type"), new PropertyModel<AttrSchemaType>(schema, "type")); type.setChoices(Arrays.asList(AttrSchemaType.values())); type.addRequiredLabel(); schemaForm.add(type); // -- long, double, date final AjaxTextFieldPanel conversionPattern = new AjaxTextFieldPanel("conversionPattern", getString("conversionPattern"), new PropertyModel<String>(schema, "conversionPattern")); schemaForm.add(conversionPattern); final WebMarkupContainer conversionParams = new WebMarkupContainer("conversionParams"); conversionParams.setOutputMarkupPlaceholderTag(true); conversionParams.add(conversionPattern); schemaForm.add(conversionParams); final WebMarkupContainer typeParams = new WebMarkupContainer("typeParams"); typeParams.setOutputMarkupPlaceholderTag(true); // -- enum final AjaxTextFieldPanel enumerationValuesPanel = new AjaxTextFieldPanel("panel", "enumerationValues", new Model<String>(null)); @SuppressWarnings({ "unchecked", "rawtypes" }) final MultiFieldPanel<String> enumerationValues = new MultiFieldPanel<>("enumerationValues", new Model(), enumerationValuesPanel); enumerationValues.setModelObject(getEnumValuesAsList(schema.getEnumerationValues())); @SuppressWarnings({ "unchecked", "rawtypes" }) final MultiFieldPanel<String> enumerationKeys = new MultiFieldPanel<>("enumerationKeys", new Model(), new AjaxTextFieldPanel("panel", "enumerationKeys", new Model<String>(null))); enumerationKeys.setModelObject(getEnumValuesAsList(schema.getEnumerationKeys())); final WebMarkupContainer enumParams = new WebMarkupContainer("enumParams"); enumParams.setOutputMarkupPlaceholderTag(true); enumParams.add(enumerationValues); enumParams.add(enumerationKeys); typeParams.add(enumParams); // -- encrypted final AjaxTextFieldPanel secretKey = new AjaxTextFieldPanel("secretKey", getString("secretKey"), new PropertyModel<String>(schema, "secretKey")); final AjaxDropDownChoicePanel<CipherAlgorithm> cipherAlgorithm = new AjaxDropDownChoicePanel<>( "cipherAlgorithm", getString("cipherAlgorithm"), new PropertyModel<CipherAlgorithm>(schema, "cipherAlgorithm")); cipherAlgorithm.setChoices(Arrays.asList(CipherAlgorithm.values())); final WebMarkupContainer encryptedParams = new WebMarkupContainer("encryptedParams"); encryptedParams.setOutputMarkupPlaceholderTag(true); encryptedParams.add(secretKey); encryptedParams.add(cipherAlgorithm); typeParams.add(encryptedParams); // -- binary final AjaxTextFieldPanel mimeType = new AjaxTextFieldPanel("mimeType", getString("mimeType"), new PropertyModel<String>(schema, "mimeType")); mimeType.setChoices(mimeTypesInitializer.getMimeTypes()); final WebMarkupContainer binaryParams = new WebMarkupContainer("binaryParams"); binaryParams.setOutputMarkupPlaceholderTag(true); binaryParams.add(mimeType); typeParams.add(binaryParams); schemaForm.add(typeParams); // -- show or hide showHide(schema, type, conversionParams, conversionPattern, enumParams, enumerationValuesPanel, enumerationValues, enumerationKeys, encryptedParams, secretKey, cipherAlgorithm, binaryParams, mimeType); type.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { PlainSchemaModalPage.this.showHide(schema, type, conversionParams, conversionPattern, enumParams, enumerationValuesPanel, enumerationValues, enumerationKeys, encryptedParams, secretKey, cipherAlgorithm, binaryParams, mimeType); target.add(typeParams); } }); final IModel<List<String>> validatorsList = new LoadableDetachableModel<List<String>>() { private static final long serialVersionUID = 5275935387613157437L; @Override protected List<String> load() { return schemaRestClient.getAllValidatorClasses(); } }; final AjaxDropDownChoicePanel<String> validatorClass = new AjaxDropDownChoicePanel<>("validatorClass", getString("validatorClass"), new PropertyModel<String>(schema, "validatorClass")); ((DropDownChoice) validatorClass.getField()).setNullValid(true); validatorClass.setChoices(validatorsList.getObject()); schemaForm.add(validatorClass); final AutoCompleteTextField<String> mandatoryCondition = new AutoCompleteTextField<String>( "mandatoryCondition") { private static final long serialVersionUID = -2428903969518079100L; @Override protected Iterator<String> getChoices(final String input) { List<String> choices = new ArrayList<String>(); if (Strings.isEmpty(input)) { choices = Collections.emptyList(); } else if ("true".startsWith(input.toLowerCase())) { choices.add("true"); } else if ("false".startsWith(input.toLowerCase())) { choices.add("false"); } return choices.iterator(); } }; mandatoryCondition.add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { } }); schemaForm.add(mandatoryCondition); final WebMarkupContainer pwdJexlHelp = JexlHelpUtils.getJexlHelpWebContainer("jexlHelp"); final AjaxLink<Void> pwdQuestionMarkJexlHelp = JexlHelpUtils.getAjaxLink(pwdJexlHelp, "questionMarkJexlHelp"); schemaForm.add(pwdQuestionMarkJexlHelp); pwdQuestionMarkJexlHelp.add(pwdJexlHelp); final AjaxCheckBoxPanel multivalue = new AjaxCheckBoxPanel("multivalue", getString("multivalue"), new PropertyModel<Boolean>(schema, "multivalue")); schemaForm.add(multivalue); final AjaxCheckBoxPanel readonly = new AjaxCheckBoxPanel("readonly", getString("readonly"), new PropertyModel<Boolean>(schema, "readonly")); schemaForm.add(readonly); final AjaxCheckBoxPanel uniqueConstraint = new AjaxCheckBoxPanel("uniqueConstraint", getString("uniqueConstraint"), new PropertyModel<Boolean>(schema, "uniqueConstraint")); schemaForm.add(uniqueConstraint); final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(SUBMIT)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { final PlainSchemaTO schemaTO = (PlainSchemaTO) form.getDefaultModelObject(); schemaTO.setEnumerationValues(getEnumValuesAsString(enumerationValues.getView().getModelObject())); schemaTO.setEnumerationKeys(getEnumValuesAsString(enumerationKeys.getView().getModelObject())); if (schemaTO.isMultivalue() && schemaTO.isUniqueConstraint()) { error(getString("multivalueAndUniqueConstr.validation")); feedbackPanel.refresh(target); return; } try { if (createFlag) { schemaRestClient.createPlainSchema(kind, schemaTO); } else { schemaRestClient.updatePlainSchema(kind, schemaTO); } if (pageRef.getPage() instanceof BasePage) { ((BasePage) pageRef.getPage()).setModalResult(true); } window.close(target); } catch (SyncopeClientException e) { error(getString(Constants.ERROR) + ": " + e.getMessage()); feedbackPanel.refresh(target); } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; schemaForm.add(submit); final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { window.close(target); } }; cancel.setDefaultFormProcessing(false); schemaForm.add(cancel); String allowedRoles = createFlag ? xmlRolesReader.getEntitlement("Schema", "create") : xmlRolesReader.getEntitlement("Schema", "update"); MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, allowedRoles); add(schemaForm); }
From source file:org.apache.syncope.client.console.pages.ResourceModalPage.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" })
public ResourceModalPage(final PageReference pageRef, final ModalWindow window, final ResourceTO resourceTO,
final boolean createFlag) {
super();/* w w w . ja v a2 s . c o m*/
this.add(new Label("new", StringUtils.isBlank(resourceTO.getKey()) ? new ResourceModel("new")
: new Model(StringUtils.EMPTY)));
this.add(new Label("name",
StringUtils.isBlank(resourceTO.getKey()) ? StringUtils.EMPTY : resourceTO.getKey()));
final Form<ResourceTO> form = new Form<>(FORM);
form.setModel(new CompoundPropertyModel<>(resourceTO));
//--------------------------------
// Resource details panel
//--------------------------------
form.add(new ResourceDetailsPanel("details", resourceTO, resourceRestClient.getPropagationActionsClasses(),
createFlag));
form.add(new AnnotatedBeanPanel("systeminformation", resourceTO));
//--------------------------------
//--------------------------------
// Resource mapping panels
//--------------------------------
form.add(new ResourceMappingPanel("umapping", resourceTO, AttributableType.USER));
form.add(new ResourceMappingPanel("gmapping", resourceTO, AttributableType.GROUP));
//--------------------------------
//--------------------------------
// Resource connector configuration panel
//--------------------------------
ResourceConnConfPanel resourceConnConfPanel = new ResourceConnConfPanel("connconf", resourceTO, createFlag);
MetaDataRoleAuthorizationStrategy.authorize(resourceConnConfPanel, ENABLE,
xmlRolesReader.getEntitlement("Connectors", "read"));
form.add(resourceConnConfPanel);
//--------------------------------
//--------------------------------
// Resource security panel
//--------------------------------
form.add(new ResourceSecurityPanel("security", resourceTO));
//--------------------------------
final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(SUBMIT, SUBMIT)) {
private static final long serialVersionUID = -958724007591692537L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
final ResourceTO resourceTO = (ResourceTO) form.getDefaultModelObject();
boolean accountIdError = false;
if (resourceTO.getUmapping() == null || resourceTO.getUmapping().getItems().isEmpty()) {
resourceTO.setUmapping(null);
} else {
int uAccountIdCount = 0;
for (MappingItemTO item : resourceTO.getUmapping().getItems()) {
if (item.isAccountid()) {
uAccountIdCount++;
}
}
accountIdError = uAccountIdCount != 1;
}
if (resourceTO.getGmapping() == null || resourceTO.getGmapping().getItems().isEmpty()) {
resourceTO.setGmapping(null);
} else {
int rAccountIdCount = 0;
for (MappingItemTO item : resourceTO.getGmapping().getItems()) {
if (item.isAccountid()) {
rAccountIdCount++;
}
}
accountIdError |= rAccountIdCount != 1;
}
if (accountIdError) {
error(getString("accountIdValidation"));
feedbackPanel.refresh(target);
} else {
try {
if (createFlag) {
resourceRestClient.create(resourceTO);
} else {
resourceRestClient.update(resourceTO);
}
if (pageRef != null && pageRef.getPage() instanceof AbstractBasePage) {
((AbstractBasePage) pageRef.getPage()).setModalResult(true);
}
window.close(target);
} catch (Exception e) {
LOG.error("Failure managing resource {}", resourceTO, e);
error(getString(Constants.ERROR) + ": " + e.getMessage());
feedbackPanel.refresh(target);
}
}
}
@Override
protected void onError(final AjaxRequestTarget target, final Form<?> form) {
feedbackPanel.refresh(target);
}
};
form.add(submit);
form.setDefaultButton(submit);
final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {
private static final long serialVersionUID = -958724007591692537L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
window.close(target);
}
@Override
protected void onError(final AjaxRequestTarget target, final Form<?> form) {
}
};
cancel.setDefaultFormProcessing(false);
form.add(cancel);
add(form);
MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE,
xmlRolesReader.getEntitlement("Resources", createFlag ? "create" : "update"));
}
From source file:org.apache.syncope.client.console.pages.RoleModalPage.java
License:Apache License
protected void submitAction(final AjaxRequestTarget target, final Form<?> form) { final RoleTO roleTO = (RoleTO) form.getDefaultModelObject(); final List<String> entitlementList = new ArrayList<String>(rolePanel.getSelectedEntitlements()); roleTO.getEntitlements().clear();/*from w w w . j a v a2 s . c om*/ roleTO.getEntitlements().addAll(entitlementList); RoleTO result; if (createFlag) { result = roleRestClient.create(roleTO); } else { RoleMod roleMod = AttributableOperations.diff(roleTO, originalRoleTO); // update role just if it is changed if (roleMod.isEmpty()) { result = roleTO; } else { result = roleRestClient.update(originalRoleTO.getETagValue(), roleMod); } } setResponsePage(new ResultStatusModalPage.Builder(window, result).build()); }
From source file:org.apache.syncope.client.console.pages.VirSchemaModalPage.java
License:Apache License
@Override public void setSchemaModalPage(final PageReference pageRef, final ModalWindow window, VirSchemaTO schema, final boolean createFlag) { if (schema == null) { schema = new VirSchemaTO(); }/*from w w w .j a v a2 s. c o m*/ final Form<VirSchemaTO> schemaForm = new Form<>(FORM); schemaForm.setModel(new CompoundPropertyModel<>(schema)); final AjaxTextFieldPanel name = new AjaxTextFieldPanel("key", getString("key"), new PropertyModel<String>(schema, "key")); name.addRequiredLabel(); name.setEnabled(createFlag); final AjaxCheckBoxPanel readonly = new AjaxCheckBoxPanel("readonly", getString("readonly"), new PropertyModel<Boolean>(schema, "readonly")); final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(SUBMIT)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { VirSchemaTO schemaTO = (VirSchemaTO) form.getDefaultModelObject(); try { if (createFlag) { schemaRestClient.createVirSchema(kind, schemaTO); } else { schemaRestClient.updateVirSchema(kind, schemaTO); } if (pageRef.getPage() instanceof BasePage) { ((BasePage) pageRef.getPage()).setModalResult(true); } window.close(target); } catch (SyncopeClientException e) { error(getString(Constants.ERROR) + ": " + e.getMessage()); feedbackPanel.refresh(target); } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { window.close(target); } }; cancel.setDefaultFormProcessing(false); String allowedRoles = createFlag ? xmlRolesReader.getEntitlement("Schema", "create") : xmlRolesReader.getEntitlement("Schema", "update"); MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, allowedRoles); schemaForm.add(name); schemaForm.add(readonly); schemaForm.add(submit); schemaForm.add(cancel); add(schemaForm); }
From source file:org.apache.syncope.client.console.panels.ResourceModal.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" })
public ResourceModal(final ModalWindow window, final PageReference pageRef, final ResourceTO resourceTO,
final boolean createFlag) {
super(window, pageRef);
final Form<ResourceTO> form = new Form<>(FORM);
form.setModel(new CompoundPropertyModel<>(resourceTO));
//--------------------------------
// Resource details panel
//--------------------------------
form.add(new ResourceDetailsPanel("details", resourceTO, resourceRestClient.getPropagationActionsClasses(),
createFlag));//from ww w . j a v a 2 s .c o m
form.add(new AnnotatedBeanPanel("systeminformation", resourceTO));
//--------------------------------
//--------------------------------
// Resource mapping panels
//--------------------------------
form.add(new ResourceMappingPanel("umapping", resourceTO, AnyTypeKind.USER));
form.add(new ResourceMappingPanel("gmapping", resourceTO, AnyTypeKind.GROUP));
//--------------------------------
//--------------------------------
// Resource connector configuration panel
//--------------------------------
ResourceConnConfPanel resourceConnConfPanel = new ResourceConnConfPanel("connconf", resourceTO, createFlag);
MetaDataRoleAuthorizationStrategy.authorize(resourceConnConfPanel, ENABLE, Entitlement.CONNECTOR_READ);
form.add(resourceConnConfPanel);
//--------------------------------
//--------------------------------
// Resource security panel
//--------------------------------
form.add(new ResourceSecurityPanel("security", resourceTO));
//--------------------------------
AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(SUBMIT, SUBMIT)) {
private static final long serialVersionUID = -958724007591692537L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
final ResourceTO resourceTO = (ResourceTO) form.getDefaultModelObject();
boolean connObjectKeyError = false;
final Collection<ProvisionTO> provisions = new ArrayList<>(resourceTO.getProvisions());
for (ProvisionTO provision : provisions) {
if (provision != null) {
if (provision.getMapping() == null || provision.getMapping().getItems().isEmpty()) {
resourceTO.getProvisions().remove(provision);
} else {
int uConnObjectKeyCount = CollectionUtils.countMatches(
provision.getMapping().getItems(), new Predicate<MappingItemTO>() {
@Override
public boolean evaluate(final MappingItemTO item) {
return item.isConnObjectKey();
}
});
connObjectKeyError = uConnObjectKeyCount != 1;
}
}
}
if (connObjectKeyError) {
error(getString("connObjectKeyValidation"));
feedbackPanel.refresh(target);
} else {
try {
if (createFlag) {
resourceRestClient.create(resourceTO);
send(pageRef.getPage(), Broadcast.BREADTH, new ResourceCreateEvent(target, resourceTO));
} else {
resourceRestClient.update(resourceTO);
}
if (pageRef.getPage() instanceof AbstractBasePage) {
((AbstractBasePage) pageRef.getPage()).setModalResult(true);
}
window.close(target);
} catch (Exception e) {
LOG.error("Failure managing resource {}", resourceTO, e);
error(getString(Constants.ERROR) + ": " + e.getMessage());
feedbackPanel.refresh(target);
}
}
}
@Override
protected void onError(final AjaxRequestTarget target, final Form<?> form) {
feedbackPanel.refresh(target);
}
};
form.add(submit);
form.setDefaultButton(submit);
final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {
private static final long serialVersionUID = -958724007591692537L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
window.close(target);
}
@Override
protected void onError(final AjaxRequestTarget target, final Form<?> form) {
}
};
cancel.setDefaultFormProcessing(false);
form.add(cancel);
add(form);
MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE,
createFlag ? Entitlement.RESOURCE_CREATE : Entitlement.RESOURCE_UPDATE);
}
From source file:org.apache.syncope.console.pages.DerSchemaModalPage.java
License:Apache License
@Override public void setSchemaModalPage(final PageReference pageRef, final ModalWindow window, DerSchemaTO schema, final boolean createFlag) { if (schema == null) { schema = new DerSchemaTO(); }//from w ww . j a v a 2 s . c o m final Form<DerSchemaTO> schemaForm = new Form<DerSchemaTO>(FORM); schemaForm.setModel(new CompoundPropertyModel<DerSchemaTO>(schema)); final AjaxTextFieldPanel name = new AjaxTextFieldPanel("name", getString("name"), new PropertyModel<String>(schema, "name")); name.addRequiredLabel(); final AjaxTextFieldPanel expression = new AjaxTextFieldPanel("expression", getString("expression"), new PropertyModel<String>(schema, "expression")); expression.addRequiredLabel(); final WebMarkupContainer jexlHelp = JexlHelpUtil.getJexlHelpWebContainer("jexlHelp"); final AjaxLink<Void> questionMarkJexlHelp = JexlHelpUtil.getAjaxLink(jexlHelp, "questionMarkJexlHelp"); schemaForm.add(questionMarkJexlHelp); questionMarkJexlHelp.add(jexlHelp); name.setEnabled(createFlag); final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(SUBMIT)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form form) { DerSchemaTO schemaTO = (DerSchemaTO) form.getDefaultModelObject(); try { if (createFlag) { schemaRestClient.createDerSchema(kind, schemaTO); } else { schemaRestClient.updateDerSchema(kind, schemaTO); } if (pageRef.getPage() instanceof BasePage) { ((BasePage) pageRef.getPage()).setModalResult(true); } window.close(target); } catch (SyncopeClientException e) { error(getString(Constants.ERROR) + ": " + e.getMessage()); feedbackPanel.refresh(target); } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { window.close(target); } }; cancel.setDefaultFormProcessing(false); String allowedRoles = createFlag ? xmlRolesReader.getAllAllowedRoles("Schema", "create") : xmlRolesReader.getAllAllowedRoles("Schema", "update"); MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, allowedRoles); schemaForm.add(name); schemaForm.add(expression); schemaForm.add(submit); schemaForm.add(cancel); add(schemaForm); }
From source file:org.apache.syncope.console.pages.ResourceModalPage.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" })
public ResourceModalPage(final PageReference pageRef, final ModalWindow window, final ResourceTO resourceTO,
final boolean createFlag) {
super();//from w w w. ja va 2 s . c o m
this.add(new Label("new",
StringUtils.isBlank(resourceTO.getName()) ? new ResourceModel("new") : new Model("")));
this.add(new Label("name", StringUtils.isBlank(resourceTO.getName()) ? "" : resourceTO.getName()));
final Form<ResourceTO> form = new Form<ResourceTO>(FORM);
form.setModel(new CompoundPropertyModel<ResourceTO>(resourceTO));
//--------------------------------
// Resource details panel
//--------------------------------
form.add(new ResourceDetailsPanel("details", resourceTO, resourceRestClient.getPropagationActionsClasses(),
createFlag));
form.add(new SysInfoPanel("systeminformation", resourceTO));
//--------------------------------
//--------------------------------
// Resource mapping panels
//--------------------------------
form.add(new ResourceMappingPanel("umapping", resourceTO, AttributableType.USER));
form.add(new ResourceMappingPanel("rmapping", resourceTO, AttributableType.ROLE));
//--------------------------------
//--------------------------------
// Resource connector configuration panel
//--------------------------------
form.add(new ResourceConnConfPanel("connconf", resourceTO, createFlag));
//--------------------------------
//--------------------------------
// Resource security panel
//--------------------------------
form.add(new ResourceSecurityPanel("security", resourceTO));
//--------------------------------
final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(SUBMIT, SUBMIT)) {
private static final long serialVersionUID = -958724007591692537L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
final ResourceTO resourceTO = (ResourceTO) form.getDefaultModelObject();
boolean accountIdError = false;
if (resourceTO.getUmapping() == null || resourceTO.getUmapping().getItems().isEmpty()) {
resourceTO.setUmapping(null);
} else {
int uAccountIdCount = 0;
for (MappingItemTO item : resourceTO.getUmapping().getItems()) {
if (item.isAccountid()) {
uAccountIdCount++;
}
}
accountIdError = uAccountIdCount != 1;
}
if (resourceTO.getRmapping() == null || resourceTO.getRmapping().getItems().isEmpty()) {
resourceTO.setRmapping(null);
} else {
int rAccountIdCount = 0;
for (MappingItemTO item : resourceTO.getRmapping().getItems()) {
if (item.isAccountid()) {
rAccountIdCount++;
}
}
accountIdError |= rAccountIdCount != 1;
}
if (accountIdError) {
error(getString("accountIdValidation"));
feedbackPanel.refresh(target);
} else {
try {
if (createFlag) {
resourceRestClient.create(resourceTO);
} else {
resourceRestClient.update(resourceTO);
}
if (pageRef != null && pageRef.getPage() instanceof AbstractBasePage) {
((AbstractBasePage) pageRef.getPage()).setModalResult(true);
}
window.close(target);
} catch (Exception e) {
LOG.error("Failure managing resource {}", resourceTO, e);
error(getString(Constants.ERROR) + ": " + e.getMessage());
feedbackPanel.refresh(target);
}
}
}
@Override
protected void onError(final AjaxRequestTarget target, final Form<?> form) {
feedbackPanel.refresh(target);
}
};
form.add(submit);
form.setDefaultButton(submit);
final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {
private static final long serialVersionUID = -958724007591692537L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
window.close(target);
}
@Override
protected void onError(final AjaxRequestTarget target, final Form<?> form) {
}
};
cancel.setDefaultFormProcessing(false);
form.add(cancel);
add(form);
MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE,
xmlRolesReader.getAllAllowedRoles("Resources", createFlag ? "create" : "update"));
}