List of usage examples for org.apache.wicket.markup.html.panel Fragment setRenderBodyOnly
public final Component setRenderBodyOnly(final boolean renderTag)
From source file:com.gitblit.wicket.pages.UserPage.java
License:Apache License
private void addPreferences(UserModel user) { // add preferences Form<Void> prefs = new Form<Void>("prefsForm"); List<Language> languages = getLanguages(); Locale locale = user.getPreferences().getLocale(); if (locale == null) { // user has not specified language preference // try server default preference String lc = app().settings().getString(Keys.web.forceDefaultLocale, null); if (StringUtils.isEmpty(lc)) { // server default language is not configured // try browser preference Locale sessionLocale = GitBlitWebSession.get().getLocale(); if (sessionLocale != null) { locale = sessionLocale;//from w w w . j a v a 2 s.c o m } } else { } } Language preferredLanguage = null; if (locale != null) { String localeCode = locale.getLanguage(); if (!StringUtils.isEmpty(locale.getCountry())) { localeCode += "_" + locale.getCountry(); } for (Language language : languages) { if (language.code.equals(localeCode)) { // language_COUNTRY match preferredLanguage = language; } else if (preferredLanguage != null && language.code.startsWith(locale.getLanguage())) { // language match preferredLanguage = language; } } } final IModel<String> displayName = Model.of(user.getDisplayName()); final IModel<String> emailAddress = Model.of(user.emailAddress == null ? "" : user.emailAddress); final IModel<Language> language = Model.of(preferredLanguage); final IModel<Boolean> emailMeOnMyTicketChanges = Model .of(user.getPreferences().isEmailMeOnMyTicketChanges()); final IModel<Transport> transport = Model.of(user.getPreferences().getTransport()); prefs.add(new TextOption("displayName", getString("gb.displayName"), getString("gb.displayNameDescription"), displayName).setVisible(app().authentication().supportsDisplayNameChanges(user))); prefs.add(new TextOption("emailAddress", getString("gb.emailAddress"), getString("gb.emailAddressDescription"), emailAddress) .setVisible(app().authentication().supportsEmailAddressChanges(user))); prefs.add(new ChoiceOption<Language>("language", getString("gb.languagePreference"), getString("gb.languagePreferenceDescription"), language, languages)); prefs.add(new BooleanOption("emailMeOnMyTicketChanges", getString("gb.emailMeOnMyTicketChanges"), getString("gb.emailMeOnMyTicketChangesDescription"), emailMeOnMyTicketChanges) .setVisible(app().notifier().isSendingMail())); List<Transport> availableTransports = new ArrayList<>(); if (app().services().isServingSSH()) { availableTransports.add(Transport.SSH); } if (app().services().isServingHTTP()) { availableTransports.add(Transport.HTTP); } if (app().services().isServingHTTPS()) { availableTransports.add(Transport.HTTPS); } if (app().services().isServingGIT()) { availableTransports.add(Transport.GIT); } prefs.add(new ChoiceOption<Transport>("transport", getString("gb.transportPreference"), getString("gb.transportPreferenceDescription"), transport, availableTransports)); prefs.add(new AjaxButton("save") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target) { UserModel user = GitBlitWebSession.get().getUser(); user.displayName = displayName.getObject(); user.emailAddress = emailAddress.getObject(); Language lang = language.getObject(); if (lang != null) { user.getPreferences().setLocale(lang.code); } user.getPreferences().setEmailMeOnMyTicketChanges(emailMeOnMyTicketChanges.getObject()); user.getPreferences().setTransport(transport.getObject()); try { app().gitblit().reviseUser(user.username, user); setResponsePage(UserPage.class, WicketUtils.newUsernameParameter(user.username)); } catch (GitBlitException e) { // logger.error("Failed to update user " + user.username, e); // error(getString("gb.failedToUpdateUser"), false); } } }); // add the preferences tab add(new Fragment("preferencesLink", "preferencesLinkFragment", this).setRenderBodyOnly(true)); Fragment fragment = new Fragment("preferencesTab", "preferencesTabFragment", UserPage.this); fragment.add(prefs); add(fragment.setRenderBodyOnly(true)); }
From source file:com.gitblit.wicket.pages.UserPage.java
License:Apache License
private void addSshKeys(final UserModel user) { Fragment keysTab = new Fragment("sshKeysTab", "sshKeysTabFragment", UserPage.this); keysTab.add(new SshKeysPanel("sshKeysPanel", user)); // add the SSH keys tab add(new Fragment("sshKeysLink", "sshKeysLinkFragment", UserPage.this).setRenderBodyOnly(true)); add(keysTab.setRenderBodyOnly(true)); }
From source file:com.gitblit.wicket.panels.RepositoryUrlPanel.java
License:Apache License
protected Fragment createPrimaryUrlPanel(String wicketId, final RepositoryModel repository, List<RepositoryUrl> repositoryUrls) { Fragment urlPanel = new Fragment(wicketId, "repositoryUrlFragment", RepositoryUrlPanel.this); urlPanel.setRenderBodyOnly(true); if (repositoryUrls.size() == 1) { ///* w w w .j a va 2s. c o m*/ // Single repository url, no dropdown menu // urlPanel.add(new Label("menu").setVisible(false)); } else { // // Multiple repository urls, show url drop down menu // ListDataProvider<RepositoryUrl> urlsDp = new ListDataProvider<RepositoryUrl>(repositoryUrls); DataView<RepositoryUrl> repoUrlMenuItems = new DataView<RepositoryUrl>("repoUrls", urlsDp) { private static final long serialVersionUID = 1L; @Override public void populateItem(final Item<RepositoryUrl> item) { RepositoryUrl repoUrl = item.getModelObject(); // repository url Fragment fragment = new Fragment("repoUrl", "actionFragment", RepositoryUrlPanel.this); Component content = new Label("content", repoUrl.url).setRenderBodyOnly(true); WicketUtils.setCssClass(content, "commandMenuItem"); fragment.add(content); item.add(fragment); Label permissionLabel = new Label("permission", repoUrl.hasPermission() ? repoUrl.permission.toString() : externalPermission); WicketUtils.setPermissionClass(permissionLabel, repoUrl.permission); String tooltip = getProtocolPermissionDescription(repository, repoUrl); WicketUtils.setHtmlTooltip(permissionLabel, tooltip); fragment.add(permissionLabel); fragment.add(createCopyFragment(repoUrl.url)); } }; Fragment urlMenuFragment = new Fragment("menu", "urlProtocolMenuFragment", RepositoryUrlPanel.this); urlMenuFragment.setRenderBodyOnly(true); urlMenuFragment.add(new Label("menuText", getString("gb.url"))); urlMenuFragment.add(repoUrlMenuItems); urlPanel.add(urlMenuFragment); } // access restriction icon and tooltip if (repository.isMirror) { urlPanel.add( WicketUtils.newImage("accessRestrictionIcon", "mirror_16x16.png", getString("gb.isMirror"))); } else if (app().services().isServingRepositories()) { switch (repository.accessRestriction) { case NONE: urlPanel.add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false)); break; case PUSH: urlPanel.add(WicketUtils.newImage("accessRestrictionIcon", "lock_go_16x16.png", getAccessRestrictions().get(repository.accessRestriction))); break; case CLONE: urlPanel.add(WicketUtils.newImage("accessRestrictionIcon", "lock_pull_16x16.png", getAccessRestrictions().get(repository.accessRestriction))); break; case VIEW: urlPanel.add(WicketUtils.newImage("accessRestrictionIcon", "shield_16x16.png", getAccessRestrictions().get(repository.accessRestriction))); break; default: if (repositoryUrls.size() == 1) { // force left end cap to have some width urlPanel.add(WicketUtils.newBlankIcon("accessRestrictionIcon")); } else { urlPanel.add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false)); } } } else { if (repositoryUrls.size() == 1) { // force left end cap to have some width urlPanel.add(WicketUtils.newBlankIcon("accessRestrictionIcon")); } else { urlPanel.add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false)); } } urlPanel.add(new Label("primaryUrl", primaryUrl.url).setRenderBodyOnly(true)); Label permissionLabel = new Label("primaryUrlPermission", primaryUrl.hasPermission() ? primaryUrl.permission.toString() : externalPermission); String tooltip = getProtocolPermissionDescription(repository, primaryUrl); WicketUtils.setHtmlTooltip(permissionLabel, tooltip); urlPanel.add(permissionLabel); urlPanel.add(createCopyFragment(primaryUrl.url)); return urlPanel; }
From source file:com.gitblit.wicket.panels.RepositoryUrlPanel.java
License:Apache License
protected Fragment createApplicationMenus(String wicketId, final UserModel user, final RepositoryModel repository, final List<RepositoryUrl> repositoryUrls) { final List<GitClientApplication> displayedApps = new ArrayList<GitClientApplication>(); final String userAgent = ((WebClientInfo) GitBlitWebSession.get().getClientInfo()).getUserAgent(); if (user.canClone(repository)) { for (GitClientApplication app : app().gitblit().getClientApplications()) { if (app.isActive && app.allowsPlatform(userAgent)) { displayedApps.add(app);//from w w w .j a v a2 s .co m } } } final String baseURL = WicketUtils.getGitblitURL(RequestCycle.get().getRequest()); ListDataProvider<GitClientApplication> displayedAppsDp = new ListDataProvider<GitClientApplication>( displayedApps); DataView<GitClientApplication> appMenus = new DataView<GitClientApplication>("appMenus", displayedAppsDp) { private static final long serialVersionUID = 1L; @Override public void populateItem(final Item<GitClientApplication> item) { final GitClientApplication clientApp = item.getModelObject(); // filter the urls for the client app List<RepositoryUrl> urls = new ArrayList<RepositoryUrl>(); for (RepositoryUrl repoUrl : repositoryUrls) { if (clientApp.minimumPermission == null || !repoUrl.hasPermission()) { // no minimum permission or untracked permissions, assume it is satisfactory if (clientApp.supportsTransport(repoUrl.url)) { urls.add(repoUrl); } } else if (repoUrl.permission.atLeast(clientApp.minimumPermission)) { // repo url meets minimum permission requirement if (clientApp.supportsTransport(repoUrl.url)) { urls.add(repoUrl); } } } if (urls.size() == 0) { // do not show this app menu because there are no urls item.add(new Label("appMenu").setVisible(false)); return; } Fragment appMenu = new Fragment("appMenu", "appMenuFragment", RepositoryUrlPanel.this); appMenu.setRenderBodyOnly(true); item.add(appMenu); // menu button appMenu.add(new Label("applicationName", clientApp.name)); // application icon Component img; if (StringUtils.isEmpty(clientApp.icon)) { img = WicketUtils.newClearPixel("applicationIcon").setVisible(false); } else { if (clientApp.icon.contains("://")) { // external image img = new ExternalImage("applicationIcon", clientApp.icon); } else { // context image img = WicketUtils.newImage("applicationIcon", clientApp.icon); } } appMenu.add(img); // application menu title, may be a link if (StringUtils.isEmpty(clientApp.productUrl)) { appMenu.add(new Label("applicationTitle", clientApp.toString())); } else { appMenu.add(new LinkPanel("applicationTitle", null, clientApp.toString(), clientApp.productUrl, true)); } // brief application description if (StringUtils.isEmpty(clientApp.description)) { appMenu.add(new Label("applicationDescription").setVisible(false)); } else { appMenu.add(new Label("applicationDescription", clientApp.description)); } // brief application legal info, copyright, license, etc if (StringUtils.isEmpty(clientApp.legal)) { appMenu.add(new Label("applicationLegal").setVisible(false)); } else { appMenu.add(new Label("applicationLegal", clientApp.legal)); } // a nested repeater for all action items ListDataProvider<RepositoryUrl> urlsDp = new ListDataProvider<RepositoryUrl>(urls); DataView<RepositoryUrl> actionItems = new DataView<RepositoryUrl>("actionItems", urlsDp) { private static final long serialVersionUID = 1L; @Override public void populateItem(final Item<RepositoryUrl> repoLinkItem) { RepositoryUrl repoUrl = repoLinkItem.getModelObject(); Fragment fragment = new Fragment("actionItem", "actionFragment", RepositoryUrlPanel.this); fragment.add(createPermissionBadge("permission", repoUrl)); if (!StringUtils.isEmpty(clientApp.cloneUrl)) { // custom registered url String url = substitute(clientApp.cloneUrl, repoUrl.url, baseURL, user.username, repository.name); fragment.add(new LinkPanel("content", "applicationMenuItem", getString("gb.clone") + " " + repoUrl.url, url)); repoLinkItem.add(fragment); fragment.add(new Label("copyFunction").setVisible(false)); } else if (!StringUtils.isEmpty(clientApp.command)) { // command-line String command = substitute(clientApp.command, repoUrl.url, baseURL, user.username, repository.name); Label content = new Label("content", command); WicketUtils.setCssClass(content, "commandMenuItem"); fragment.add(content); repoLinkItem.add(fragment); // copy function for command fragment.add(createCopyFragment(command)); } } }; appMenu.add(actionItems); } }; Fragment applicationMenus = new Fragment(wicketId, "applicationMenusFragment", RepositoryUrlPanel.this); applicationMenus.add(appMenus); return applicationMenus; }
From source file:gr.abiss.calipso.wicket.CustomFieldsFormPanel.java
License:Open Source License
@SuppressWarnings("serial") private void addComponents(final CompoundPropertyModel model, final Metadata metadata, final List<Field> fields, final Map<String, FileUploadField> fileUploadFields) { //final AbstractItem item = (AbstractItem) model.getObject(); List<FieldGroup> fieldGroupsList = metadata.getFieldGroups(); @SuppressWarnings("unchecked") ListView fieldGroups = new ListView("fieldGroups", fieldGroupsList) { @Override/* w w w. ja v a 2 s . co m*/ protected void populateItem(ListItem listItem) { FieldGroup fieldGroup = (FieldGroup) listItem.getModelObject(); listItem.add(new Label("fieldGroupLabel", fieldGroup.getName())); List<Field> groupFields = fieldGroup.getFields(); List<Field> editableGroupFields = new LinkedList<Field>(); if (CollectionUtils.isNotEmpty(groupFields)) { for (Field field : groupFields) { // is editable? if (fields.contains(field)) { editableGroupFields.add(field); } } } ListView listView = new ListView("fields", editableGroupFields) { @Override @SuppressWarnings("deprecation") protected void populateItem(ListItem listItem) { boolean preloadExistingValue = true; final Field field = (Field) listItem.getModelObject(); // preload custom attribute if (field.getCustomAttribute() == null) { field.setCustomAttribute(getCalipso().loadItemCustomAttribute(getCurrentSpace(), field.getName().getText())); } // preload value? if (preloadExistingValue) { AbstractItem history = (AbstractItem) model.getObject(); history.setValue(field.getName(), item.getValue(field.getName())); } // return the value for the field (see abstract item getCustomValue method) Object fieldLastCustomValue = null; String i18nedFieldLabelResourceKey = item.getSpace() .getPropertyTranslationResourceKey(field.getName().getText()); if (item != null && !editMode) { if (field.getName().isFile()) { Set<Attachment> tmpAttachments = item.getAttachments(); if (tmpAttachments != null && tmpAttachments.size() > 0) { for (Attachment attachment : tmpAttachments) { if (field.getLabel() .equals(AttachmentUtils.getBaseName(attachment.getFileName()))) { fieldLastCustomValue = attachment.getFileName(); break; } } } } else { fieldLastCustomValue = item.getValue(field.getName()); } } // Decide whether the field is mandatory boolean valueRequired = false; //logger.info("fieldLastCustomValue for field " + field.getLabel() +": "+fieldLastCustomValue); if (field.getMask() == State.MASK_MANDATORY || (field.getMask() == State.MASK_MANDATORY_IF_EMPTY && (fieldLastCustomValue == null || StringUtils.isBlank(fieldLastCustomValue.toString())))) { valueRequired = true; // value required } // go over custom fields WebMarkupContainer labelContainer = new WebMarkupContainer("labelContainer"); listItem.add(labelContainer); SimpleFormComponentLabel label = null; if (field.getName().isDropDownType()) { String autoValue; final Map<String, String> options = field.getOptions(); if (field.getFieldType().equals(Field.FIELD_TYPE_DROPDOWN_HIERARCHICAL)) { Fragment f = new Fragment("field", "treeField", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); ItemFieldCustomAttribute customAttribute = field.getCustomAttribute(); // if(customAttribute == null){ // customAttribute = getCalipso().loadCustomAttribute(getCurrentSpace(), field.getName().getText()); // field.setCustomAttribute(customAttribute); // } // preload existing value if (field.getCustomAttribute() != null && customAttribute.getLookupValue() == null && item.getCustomValue(field) != null) { logger.info("preloading custom attribute for field: " + field.getLabel()); customAttribute.setLookupValue(getCalipso().loadCustomAttributeLookupValue( NumberUtils.createLong(item.getCustomValue(field).toString()))); customAttribute.setAllowedLookupValues( getCalipso().findActiveLookupValuesByCustomAttribute(customAttribute)); } else { logger.info( "SKIPPED preloading custom attribute for field: " + field.getLabel()); customAttribute.setAllowedLookupValues( getCalipso().findActiveLookupValuesByCustomAttribute(customAttribute)); } TreeChoice choice = new TreeChoice("field", new PropertyModel<CustomAttributeLookupValue>(field, "customAttribute.lookupValue"), customAttribute.getAllowedLookupValues(), customAttribute); // TODO: temp, make configurable in space field form for 1520 int attrId = customAttribute.getId().intValue(); choice.setVisibleMenuLinks( attrId == 3 || attrId == 4 || attrId == 16 || attrId == 17); //choice.setType(Long.class); choice.setRequired(valueRequired); // i18n choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); WebMarkupContainer border = new WebMarkupContainer("border"); f.add(border); //border.add(new ErrorHighlighter(choice)); border.add(choice); //choice.setModel(model.bind(field.getName().getText())); //border.add(model.bind(choice, field.getName().getText())); listItem.add(f.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", choice); } // get the type of component that will render the choices else if (field.getFieldType().equals(Field.FIELD_TYPE_AUTOSUGGEST)) { renderAutoSuggest(model, listItem, field, i18nedFieldLabelResourceKey, valueRequired, options); } else { // normal drop down label = renderDropDown(model, listItem, field, i18nedFieldLabelResourceKey, valueRequired, options); } } else if (field.getName().equals(Field.Name.ASSIGNABLE_SPACES)) { Fragment f = new Fragment("field", "dropDown", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); List assignableSpaces = loadAssignableSpaces(field); final Map options = new LinkedHashMap(); // Replace value from space id to space description for // reasons of appearance. for (int i = 0; i < assignableSpaces.size(); i++) { Space space = (Space) assignableSpaces.get(i); if (!space.equals(getCurrentSpace())) { options.put(space.getId(), localize(space.getNameTranslationResourceKey())); } // if } // for final List keys = new ArrayList(options.keySet()); AssignableSpacesDropDownChoice choice = new AssignableSpacesDropDownChoice("field", keys, new IChoiceRenderer() { @Override public Object getDisplayValue(Object o) { return o; }; @Override public String getIdValue(Object o, int i) { return o.toString(); }; }); choice.setNullValid(true); // i18n choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); choice.setRequired(valueRequired); choice.add(new Behavior() { @Override public void renderHead(Component component, IHeaderResponse response) { response.renderJavaScript(new JavaScripts().setAssignableSpacesId.asString(), "setAssignableSpacesId"); } }); choice.add(new AjaxFormComponentUpdatingBehavior("onChange") { @Override protected void onUpdate(AjaxRequestTarget target) { if (statusChoice != null && !statusChoice.getDefaultModelObjectAsString().equals("") && !statusChoice.getDefaultModelObjectAsString().equals("-1")) { // if // (statusChoice.getValue().equals(String.valueOf(State.MOVE_TO_OTHER_SPACE))){ // assignedToChoice.setChoices(getAssignableSpaceUsers()); // assignedToChoice.setNullValid(false); // assignedToChoice.setVisible(true); // }//if } // if target.appendJavaScript("assignableSpacesId=" + "'" + assignableSpacesDropDownChoice.getMarkupId() + "';"); // This can happen at the creation of a new item // where makes no sense to be moved to other space if (assignedToChoice != null) { target.addComponent(assignedToChoice); } }// onUpdate @Override protected void onError(AjaxRequestTarget arg0, RuntimeException arg1) { // Do nothing. // It happens only if the choice be set to NULL by // the user. // The exception occurs because the model binds to // space id that is from (primitive) type // long and its value can not be set to NULL. } }); choice.setOutputMarkupId(true); assignableSpacesDropDownChoice = choice; if (itemViewFormPanel != null) { itemViewFormPanel.getItemViewForm() .setAssignableSpacesDropDownChoice(assignableSpacesDropDownChoice); } // if WebMarkupContainer border = new WebMarkupContainer("border"); f.add(border); border.add(new ErrorHighlighter(choice)); // Set field name explicitly to avoid runtime error //border.add(model.bind(choice, field.getName() + ".id")); choice.setModel(model.bind(field.getName() + ".id")); border.add(choice); listItem.add(f.setRenderBodyOnly(true)); border.setVisible(!CustomFieldsFormPanel.this.editMode); label = new SimpleFormComponentLabel("label", choice); } else if (field.getName().getType() == 6) { // date picker Fragment fragment = new Fragment("field", "dateFragment", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(fragment, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); if (item.getId() == 0 && item.getValue(field.getName()) == null && field.getDefaultValueExpression() != null && field.getDefaultValueExpression().equalsIgnoreCase("now")) { item.setValue(field.getName(), new Date()); } DateField calendar = new DateField("field", preloadExistingValue ? new PropertyModel(model.getObject(), field.getName().getText()) : new PropertyModel(model, field.getName().getText())) { @Override protected String getDateFormat() { // TODO Auto-generated method stub return metadata.getDateFormats().get(Metadata.DATE_FORMAT_SHORT); } }; calendar.setRequired(valueRequired); // i8n calendar.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); fragment.add(calendar); listItem.add(fragment.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", calendar); } // TODO: Creating new space item - users custom field else if (field.getName().isOrganization()) { // is organization // Get users list Fragment f = new Fragment("field", "dropDownFragment", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); Organization organization = (Organization) item.getValue(field.getName()); // logger.debug("Item organization field has value: "+organization); final List<Organization> allOrganizationsList = getCalipso().findAllOrganizations(); DropDownChoice organizationChoice = new DropDownChoice("field", allOrganizationsList, new IChoiceRenderer() { // user's choice renderer // display value user's name @Override public Object getDisplayValue(Object object) { return ((Organization) object).getName(); } @Override public String getIdValue(Object object, int index) { // id value user's id return index + ""; } }); organizationChoice.add(new ErrorHighlighter()); organizationChoice.setRequired(valueRequired); // i18n organizationChoice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); //f.add(model.bind(organizationChoice, field.getName().getText())); organizationChoice.setModel(model.bind(field.getName().getText())); f.add(organizationChoice); listItem.add(f.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", organizationChoice); } else if (field.getName().isFile()) { // File addFileInputField(model, fileUploadFields, listItem, field, i18nedFieldLabelResourceKey, valueRequired); } // TODO: Creating new space item - organizations custom field else if (field.getName().isUser()) { // is user Fragment f = new Fragment("field", "dropDownFragment", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); // find organization id from field's options String strOrgId = field.getOptions().get("organizationId"); Long orgId = Long.valueOf(strOrgId); // load organization from database Organization selectedOrg = getCalipso().loadOrganization(orgId); // TODO: load all users from organization // add new list of selected organizations List<Organization> selectedOrganization = new ArrayList<Organization>(); // add selected organization selectedOrganization.add(selectedOrg); final List<User> usersFromOrganization = getCalipso() .findUsersInOrganizations(selectedOrganization); // TODO: dropdown of all organization DropDownChoice usersFromOrganizationChoice = new DropDownChoice("field", usersFromOrganization, new UserChoiceRenderer()); usersFromOrganizationChoice.setNullValid(false); usersFromOrganizationChoice.setRequired(valueRequired); // i18n usersFromOrganizationChoice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); //f.add(model.bind(usersFromOrganizationChoice, field.getName().getText())); usersFromOrganizationChoice.setModel(model.bind(field.getName().getText())); f.add(usersFromOrganizationChoice); listItem.add(f.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", usersFromOrganizationChoice); } else if (field.getName().isCountry()) { // organization fragment holds a dropDown of countries final List<Country> allCountriesList = getCalipso().findAllCountries(); Fragment f = new Fragment("field", "dropDownFragment", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); listItem.add(f.setRenderBodyOnly(true)); DropDownChoice countryChoice = getCountriesDropDown("field", allCountriesList); countryChoice.add(new ErrorHighlighter()); countryChoice.setRequired(valueRequired); // i18n countryChoice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); //f.add(model.bind(countryChoice, field.getName().getText())); countryChoice.setModel(model.bind(field.getName().getText())); f.add(countryChoice); label = new SimpleFormComponentLabel("label", countryChoice); } else { if (logger.isDebugEnabled()) logger.debug("model.getObject(): " + model.getObject()); if (logger.isDebugEnabled()) logger.debug( "model.getObject().getClass(): " + model.getObject().getClass().getName()); if (logger.isDebugEnabled()) logger.debug("field.getName().getText(): " + field.getName().getText()); //if(logger.isDebugEnabled()) logger.debug("((Item)model.getObject()).getCusStr01(): "+((Item)model.getObject()).getCusStr01()); FormComponent textField; Fragment f; if (field.isMultivalue()) { f = new Fragment("field", "multipleValuesTextField", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); if (logger.isDebugEnabled()) logger.debug("model.getObject(): " + model.getObject()); if (logger.isDebugEnabled()) logger.debug("field.getName().getText(): " + field.getName().getText()); textField = preloadExistingValue ? new MultipleValuesTextField("field", new PropertyModel(model.getObject(), field.getName().getText()), field.getXmlConfig()) : new MultipleValuesTextField("field", field.getXmlConfig()); } else if (field.getLineCount() == 1) { f = new Fragment("field", "textField", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); textField = preloadExistingValue ? new TextField("field", new PropertyModel(model.getObject(), field.getName().getText())) : new TextField("field"); } else { f = new Fragment("field", "textareaField", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); textField = preloadExistingValue ? new TextArea("field", new PropertyModel(model.getObject(), field.getName().getText())) { @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.put("rows", field.getLineCount().toString()); } } : new TextArea("field") { @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.put("rows", field.getLineCount().toString()); } }; } // any validations for this field? ValidationExpression validationExpression = getCalipso() .loadValidationExpression(field.getValidationExpressionId()); if (validationExpression != null) { textField.add(new ValidationExpressionValidator(validationExpression)); } // TODO: do we need these two? if (field.getName().getType() == 4) { textField.setType(Double.class); } else if (field.getName().isDecimalNumber()) { textField.add(new PositiveNumberValidator()); } textField.add(new ErrorHighlighter()); textField.setRequired(valueRequired); // i18n textField.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); if (preloadExistingValue) { f.add(textField); } else { //f.add(model.bind(textField, field.getName().getText())); textField.setModel(model.bind(field.getName().getText())); f.add(textField); } // f.add(textField); listItem.add(f.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", textField); // styles FieldUtils.appendFieldStyles(field.getXmlConfig(), textField); } // add label labelContainer.add(label != null ? label : new Label("label", "")); if (field.getCustomAttribute() != null && StringUtils.isBlank(field.getCustomAttribute().getHtmlDescription())) { labelContainer.add(new SimpleAttributeModifier("class", "labelContainer")); } // mandatory? // mark as mandatory in the UI? labelContainer .add(new Label("star", valueRequired ? "* " : " ").setEscapeModelStrings(false)); } private SimpleFormComponentLabel renderAutoSuggest(final IModel model, ListItem listItem, final Field field, String i18nedFieldLabelResourceKey, boolean valueRequired, final Map<String, String> options) { SimpleFormComponentLabel label = null; Fragment f = new Fragment("field", "autoCompleteFragment", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); final List<String> autoKeys = new ArrayList<String>( options != null ? new ArrayList<String>(options.keySet()) : new ArrayList<String>()); // the autocomplet textField // TODO: fix to render values instead of integer AbstractAutoCompleteRenderer autoRenderer = new AbstractAutoCompleteRenderer() { @Override protected String getTextValue(Object object) { // TODO Auto-generated method stub return object.toString(); } @Override protected void renderChoice(Object object, Response response, String criteria) { response.write(object.toString()); } }; autoTextField = new AutoCompleteTextField("field", new PropertyModel(field, "customAttribute.lookupValue")) { // TODO: the list @Override protected Iterator<String> getChoices(String input) { if (Strings.isEmpty(input)) { List<String> emptyList = Collections.emptyList(); return emptyList.iterator(); } List<String> searchResults = new ArrayList<String>(); for (String s : options.values()) { if (s.startsWith(input)) { searchResults.add(s); } } return searchResults.iterator(); } }; autoTextField.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { // TODO Auto-generated method stub List<String> searchResults = new ArrayList<String>(); for (String s : options.values()) { if (s.startsWith((String) autoTextField.getModelObject())) { searchResults.add(s); } } target.addComponent(autoTextField); } }); // i18n autoTextField.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); String componentValue = (String) ((autoTextField != null && autoTextField.getModelObject() != null) ? autoTextField.getModelObject() : null); autoTextField.setRequired(valueRequired); WebMarkupContainer border = new WebMarkupContainer("border"); f.add(border); border.add(new ErrorHighlighter(autoTextField)); autoTextField.setModel(new PropertyModel(model.getObject(), field.getName().getText())); //border.add(model.bind(autoTextField, field.getName().getText())); border.add(autoTextField); if (logger.isDebugEnabled() && autoTextField != null && autoTextField.getDefaultModelObjectAsString() != null) { if (logger.isDebugEnabled()) logger.debug( "Auto complete value is :" + autoTextField.getDefaultModelObjectAsString()); } listItem.add(f.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", autoTextField); return label; // ------------------------- } private SimpleFormComponentLabel addFileInputField(final CompoundPropertyModel model, final Map<String, FileUploadField> fileUploadFields, ListItem listItem, final Field field, String i18nedFieldLabelResourceKey, boolean valueRequired) { SimpleFormComponentLabel label = null; Fragment f = new Fragment("field", "fileField", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); FileUploadField fileField = new FileUploadField("field"); fileUploadFields.put(field.getLabel(), fileField); fileField.add(new ErrorHighlighter()); fileField.setRequired(valueRequired); // i18n fileField.setLabel(new ResourceModel( StringUtils.isNotBlank(i18nedFieldLabelResourceKey) ? i18nedFieldLabelResourceKey : Field.FIELD_TYPE_SIMPLE_ATTACHEMENT));//field.getName().getText().equalsIgnoreCase(Field.FIELD_TYPE_SIMPLE_ATTACHEMENT) ? Field.FIELD_TYPE_SIMPLE_ATTACHEMENT : i18nedFieldLabelResourceKey)); //f.add(model.bind(fileField, field.getName().getText())); fileField.setModel(new Model()); // List<FileUpload> fileUploads = new LinkedList<FileUpload>(); f.add(fileField); listItem.add(f.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", fileField); return label; } /** * @param model * @param listItem * @param field * @param i18nedFieldLabelResourceKey * @param valueRequired * @param options */ private SimpleFormComponentLabel renderDropDown(final IModel model, ListItem listItem, final Field field, String i18nedFieldLabelResourceKey, boolean valueRequired, final Map<String, String> options) { SimpleFormComponentLabel label = null; /* final List<CustomAttributeLookupValue> lookupValues = getCalipso().findLookupValuesByCustomAttribute(field.getCustomAttribute()); TreeChoice choice = new TreeChoice("field", new PropertyModel(field, "customAttribute.lookupValue"), lookupValues); choice.setType(CustomAttributeLookupValue.class); //choice.setType(Long.class); choice.setRequired(valueRequired); // i18n choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); WebMarkupContainer border = new WebMarkupContainer("border"); f.add(border); //border.add(new ErrorHighlighter(choice)); border.add(choice); */ // drop down list final Fragment fragment = new Fragment("field", "dropDown", CustomFieldsFormPanel.this); if (field.getCustomAttribute() == null) { field.setCustomAttribute(getCalipso().loadItemCustomAttribute(getCurrentSpace(), field.getName().getText())); } // add HTML description through velocity logger.info("field name:" + field.getName() + ", custom atribute: " + field.getCustomAttribute()); addVelocityTemplatePanel(fragment, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute() != null ? field.getCustomAttribute().getHtmlDescription() : "", null, true); final List<CustomAttributeLookupValue> lookupValues = getCalipso() .findActiveLookupValuesByCustomAttribute(field.getCustomAttribute()); // preselect previous user choice from DB if available Object preselected = item.getValue(field.getName()); if (preselected != null) { String sPreselectedId = preselected.toString(); if (CollectionUtils.isNotEmpty(lookupValues)) { for (CustomAttributeLookupValue value : lookupValues) { if ((value.getId() + "").equals(sPreselectedId)) { field.getCustomAttribute().setLookupValue(value); break; } } } } // else set using the default string value instead, if any // TODO: move this into a LookupValueDropDownChoice class else { String defaultStringValue = field.getCustomAttribute() != null ? field.getCustomAttribute().getDefaultStringValue() : null; if (defaultStringValue != null && CollectionUtils.isNotEmpty(lookupValues)) { for (CustomAttributeLookupValue value : lookupValues) { if (value.getValue().equals(defaultStringValue)) { field.getCustomAttribute().setLookupValue(value); break; } } } } DropDownChoice choice = new DropDownChoice("field", new PropertyModel(field, "customAttribute.lookupValue"), lookupValues, new IChoiceRenderer<CustomAttributeLookupValue>() { @Override public Object getDisplayValue(CustomAttributeLookupValue o) { return fragment.getString(o.getNameTranslationResourceKey()); } @Override public String getIdValue(CustomAttributeLookupValue o, int index) { return String.valueOf(index); } }); choice.setNullValid(true); // i18n choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); choice.setRequired(valueRequired); WebMarkupContainer border = new WebMarkupContainer("border"); fragment.add(border); border.add(new ErrorHighlighter(choice)); //border.add(model.bind(choice, field.getName().getText())); border.add(choice); listItem.add(fragment.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", choice); return label; } /** * @param model * @param listItem * @param field * @param i18nedFieldLabelResourceKey * @param valueRequired * @param options */ private SimpleFormComponentLabel renderPeriodPartDropDown(final CompoundPropertyModel model, ListItem listItem, final Field field, String i18nedFieldLabelResourceKey, boolean valueRequired, final List<Date> options) { SimpleFormComponentLabel label = null; // drop down list Fragment f = new Fragment("field", "dropDown", CustomFieldsFormPanel.this); // add HTML description through velocity addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription", field.getCustomAttribute().getHtmlDescription(), null, true); DropDownChoice choice = new DropDownChoice("field", options, new IChoiceRenderer() { @Override public Object getDisplayValue(Object o) { return DateUtils.format((Date) o); }; @Override public String getIdValue(Object o, int i) { return String.valueOf(i); }; }); choice.setNullValid(true); // i18n choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey)); choice.setRequired(valueRequired); WebMarkupContainer border = new WebMarkupContainer("border"); f.add(border); border.add(new ErrorHighlighter(choice)); //border.add(model.bind(choice, field.getName().getText())); choice.setModel(model.bind(field.getName().getText())); border.add(choice); listItem.add(f.setRenderBodyOnly(true)); label = new SimpleFormComponentLabel("label", choice); return label; } }; if (editableGroupFields.isEmpty()) { listItem.setVisible(false); } listView.setReuseItems(true); listItem.add(listView.setRenderBodyOnly(true)); } }; add(fieldGroups.setReuseItems(true)); // }
From source file:info.jtrac.wicket.ItemListPanel.java
License:Apache License
public ItemListPanel(final String id, ItemSearch is) { super(id);// w ww .j a v a 2 s . c o m // this.itemSearch = getCurrentItemSearch(); this.itemSearch = is; LoadableDetachableModel itemListModel = new LoadableDetachableModel() { @Override protected Object load() { logger.debug("loading item list from database"); return getJtrac().findItems(itemSearch); } }; // hack - ensure that wicket model "attach" happens NOW before pagination logic sp that // itemSearch is properly initialized in the LoadableDetachableModel#load() above itemListModel.getObject(); //======================== PAGINATION ================================== int pageCount = 1; final int pageSize = itemSearch.getPageSize(); long resultCount = itemSearch.getResultCount(); if (pageSize != -1) { pageCount = (int) Math.ceil((double) resultCount / pageSize); } final int currentPage = itemSearch.getCurrentPage(); Link link = new Link("count") { @Override public void onClick() { // return to item search form itemSearch.setCurrentPage(0); setResponsePage(new ItemSearchFormPage(itemSearch)); } }; link.add(new Label("count", resultCount + "")); String resultCountMessage = resultCount == 1 ? "item_list.recordFound" : "item_list.recordsFound"; link.add(new Label("recordsFound", localize(resultCountMessage))); add(link); WebMarkupContainer pagination = new WebMarkupContainer("pagination"); if (pageCount > 1) { Link prevOn = new Link("prevOn") { @Override public void onClick() { itemSearch.setCurrentPage(currentPage - 1); // TODO avoid next line, refresh pagination only setResponsePage(new ItemListPage(itemSearch)); } }; prevOn.add(new Label("prevOn", "<<")); Label prevOff = new Label("prevOff", "<<"); if (currentPage == 0) { prevOn.setVisible(false); } else { prevOff.setVisible(false); } pagination.add(prevOn); pagination.add(prevOff); List<Integer> pageNumbers = new ArrayList<Integer>(pageCount); for (int i = 0; i < pageCount; i++) { pageNumbers.add(new Integer(i)); } ListView pages = new ListView("pages", pageNumbers) { @Override protected void populateItem(ListItem listItem) { final Integer i = (Integer) listItem.getModelObject(); String pageNumber = i + 1 + ""; Link pageOn = new Link("pageOn") { @Override public void onClick() { itemSearch.setCurrentPage(i); // TODO avoid next line, refresh pagination only setResponsePage(new ItemListPage(itemSearch)); } }; pageOn.add(new Label("pageOn", pageNumber)); Label pageOff = new Label("pageOff", pageNumber); if (i == currentPage) { pageOn.setVisible(false); } else { pageOff.setVisible(false); } listItem.add(pageOn); listItem.add(pageOff); } }; pagination.add(pages); Link nextOn = new Link("nextOn") { @Override public void onClick() { itemSearch.setCurrentPage(currentPage + 1); // TODO avoid next line, refresh pagination only setResponsePage(new ItemListPage(itemSearch)); } }; nextOn.add(new Label("nextOn", ">>")); Label nextOff = new Label("nextOff", ">>"); if (currentPage == pageCount - 1) { nextOn.setVisible(false); } else { nextOff.setVisible(false); } pagination.add(nextOn); pagination.add(nextOff); } else { // if pageCount == 1 pagination.setVisible(false); } add(pagination); //========================== XML EXPORT ================================ add(new Link("exportToXml") { @Override public void onClick() { getRequestCycle().setRequestTarget(new IRequestTarget() { @Override public void respond(RequestCycle requestCycle) { WebResponse r = (WebResponse) requestCycle.getResponse(); r.setAttachmentHeader("jtrac-export.xml"); getJtrac().writeAsXml(itemSearch, new OutputStreamWriter(r.getOutputStream())); } @Override public void detach(RequestCycle requestCycle) { } }); } }); //========================== EXCEL EXPORT ============================== add(new Link("exportToExcel") { @Override public void onClick() { // temporarily switch off paging of results itemSearch.setPageSize(-1); final ExcelUtils eu = new ExcelUtils(getJtrac().findItems(itemSearch), itemSearch); // restore page size itemSearch.setPageSize(pageSize); getRequestCycle().setRequestTarget(new IRequestTarget() { @Override public void respond(RequestCycle requestCycle) { WebResponse r = (WebResponse) requestCycle.getResponse(); r.setAttachmentHeader("jtrac-export.xls"); try { Map<Name, String> labels = BasePage.getLocalizedLabels(ItemListPanel.this); eu.exportToExcel(labels).write(r.getOutputStream()); } catch (IOException e) { throw new RuntimeException(e); } } @Override public void detach(RequestCycle requestCycle) { } }); } }); //====================== HEADER ======================================== final List<ColumnHeading> columnHeadings = itemSearch.getColumnHeadingsToRender(); ListView headings = new ListView("headings", columnHeadings) { @Override protected void populateItem(ListItem listItem) { final ColumnHeading ch = (ColumnHeading) listItem.getModelObject(); Link headingLink = new Link("heading") { @Override public void onClick() { doSort(ch.getNameText()); } }; listItem.add(headingLink); String label = ch.isField() ? ch.getLabel() : localize("item_list." + ch.getName()); headingLink.add(new Label("heading", label)); if (ch.getNameText().equals(itemSearch.getSortFieldName())) { String order = itemSearch.isSortDescending() ? "order-down" : "order-up"; listItem.add(new SimpleAttributeModifier("class", order)); } } }; add(headings); //======================== ITEMS ======================================= final long selectedItemId = itemSearch.getSelectedItemId(); final SimpleAttributeModifier sam = new SimpleAttributeModifier("class", "alt"); ListView itemList = new ListView("itemList", itemListModel) { @Override protected void populateItem(ListItem listItem) { // cast to AbstactItem - show history may be == true final AbstractItem item = (AbstractItem) listItem.getModelObject(); if (selectedItemId == item.getId()) { listItem.add(new SimpleAttributeModifier("class", "selected")); } else if (listItem.getIndex() % 2 == 1) { listItem.add(sam); } final boolean showHistory = itemSearch.isShowHistory(); ListView fieldValues = new ListView("columns", columnHeadings) { @Override protected void populateItem(ListItem listItem) { ColumnHeading ch = (ColumnHeading) listItem.getModelObject(); IModel value = null; if (ch.isField()) { value = new Model(item.getCustomValue(ch.getField().getName())); } else { switch (ch.getName()) { case ID: String refId = item.getRefId(); Fragment refIdFrag = new Fragment("column", "refId", ItemListPanel.this); refIdFrag.setRenderBodyOnly(true); listItem.add(refIdFrag); Link refIdLink = new BookmarkablePageLink("refId", ItemViewPage.class, new PageParameters("0=" + refId)); refIdFrag.add(refIdLink); refIdLink.add(new Label("refId", refId)); if (showHistory) { int index = ((History) item).getIndex(); if (index > 0) { refIdFrag.add(new Label("index", " (" + index + ")")); } else { refIdFrag.add(new WebMarkupContainer("index").setVisible(false)); } } else { refIdFrag.add(new WebMarkupContainer("index").setVisible(false)); } // the first column ID is a special case, where we add a fragment. // since we have already added a fragment return, instead of "break" // so avoid going to the new Label("column", value) after the switch case return; case SUMMARY: value = new PropertyModel(item, "summary"); break; case DETAIL: if (showHistory) { Fragment detailFrag = new Fragment("column", "detail", ItemListPanel.this); final History history = (History) item; detailFrag.add(new AttachmentLinkPanel("attachment", history.getAttachment())); if (history.getIndex() > 0) { detailFrag.add(new Label("detail", new PropertyModel(history, "comment"))); } else { detailFrag.add(new Label("detail", new PropertyModel(history, "detail"))); } listItem.add(detailFrag); return; } else { value = new PropertyModel(item, "detail"); } break; case LOGGED_BY: value = new PropertyModel(item, "loggedBy.name"); break; case STATUS: value = new PropertyModel(item, "statusValue"); break; case ASSIGNED_TO: value = new PropertyModel(item, "assignedTo.name"); break; case TIME_STAMP: value = new Model(DateUtils.formatTimeStamp(item.getTimeStamp())); break; case SPACE: if (showHistory) { value = new PropertyModel(item, "parent.space.name"); } else { value = new PropertyModel(item, "space.name"); } break; default: throw new RuntimeException("Unexpected name: '" + ch.getName() + "'"); } } Label label = new Label("column", value); label.setRenderBodyOnly(true); listItem.add(label); } }; listItem.add(fieldValues); } }; add(itemList); }
From source file:org.apache.syncope.client.console.panels.RealmDetails.java
License:Apache License
public RealmDetails(final String id, final RealmTO realmTO, final ActionLinksPanel<?> actions, final boolean unwrapped) { super(id);/* w w w . j a v a 2s .c o m*/ container = new WebMarkupContainer("container"); container.setOutputMarkupId(true); container.setRenderBodyOnly(unwrapped); add(container); final WebMarkupContainer generics = new WebMarkupContainer("generics"); container.add(generics.setVisible(unwrapped)); FieldPanel<String> name = new AjaxTextFieldPanel("name", "name", new PropertyModel<String>(realmTO, "name"), false); name.addRequiredLabel(); generics.add(name); FieldPanel<String> fullPath = new AjaxTextFieldPanel("fullPath", "fullPath", new PropertyModel<String>(realmTO, "fullPath"), false); fullPath.setEnabled(false); generics.add(fullPath); AjaxDropDownChoicePanel<String> accountPolicy = new AjaxDropDownChoicePanel<>("accountPolicy", new ResourceModel("accountPolicy", "accountPolicy").getObject(), new PropertyModel<String>(realmTO, "accountPolicy"), false); accountPolicy.setChoiceRenderer(new PolicyRenderer(accountPolicies)); accountPolicy.setChoices(new ArrayList<>(accountPolicies.getObject().keySet())); ((DropDownChoice<?>) accountPolicy.getField()).setNullValid(true); container.add(accountPolicy); AjaxDropDownChoicePanel<String> passwordPolicy = new AjaxDropDownChoicePanel<>("passwordPolicy", new ResourceModel("passwordPolicy", "passwordPolicy").getObject(), new PropertyModel<String>(realmTO, "passwordPolicy"), false); passwordPolicy.setChoiceRenderer(new PolicyRenderer(passwordPolicies)); passwordPolicy.setChoices(new ArrayList<>(passwordPolicies.getObject().keySet())); ((DropDownChoice<?>) passwordPolicy.getField()).setNullValid(true); container.add(passwordPolicy); AjaxPalettePanel<String> actionsClassNames = new AjaxPalettePanel.Builder<String>().setAllowMoveAll(true) .setAllowOrder(true).build("actionsClassNames", new PropertyModel<List<String>>(realmTO, "actionsClassNames"), new ListModel<>(logicActionsClasses.getObject())); actionsClassNames.setOutputMarkupId(true); container.add(actionsClassNames); container.add(new AjaxPalettePanel.Builder<String>() .build("resources", new PropertyModel<List<String>>(realmTO, "resources"), new ListModel<>(CollectionUtils.collect(new ResourceRestClient().list(), EntityTOUtils.<ResourceTO>keyTransformer(), new ArrayList<String>()))) .setOutputMarkupId(true).setEnabled(!SyncopeConstants.ROOT_REALM.equals(realmTO.getName())) .setVisible(!SyncopeConstants.ROOT_REALM.equals(realmTO.getName()))); if (actions == null) { add(new Fragment("actions", "emptyFragment", this).setRenderBodyOnly(true)); } else { Fragment fragment = new Fragment("actions", "actionsFragment", this); fragment.add(actions); add(fragment.setRenderBodyOnly(true)); } }
From source file:org.apache.syncope.client.console.wicket.markup.html.form.AbstractMultiPanel.java
License:Apache License
private Fragment getPlusFragment(final IModel<List<INNER>> model, final String label) { final IndicatorAjaxSubmitLink plus = new IndicatorAjaxSubmitLink("add") { private static final long serialVersionUID = -7978723352517770644L; @Override//from w ww. java 2 s . co m protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { //Add current component model.getObject().add(newModelObject()); if (model.getObject().size() == 1) { form.addOrReplace(getDataFragment()); } target.add(container); } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { SyncopeConsoleSession.get().error(getString(Constants.OPERATION_ERROR)); super.onError(target, form); ((BasePage) getPage()).getNotificationPanel().refresh(target); } }; final Fragment fragment = new Fragment("panelPlus", "fragmentPlus", AbstractMultiPanel.this); fragment.addOrReplace(plus); fragment.setRenderBodyOnly(true); return fragment; }
From source file:org.sakaiproject.sitestats.tool.wicket.components.AjaxLazyLoadFragment.java
License:Educational Community License
/** * @param id//ww w .j a v a 2s. c o m */ public AjaxLazyLoadFragment(final String id) { super(id); setOutputMarkupId(true); final AbstractDefaultAjaxBehavior behavior = new AbstractDefaultAjaxBehavior() { @Override protected void respond(AjaxRequestTarget target) { Fragment fragment = getLazyLoadFragment("content"); AjaxLazyLoadFragment.this.replace(fragment.setRenderBodyOnly(true)); target.add(AjaxLazyLoadFragment.this); setState((byte) 2); } @Override public void renderHead(Component component, IHeaderResponse response) { response.render(OnDomReadyHeaderItem.forScript(getCallbackScript().toString())); super.renderHead(component, response); } @Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); attributes.setChannel(new AjaxChannel(getId())); } @Override public boolean isEnabled(Component component) { return state < 2; } }; add(behavior); }