List of usage examples for org.apache.wicket.markup.html.form Form setDefaultButton
public final void setDefaultButton(IFormSubmittingComponent submittingComponent)
From source file:org.apache.syncope.console.pages.MembershipModalPage.java
License:Apache License
public MembershipModalPage(final PageReference pageRef, final ModalWindow window, final MembershipTO membershipTO, final boolean templateMode) { final Form<MembershipTO> form = new Form<MembershipTO>("MembershipForm"); final UserTO userTO = ((UserModalPage) pageRef.getPage()).getUserTO(); form.setModel(new CompoundPropertyModel<MembershipTO>(membershipTO)); submit = new AjaxButton(SUBMIT, new ResourceModel(SUBMIT)) { private static final long serialVersionUID = -958724007591692537L; @Override/* ww w . ja va 2 s . co m*/ protected void onSubmit(final AjaxRequestTarget target, final Form form) { userTO.getMemberships().remove(membershipTO); userTO.getMemberships().add(membershipTO); ((UserModalPage) pageRef.getPage()).setUserTO(userTO); window.close(target); } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; form.add(submit); form.setDefaultButton(submit); final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { ((UserModalPage) pageRef.getPage()).setUserTO(userTO); window.close(target); } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { } }; cancel.setDefaultFormProcessing(false); form.add(cancel); //-------------------------------- // Attributes panel //-------------------------------- form.add(new AttributesPanel("attrs", membershipTO, form, templateMode)); form.add(new SysInfoPanel("systeminformation", membershipTO)); //-------------------------------- //-------------------------------- // Derived attributes container //-------------------------------- form.add(new DerivedAttributesPanel("derAttrs", membershipTO)); //-------------------------------- //-------------------------------- // Virtual attributes container //-------------------------------- form.add(new VirtualAttributesPanel("virAttrs", membershipTO, templateMode)); //-------------------------------- add(form); }
From source file:org.apache.syncope.console.pages.NotificationModalPage.java
License:Apache License
public NotificationModalPage(final PageReference pageRef, final ModalWindow window, final NotificationTO notificationTO, final boolean createFlag) { final Form<NotificationTO> form = new Form<NotificationTO>(FORM, new CompoundPropertyModel<NotificationTO>(notificationTO)); final AjaxTextFieldPanel sender = new AjaxTextFieldPanel("sender", getString("sender"), new PropertyModel<String>(notificationTO, "sender")); sender.addRequiredLabel();// w ww .ja va 2 s . c om sender.addValidator(EmailAddressValidator.getInstance()); form.add(sender); final AjaxTextFieldPanel subject = new AjaxTextFieldPanel("subject", getString("subject"), new PropertyModel<String>(notificationTO, "subject")); subject.addRequiredLabel(); form.add(subject); final AjaxDropDownChoicePanel<String> template = new AjaxDropDownChoicePanel<String>("template", getString("template"), new PropertyModel<String>(notificationTO, "template")); template.setChoices(restClient.getMailTemplates()); template.addRequiredLabel(); form.add(template); final AjaxDropDownChoicePanel<TraceLevel> traceLevel = new AjaxDropDownChoicePanel<TraceLevel>("traceLevel", getString("traceLevel"), new PropertyModel<TraceLevel>(notificationTO, "traceLevel")); traceLevel.setChoices(Arrays.asList(TraceLevel.values())); traceLevel.addRequiredLabel(); form.add(traceLevel); final AjaxCheckBoxPanel isActive = new AjaxCheckBoxPanel("isActive", getString("isActive"), new PropertyModel<Boolean>(notificationTO, "active")); if (createFlag) { isActive.getField().setDefaultModelObject(Boolean.TRUE); } form.add(isActive); final WebMarkupContainer aboutContainer = new WebMarkupContainer("aboutContainer"); aboutContainer.setOutputMarkupId(true); form.add(aboutContainer); final AjaxCheckBoxPanel checkAbout = new AjaxCheckBoxPanel("checkAbout", "checkAbout", new Model<Boolean>(notificationTO.getUserAbout() == null && notificationTO.getRoleAbout() == null)); aboutContainer.add(checkAbout); final AjaxCheckBoxPanel checkUserAbout = new AjaxCheckBoxPanel("checkUserAbout", "checkUserAbout", new Model<Boolean>(notificationTO.getUserAbout() != null)); aboutContainer.add(checkUserAbout); final AjaxCheckBoxPanel checkRoleAbout = new AjaxCheckBoxPanel("checkRoleAbout", "checkRoleAbout", new Model<Boolean>(notificationTO.getRoleAbout() != null)); aboutContainer.add(checkRoleAbout); final UserSearchPanel userAbout = new UserSearchPanel.Builder("userAbout") .fiql(notificationTO.getUserAbout()).build(); aboutContainer.add(userAbout); userAbout.setEnabled(checkUserAbout.getModelObject()); final RoleSearchPanel roleAbout = new RoleSearchPanel.Builder("roleAbout") .fiql(notificationTO.getRoleAbout()).build(); aboutContainer.add(roleAbout); roleAbout.setEnabled(checkRoleAbout.getModelObject()); checkAbout.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { if (checkAbout.getModelObject()) { checkUserAbout.setModelObject(Boolean.FALSE); checkRoleAbout.setModelObject(Boolean.FALSE); userAbout.setEnabled(Boolean.FALSE); roleAbout.setEnabled(Boolean.FALSE); } else { checkAbout.setModelObject(Boolean.TRUE); } target.add(aboutContainer); } }); checkUserAbout.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { if (checkUserAbout.getModelObject()) { checkAbout.setModelObject(!checkUserAbout.getModelObject()); checkRoleAbout.setModelObject(!checkUserAbout.getModelObject()); roleAbout.setEnabled(Boolean.FALSE); } else { checkUserAbout.setModelObject(Boolean.TRUE); } userAbout.setEnabled(Boolean.TRUE); target.add(aboutContainer); } }); checkRoleAbout.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { if (checkRoleAbout.getModelObject()) { checkAbout.setModelObject(Boolean.FALSE); checkUserAbout.setModelObject(Boolean.FALSE); userAbout.setEnabled(Boolean.FALSE); } else { checkRoleAbout.setModelObject(Boolean.TRUE); } roleAbout.setEnabled(Boolean.TRUE); target.add(aboutContainer); } }); final AjaxDropDownChoicePanel<IntMappingType> recipientAttrType = new AjaxDropDownChoicePanel<IntMappingType>( "recipientAttrType", new ResourceModel("recipientAttrType", "recipientAttrType").getObject(), new PropertyModel<IntMappingType>(notificationTO, "recipientAttrType")); recipientAttrType .setChoices(new ArrayList<IntMappingType>(IntMappingType.getAttributeTypes(AttributableType.USER, EnumSet.of(IntMappingType.UserId, IntMappingType.Password)))); recipientAttrType.setRequired(true); form.add(recipientAttrType); final AjaxDropDownChoicePanel<String> recipientAttrName = new AjaxDropDownChoicePanel<String>( "recipientAttrName", new ResourceModel("recipientAttrName", "recipientAttrName").getObject(), new PropertyModel<String>(notificationTO, "recipientAttrName")); recipientAttrName.setChoices(getSchemaNames(recipientAttrType.getModelObject())); recipientAttrName.setRequired(true); form.add(recipientAttrName); recipientAttrType.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { recipientAttrName.setChoices(getSchemaNames(recipientAttrType.getModelObject())); target.add(recipientAttrName); } }); form.add(new LoggerCategoryPanel("eventSelection", loggerRestClient.listEvents(), new PropertyModel<List<String>>(notificationTO, "events"), getPageReference(), "Notification") { private static final long serialVersionUID = 6429053774964787735L; @Override protected String[] getListRoles() { return new String[] {}; } @Override protected String[] getChangeRoles() { return new String[] {}; } }); final WebMarkupContainer recipientsContainer = new WebMarkupContainer("recipientsContainer"); recipientsContainer.setOutputMarkupId(true); form.add(recipientsContainer); final AjaxCheckBoxPanel checkStaticRecipients = new AjaxCheckBoxPanel("checkStaticRecipients", "recipients", new Model<Boolean>(!notificationTO.getStaticRecipients().isEmpty())); form.add(checkStaticRecipients); if (createFlag) { checkStaticRecipients.getField().setDefaultModelObject(Boolean.FALSE); } final AjaxTextFieldPanel staticRecipientsFieldPanel = new AjaxTextFieldPanel("panel", "staticRecipients", new Model<String>(null)); staticRecipientsFieldPanel.addValidator(EmailAddressValidator.getInstance()); staticRecipientsFieldPanel.setRequired(checkStaticRecipients.getModelObject()); if (notificationTO.getStaticRecipients().isEmpty()) { notificationTO.getStaticRecipients().add(null); } final MultiFieldPanel<String> staticRecipients = new MultiFieldPanel<String>("staticRecipients", new PropertyModel<List<String>>(notificationTO, "staticRecipients"), staticRecipientsFieldPanel); staticRecipients.setEnabled(checkStaticRecipients.getModelObject()); form.add(staticRecipients); final AjaxCheckBoxPanel checkRecipients = new AjaxCheckBoxPanel("checkRecipients", "checkRecipients", new Model<Boolean>(notificationTO.getRecipients() == null ? false : true)); recipientsContainer.add(checkRecipients); if (createFlag) { checkRecipients.getField().setDefaultModelObject(Boolean.TRUE); } final UserSearchPanel recipients = new UserSearchPanel.Builder("recipients") .fiql(notificationTO.getRecipients()).build(); recipients.setEnabled(checkRecipients.getModelObject()); recipientsContainer.add(recipients); final AjaxCheckBoxPanel selfAsRecipient = new AjaxCheckBoxPanel("selfAsRecipient", getString("selfAsRecipient"), new PropertyModel<Boolean>(notificationTO, "selfAsRecipient")); form.add(selfAsRecipient); if (createFlag) { selfAsRecipient.getField().setDefaultModelObject(Boolean.FALSE); } selfAsRecipient.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { if (!selfAsRecipient.getModelObject() && !checkRecipients.getModelObject() && !checkStaticRecipients.getModelObject()) { checkRecipients.getField().setDefaultModelObject(Boolean.TRUE); target.add(checkRecipients); recipients.setEnabled(checkRecipients.getModelObject()); target.add(recipients); target.add(recipientsContainer); } } }); checkRecipients.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { if (!checkRecipients.getModelObject() && !selfAsRecipient.getModelObject() && !checkStaticRecipients.getModelObject()) { checkStaticRecipients.getField().setDefaultModelObject(Boolean.TRUE); target.add(checkStaticRecipients); staticRecipients.setEnabled(Boolean.TRUE); target.add(staticRecipients); staticRecipientsFieldPanel.setRequired(Boolean.TRUE); target.add(staticRecipientsFieldPanel); } recipients.setEnabled(checkRecipients.getModelObject()); target.add(recipients); target.add(recipientsContainer); } }); checkStaticRecipients.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { if (!checkStaticRecipients.getModelObject() && !selfAsRecipient.getModelObject() && !checkRecipients.getModelObject()) { checkRecipients.getField().setDefaultModelObject(Boolean.TRUE); checkRecipients.setEnabled(Boolean.TRUE); target.add(checkRecipients); } staticRecipients.setEnabled(checkStaticRecipients.getModelObject()); staticRecipientsFieldPanel.setRequired(checkStaticRecipients.getModelObject()); recipients.setEnabled(checkRecipients.getModelObject()); target.add(staticRecipientsFieldPanel); target.add(staticRecipients); target.add(recipients); target.add(recipientsContainer); } }); AjaxButton submit = new IndicatingAjaxButton(APPLY, new Model<String>(getString(SUBMIT))) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { notificationTO.setUserAbout( !checkAbout.getModelObject() && checkUserAbout.getModelObject() ? userAbout.buildFIQL() : null); notificationTO.setRoleAbout( !checkAbout.getModelObject() && checkRoleAbout.getModelObject() ? roleAbout.buildFIQL() : null); notificationTO.setRecipients(checkRecipients.getModelObject() ? recipients.buildFIQL() : null); notificationTO.getStaticRecipients().removeAll(Collections.singleton(null)); try { if (createFlag) { restClient.createNotification(notificationTO); } else { restClient.updateNotification(notificationTO); } info(getString(Constants.OPERATION_SUCCEEDED)); Configuration callerPage = (Configuration) pageRef.getPage(); callerPage.setModalResult(true); window.close(target); } catch (SyncopeClientException scee) { error(getString(Constants.ERROR) + ": " + scee.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("Notification", "create") : xmlRolesReader.getAllAllowedRoles("Notification", "update"); MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, allowedRoles); form.add(submit); form.setDefaultButton(submit); form.add(cancel); add(form); }
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 ww .j av a 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")); }
From source file:org.apache.syncope.console.pages.RoleModalPage.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" }) public RoleModalPage(final PageReference pageRef, final ModalWindow window, final RoleTO roleTO, final Mode mode) { super();//from w ww.j a v a 2 s .c om this.pageRef = pageRef; this.window = window; this.mode = mode; this.createFlag = roleTO.getId() == 0; if (!createFlag) { originalRoleTO = SerializationUtils.clone(roleTO); } final Form<RoleTO> form = new Form<RoleTO>("RoleForm"); form.setMultiPart(true); add(new Label("displayName", roleTO.getId() == 0 ? "" : roleTO.getDisplayName())); form.setModel(new CompoundPropertyModel<RoleTO>(roleTO)); this.rolePanel = new RolePanel.Builder("rolePanel").form(form).roleTO(roleTO).roleModalPageMode(mode) .pageRef(getPageReference()).build(); form.add(rolePanel); final AjaxButton submit = new IndicatingAjaxButton(SUBMIT, new ResourceModel(SUBMIT)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { try { submitAction(target, form); if (pageRef.getPage() instanceof BasePage) { ((BasePage) pageRef.getPage()).setModalResult(true); } closeAction(target, form); } catch (Exception 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) { closeAction(target, form); } }; cancel.setDefaultFormProcessing(false); MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, xmlRolesReader.getAllAllowedRoles("Roles", createFlag ? "create" : "update")); form.add(submit); form.setDefaultButton(submit); form.add(cancel); add(form); }
From source file:org.apache.syncope.console.pages.UserModalPage.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" }) protected Form setupEditPanel() { fragment.add(new Label("id", userTO.getId() == 0 ? "" : userTO.getUsername())); fragment.add(new Label("new", userTO.getId() == 0 ? new ResourceModel("new") : new Model(""))); final Form form = new Form("UserForm"); form.setModel(new CompoundPropertyModel(userTO)); //-------------------------------- // User details //-------------------------------- form.add(new UserDetailsPanel("details", userTO, form, resetPassword, mode == Mode.TEMPLATE)); form.add(new Label("statuspanel", "")); form.add(new Label("pwdChangeInfo", "")); form.add(new Label("accountinformation", "")); //-------------------------------- //-------------------------------- // Attributes panel //-------------------------------- form.add(new AttributesPanel("attrs", userTO, form, mode == Mode.TEMPLATE)); //-------------------------------- //-------------------------------- // Derived attributes panel //-------------------------------- form.add(new DerivedAttributesPanel("derAttrs", userTO)); //-------------------------------- //-------------------------------- // Virtual attributes panel //-------------------------------- form.add(new VirtualAttributesPanel("virAttrs", userTO, mode == Mode.TEMPLATE)); //-------------------------------- //-------------------------------- // Resources panel //-------------------------------- form.add(new ResourcesPanel.Builder("resources").attributableTO(userTO).statusPanel(null).build()); //-------------------------------- //-------------------------------- // Roles panel //-------------------------------- form.add(new MembershipsPanel("memberships", userTO, mode == Mode.TEMPLATE, null, getPageReference())); //-------------------------------- final AjaxButton submit = getOnSubmit(); if (mode == Mode.ADMIN) { String allowedRoles = userTO.getId() == 0 ? xmlRolesReader.getAllAllowedRoles("Users", "create") : xmlRolesReader.getAllAllowedRoles("Users", "update"); MetaDataRoleAuthorizationStrategy.authorize(submit, RENDER, allowedRoles); }/* w ww.j a v a 2 s .c o m*/ fragment.add(form); form.add(submit); form.setDefaultButton(submit); final AjaxButton cancel = new AjaxButton(CANCEL, new ResourceModel(CANCEL)) { private static final long serialVersionUID = 530608535790823587L; @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); return form; }
From source file:org.apache.syncope.console.pages.Users.java
License:Apache License
public Users(final PageParameters parameters) { super(parameters); // Modal window for editing user attributes final ModalWindow editModalWin = new ModalWindow("editModal"); editModalWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY); editModalWin.setInitialHeight(EDIT_MODAL_WIN_HEIGHT); editModalWin.setInitialWidth(EDIT_MODAL_WIN_WIDTH); editModalWin.setCookieName("edit-modal"); add(editModalWin);/*from w ww . j a va 2 s .c o m*/ final AbstractSearchResultPanel searchResult = new UserSearchResultPanel("searchResult", true, null, getPageReference(), restClient); add(searchResult); final AbstractSearchResultPanel listResult = new UserSearchResultPanel("listResult", false, null, getPageReference(), restClient); add(listResult); // create new user final AjaxLink<Void> createLink = new ClearIndicatingAjaxLink<Void>("createLink", getPageReference()) { private static final long serialVersionUID = -7978723352517770644L; @Override protected void onClickInternal(final AjaxRequestTarget target) { editModalWin.setPageCreator(new ModalWindow.PageCreator() { private static final long serialVersionUID = -7834632442532690940L; @Override public Page createPage() { return new EditUserModalPage(Users.this.getPageReference(), editModalWin, new UserTO()); } }); editModalWin.show(target); } }; MetaDataRoleAuthorizationStrategy.authorize(createLink, ENABLE, xmlRolesReader.getAllAllowedRoles("Users", "create")); add(createLink); setWindowClosedReloadCallback(editModalWin); final Form searchForm = new Form("searchForm"); add(searchForm); final UserSearchPanel searchPanel = new UserSearchPanel.Builder("searchPanel").build(); searchForm.add(searchPanel); final ClearIndicatingAjaxButton searchButton = new ClearIndicatingAjaxButton("search", new ResourceModel("search"), getPageReference()) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmitInternal(final AjaxRequestTarget target, final Form<?> form) { final String fiql = searchPanel.buildFIQL(); LOG.debug("FIQL: " + fiql); doSearch(target, fiql, searchResult); Session.get().getFeedbackMessages().clear(); searchPanel.getSearchFeedback().refresh(target); } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { searchPanel.getSearchFeedback().refresh(target); } }; searchForm.add(searchButton); searchForm.setDefaultButton(searchButton); }
From source file:org.artifactory.common.wicket.behavior.defaultbutton.DefaultButtonBehavior.java
License:Open Source License
@Override public void bind(Component component) { super.bind(component); if (!(component instanceof Form)) { throw new IllegalArgumentException( DefaultButtonBehavior.class.getSimpleName() + " can only be added to Form components."); }/*from www. j a v a 2 s . c o m*/ Form form = (Form) component; form.setDefaultButton(defaultButton); final Component button = (Component) defaultButton; button.add(new CssClass(new DefaultButtonStyleModel(button))); }
From source file:org.artifactory.webapp.wicket.page.base.BasePage.java
License:Open Source License
private void addSearchForm() { Form form = new SecureForm("searchForm") { @Override/*from w w w .j av a2s .co m*/ public boolean isVisible() { return isSignedInOrAnonymous(); } }; add(form); final TextField<String> searchTextField = new TextField<>("query", Model.of("")); form.add(searchTextField); TitledAjaxSubmitLink searchButton = new TitledAjaxSubmitLink("searchButton", "Search", form) { @Override protected void onSubmit(AjaxRequestTarget target, Form form) { String query = searchTextField.getDefaultModelObjectAsString(); //HttpServletRequest req = ((WebRequest) RequestCycle.get().getRequest()).getHttpServletRequest(); StringBuilder urlBuilder = new StringBuilder( WicketUtils.absoluteMountPathForPage(ArtifactSearchPage.class)); //StringBuilder urlBuilder = new StringBuilder(HttpUtils.getServletContextUrl(req)); //urlBuilder.append("/webapp/search/artifact"); if (StringUtils.isNotBlank(query)) { try { urlBuilder.append("?").append(BaseSearchPage.QUERY_PARAM).append("=") .append(URLEncoder.encode(query, "UTF-8")); } catch (UnsupportedEncodingException e) { log.error(String.format("Unable to append the Quick-Search query '%s'", query), e); } } throw new RedirectToUrlException(urlBuilder.toString()); } }; form.setDefaultButton(searchButton); form.add(searchButton); }
From source file:org.dcm4chee.web.war.tc.TCSearchPanel.java
License:LGPL
@SuppressWarnings({ "serial" }) public TCSearchPanel(final String id) { super(id, new Model<TCQueryFilter>(new TCQueryFilter())); setOutputMarkupId(true);/*from www .j a v a2s . c o m*/ final DateSpanSearchItem dateSpanItem = new DateSpanSearchItem(); final DateSpanDialog dateSpanDialog = new DateSpanDialog(dateSpanItem); final List<IDateSearchItem> dateItems = new ArrayList<IDateSearchItem>(); dateItems.addAll(Arrays.asList(NotOlderThanSearchItem.values())); dateItems.add(dateSpanItem); Form<?> dateSpanDialogOuterForm = new Form<Void>("date-input-dialog-outer-form"); dateSpanDialogOuterForm.setOutputMarkupId(true); dateSpanDialogOuterForm.setMarkupId("tc-search-date-input-form-helper"); dateSpanDialogOuterForm.add(dateSpanDialog); final TCInput keywordInput = TCUtilities.createInput("keywordInput", TCQueryFilterKey.Keyword, getFilterValue(TCQueryFilterKey.Keyword), true); final TCInput anatomyInput = TCUtilities.createInput("anatomyInput", TCQueryFilterKey.Anatomy, getFilterValue(TCQueryFilterKey.Anatomy), true); final TCInput pathologyInput = TCUtilities.createInput("pathologyInput", TCQueryFilterKey.Pathology, getFilterValue(TCQueryFilterKey.Pathology), true); final TCInput findingInput = TCUtilities.createInput("findingInput", TCQueryFilterKey.Finding, getFilterValue(TCQueryFilterKey.Finding), true); final TCInput diagnosisInput = TCUtilities.createInput("diagnosisInput", TCQueryFilterKey.Diagnosis, getFilterValue(TCQueryFilterKey.Diagnosis), true); final TCInput diffDiagnosisInput = TCUtilities.createInput("diffDiagnosisInput", TCQueryFilterKey.DifferentialDiagnosis, getFilterValue(TCQueryFilterKey.DifferentialDiagnosis), true); final TextField<String> textText = new TextField<String>("textText", new Model<String>("")); textText.add(new AutoSelectInputTextBehaviour()); final DropDownChoice<TCQueryFilterValue.AcquisitionModality> modalityChoice = TCUtilities .createDropDownChoice("modalityChoice", new Model<TCQueryFilterValue.AcquisitionModality>(), Arrays.asList(TCQueryFilterValue.AcquisitionModality.values()), NullDropDownItem.All); final DropDownChoice<TCQueryFilterValue.PatientSex> patientSexChoice = TCUtilities.createEnumDropDownChoice( "patientSexChoice", new Model<TCQueryFilterValue.PatientSex>(), Arrays.asList(TCQueryFilterValue.PatientSex.values()), true, "tc.patientsex", NullDropDownItem.All); final DropDownChoice<TCQueryFilterValue.Category> categoryChoice = TCUtilities.createEnumDropDownChoice( "categoryChoice", new Model<TCQueryFilterValue.Category>(), Arrays.asList(TCQueryFilterValue.Category.values()), true, "tc.category", NullDropDownItem.All); final DropDownChoice<TCQueryFilterValue.Level> levelChoice = TCUtilities.createEnumDropDownChoice( "levelChoice", new Model<TCQueryFilterValue.Level>(), Arrays.asList(TCQueryFilterValue.Level.values()), true, "tc.level", NullDropDownItem.All); final DropDownChoice<TCQueryFilterValue.YesNo> diagnosisConfirmedChoice = TCUtilities .createEnumDropDownChoice("diagnosisConfirmedChoice", new Model<TCQueryFilterValue.YesNo>(), Arrays.asList(TCQueryFilterValue.YesNo.values()), true, "tc.yesno", NullDropDownItem.All); final TCAjaxComboBox<IDateSearchItem> dateBox = new TCAjaxComboBox<IDateSearchItem>("dateChoice", dateItems, new IChoiceRenderer<IDateSearchItem>() { public String getIdValue(IDateSearchItem item, int index) { return item.getId(); } public String getDisplayValue(IDateSearchItem item) { return item.getLabel(getSession().getLocale()); } }) { @Override protected IDateSearchItem convertValue(String svalue) { if (TCUtilities.equals(dateSpanItem.getLabel(getSession().getLocale()), svalue)) { return dateSpanItem; } else { return NotOlderThanSearchItem.valueForLabel(svalue, getSession().getLocale()); } } @Override protected boolean shallCommitValue(IDateSearchItem oldValue, IDateSearchItem newValue, AjaxRequestTarget target) { if (dateSpanItem == newValue) { final Component c = this; dateSpanDialog.setWindowClosedCallback(new WindowClosedCallback() { @Override public void onClose(AjaxRequestTarget target) { target.appendJavascript( getDateBoxInitUIJavascript(c.getMarkupId(true), dateSpanItem, false)); } }); dateSpanDialog.show(target); return true; } return super.shallCommitValue(oldValue, newValue, target); } }; TCUtilities.addOnDomReadyJavascript(dateBox, getDateBoxInitUIJavascript(dateBox.getMarkupId(), dateSpanItem, true)); final RadioGroup<Option> optionGroup = new RadioGroup<Option>("optionGroup", new Model<Option>()); optionGroup.add(new Radio<Option>("historyOption", new Model<Option>(Option.History))); optionGroup.add(new Radio<Option>("authorNameOption", new Model<Option>(Option.AuthorName))); optionGroup.add(new Radio<Option>("authorContactOption", new Model<Option>(Option.AuthorContact))); optionGroup.add(new Radio<Option>("authorOrganisationOption", new Model<Option>(Option.AuthorAffiliation))); optionGroup.add(new Radio<Option>("discussionOption", new Model<Option>(Option.Discussion))); optionGroup.add(new Radio<Option>("titleOption", new Model<Option>(Option.Title))); optionGroup.add(new Radio<Option>("abstractOption", new Model<Option>(Option.Abstract))); optionGroup.add(new Radio<Option>("patientSpeciesOption", new Model<Option>(Option.PatientSpecies))); final AjaxButton searchBtn = new AjaxButton("doSearchBtn") { private static final long serialVersionUID = 1L; private IAjaxCallDecorator decorator; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { try { try { findParent(TCPanel.class).getPopupManager().hidePopups(target); } catch (Exception e) { log.error("Error while closing popups!", e); } TCQueryFilter filter = (TCQueryFilter) TCSearchPanel.this.getDefaultModelObject(); filter.clear(); filter.setKeywords(keywordInput.getValues()); if (showAdvancedOptions) { filter.setAnatomy(anatomyInput.getValue()); filter.setPathology(pathologyInput.getValue()); filter.setFinding(findingInput.getValue()); filter.setDiagnosis(diagnosisInput.getValue()); filter.setDiffDiagnosis(diffDiagnosisInput.getValue()); filter.setAcquisitionModality(modalityChoice.getModelObject()); filter.setPatientSex(patientSexChoice.getModelObject()); filter.setCategory(categoryChoice.getModelObject()); filter.setLevel(levelChoice.getModelObject()); YesNo yesNo = diagnosisConfirmedChoice.getModelObject(); if (YesNo.Yes.equals(yesNo)) { filter.setDiagnosisConfirmed(yesNo); } IDateSearchItem dateItem = dateBox.getModelObject(); if (dateItem == null) { filter.setCreationDate(null, null); } else { filter.setCreationDate(dateItem.getFromDate(), dateItem.getUntilDate()); } Option selectedOption = optionGroup.getModelObject(); if (selectedOption != null) { if (Option.History.equals(selectedOption)) { filter.setHistory(textText.getDefaultModelObjectAsString()); } else if (Option.AuthorName.equals(selectedOption)) { filter.setAuthorName(textText.getDefaultModelObjectAsString()); } else if (Option.AuthorContact.equals(selectedOption)) { filter.setAuthorContact(textText.getDefaultModelObjectAsString()); } else if (Option.AuthorAffiliation.equals(selectedOption)) { filter.setAuthorAffiliation(textText.getDefaultModelObjectAsString()); } else if (Option.Title.equals(selectedOption)) { filter.setTitle(textText.getDefaultModelObjectAsString()); } else if (Option.Abstract.equals(selectedOption)) { filter.setAbstract(textText.getDefaultModelObjectAsString()); } else if (Option.PatientSpecies.equals(selectedOption)) { filter.setPatientSpecies(textText.getDefaultModelObjectAsString()); } else if (Option.Discussion.equals(selectedOption)) { filter.setDiscussion(textText.getDefaultModelObjectAsString()); } } } Component[] toUpdate = doSearch(filter); if (toUpdate != null && target != null) { for (Component c : toUpdate) { target.addComponent(c); } } } catch (Throwable t) { log.error("Searching for teaching-files failed!", t); } } @Override public void onError(AjaxRequestTarget target, Form<?> form) { BaseForm.addInvalidComponentsToAjaxRequestTarget(target, form); } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { if (decorator == null) { decorator = new TCMaskingAjaxDecorator(false, true); } return decorator; } }; searchBtn.setOutputMarkupId(true); searchBtn.add(new Image("doSearchImg", ImageManager.IMAGE_COMMON_SEARCH) .add(new ImageSizeBehaviour("vertical-align: middle;"))); searchBtn.add(new Label("doSearchText", new ResourceModel("tc.search.dosearch.text")) .add(new AttributeModifier("style", true, new Model<String>("vertical-align: middle;"))) .setOutputMarkupId(true)); AjaxButton resetBtn = new AjaxButton("resetSearchBtn") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { TCQueryFilter filter = (TCQueryFilter) TCSearchPanel.this.getDefaultModelObject(); filter.clear(); keywordInput.setValues(); anatomyInput.setValues(); pathologyInput.setValues(); findingInput.setValues(); diagnosisInput.setValues(); diffDiagnosisInput.setValues(); modalityChoice.setModelObject(null); levelChoice.setModelObject(null); patientSexChoice.setModelObject(null); categoryChoice.setModelObject(null); diagnosisConfirmedChoice.setModelObject(null); dateBox.setModelObject(null); textText.setModelObject(null); optionGroup.setModelObject(null); target.addComponent(form); target.appendJavascript("initUI($('#" + TCSearchPanel.this.getMarkupId(true) + "'));"); } @Override public void onError(AjaxRequestTarget target, Form<?> form) { BaseForm.addInvalidComponentsToAjaxRequestTarget(target, form); } }; resetBtn.add(new Image("resetSearchImg", ImageManager.IMAGE_COMMON_RESET) .add(new ImageSizeBehaviour("vertical-align: middle;"))); resetBtn.add(new Label("resetSearchText", new ResourceModel("tc.search.reset.text")) .add(new AttributeModifier("style", true, new Model<String>("vertical-align: middle;")))); final WebMarkupContainer wmc = new WebMarkupContainer("advancedOptions"); wmc.setOutputMarkupPlaceholderTag(true); wmc.setOutputMarkupId(true); wmc.setVisible(false); wmc.add(anatomyInput.getComponent()); wmc.add(pathologyInput.getComponent()); wmc.add(findingInput.getComponent()); wmc.add(diagnosisInput.getComponent()); wmc.add(diffDiagnosisInput.getComponent()); wmc.add(modalityChoice); wmc.add(patientSexChoice); wmc.add(categoryChoice); wmc.add(levelChoice); wmc.add(diagnosisConfirmedChoice); wmc.add(dateBox); wmc.add(optionGroup); wmc.add(textText); wmc.add(resetBtn); final MarkupContainer advancedOptionsToggleLink = new AjaxFallbackLink<String>("advancedOptionsToggle") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { showAdvancedOptions = !showAdvancedOptions; wmc.setVisible(showAdvancedOptions); target.addComponent(wmc); target.addComponent(this); if (showAdvancedOptions) { target.appendJavascript("initUI($('#" + wmc.getMarkupId(true) + "'));"); } } }.add(new Label("advancedOptionsToggleText", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = -7928173606391768738L; @Override public String getObject() { return showAdvancedOptions ? getString("tc.search.advancedOptions.hide.Text") : getString("tc.search.advancedOptions.show.Text"); } })).add((new Image("advancedOptionsToggleImg", new AbstractReadOnlyModel<ResourceReference>() { private static final long serialVersionUID = 1L; @Override public ResourceReference getObject() { return showAdvancedOptions ? ImageManager.IMAGE_COMMON_COLLAPSE : ImageManager.IMAGE_COMMON_EXPAND; } })).add(new ImageSizeBehaviour())); advancedOptionsToggleLink.setOutputMarkupId(true); final Form<?> form = new Form<Object>("searchForm"); form.add(keywordInput.getComponent()); form.add(wmc); form.add(searchBtn); form.setDefaultButton(searchBtn); form.setOutputMarkupPlaceholderTag(true); form.add(advancedOptionsToggleLink); add(dateSpanDialogOuterForm); add(form); add(new AjaxFallbackLink<Object>("searchToggle") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { showSearch = !showSearch; form.setVisible(showSearch); target.addComponent(TCSearchPanel.this); if (showSearch) { target.appendJavascript("initUI($('#" + TCSearchPanel.this.getMarkupId(true) + "'));"); } } }.add((new Image("searchToggleImg", new AbstractReadOnlyModel<ResourceReference>() { private static final long serialVersionUID = 1L; @Override public ResourceReference getObject() { return showSearch ? ImageManager.IMAGE_COMMON_COLLAPSE : ImageManager.IMAGE_COMMON_EXPAND; } })).add(new ImageSizeBehaviour()))); }
From source file:org.efaps.ui.wicket.components.search.SearchPanel.java
License:Apache License
/** * Instantiates a new search panel.// w ww. ja va2 s.co m * * @param _wicketId the wicket id */ public SearchPanel(final String _wicketId) { super(_wicketId); boolean access = false; try { final Command cmd = Command .get(UUID.fromString(Configuration.getAttribute(ConfigAttribute.INDEXACCESSCMD))); access = cmd.hasAccess(TargetMode.VIEW, null); } catch (final EFapsException e) { LOG.error("Catched error during access control to index.", e); } this.setVisible(access); final Model<IndexSearch> searchModel = Model.of(new IndexSearch()); final ResultPanel resultPanel = new ResultPanel("result", searchModel); resultPanel.setOutputMarkupPlaceholderTag(true).setVisible(false); add(resultPanel); final Form<IndexSearch> form = new Form<>("form", searchModel); add(form); final TextField<String> input = new TextField<>("input", Model.of("")); input.setOutputMarkupId(true); input.add(new AttributeModifier("placeholder", DBProperties.getProperty(SearchPanel.class.getName() + ".Placeholder"))); form.add(input); final AjaxButton button = new AjaxButton("button") { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; @Override protected void onSubmit(final AjaxRequestTarget _target, final Form<?> _form) { super.onSubmit(_target, _form); final String query = (String) input.getDefaultModelObject(); if (StringUtils.isNotEmpty(query)) { final IndexSearch indexSearch = (IndexSearch) _form.getDefaultModelObject(); indexSearch.setCurrentQuery(query); indexSearch.search(); SearchPanel.this.visitChildren(ResultPanel.class, new IVisitor<Component, Void>() { @Override public void component(final Component _component, final IVisit<Void> _visit) { ((ResultPanel) _component).update(_target, indexSearch); } }); resultPanel.setVisible(true); _target.add(resultPanel); final StringBuilder js = new StringBuilder(); js.append("require(['dijit/TooltipDialog', 'dijit/popup', 'dojo/dom', 'dijit/registry',") .append("'dojo/_base/window', 'dojo/window', 'dojo/query',") .append("'dojo/dom-construct', 'dojo/NodeList-dom'],") .append("function(TooltipDialog, popup, dom, registry, baseWindow, win, ") .append(" query, domConstruct){\n").append("var rN = dom.byId('") .append(resultPanel.getMarkupId()).append("');\n") .append("var dialog = registry.byId(rN.id);") .append("if (typeof(dialog) !== \"undefined\") {\n").append("popup.close(dialog);") .append("registry.remove(dialog.id);").append("}\n").append("var vs = win.getBox();\n") .append("var wi = (vs.w - 100) + 'px';\n").append("var wh = (vs.h - 150) + 'px';\n") .append("query(\".searchOverlay\").forEach(domConstruct.destroy);\n") .append("var ov = domConstruct.create(\"div\", {'class' : 'searchOverlay'}, ") .append("baseWindow.body());\n") .append("query('.searchOverlay').on('click', function (e) {\n") .append("popup.close(registry.byId(rN.id));\n").append("});\n") .append("query(\".resultPlaceholder\", rN).style(\"width\", wi);\n") .append("query('.resultContainer', rN).style('height', wh);") .append("query('.resultClose', rN).on(\"click\", function(e){\n") .append("popup.close(registry.byId(rN.id));\n").append("});\n") .append("dialog = new TooltipDialog({}, rN);\n").append("popup.open({\n") .append("popup: dialog,") .append("orient: [ \"below-centered\", \"below-alt\", \"below\"],") .append("onClose: function(){\n") .append("query(\".searchOverlay\").forEach(domConstruct.destroy);\n").append("") .append("},\n").append("around: dom.byId('").append(form.getMarkupId()).append("')") .append("});").append("});"); _target.appendJavaScript(js); } } @Override public void onComponentTagBody(final MarkupStream _markupStream, final ComponentTag _openTag) { replaceComponentTagBody(_markupStream, _openTag, DBProperties.getProperty(SearchPanel.class.getName() + ".Button")); } }; form.add(button); form.setDefaultButton(button); }