/** * Copyright 2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.bricket.plugin.user_picture.web; import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.AjaxLink; import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn; import org.apache.wicket.markup.repeater.Item; import org.apache.wicket.model.IModel; import org.apache.wicket.model.StringResourceModel; import org.apache.wicket.spring.injection.annot.SpringBean; import org.bricket.plugin.user_picture.domain.UserPicture; import org.bricket.plugin.user_picture.service.UserPictureService; import org.bricket.web.BricketPanel; import org.bricket.web.common.ActionPanelBuilder; import org.bricket.web.common.DeleteActionLink; import org.bricket.web.common.EditActionLink; import org.bricket.web.common.table.AjaxFallbackDefaultDataTableBuilder; /** * @author Ingo Renner * @author Henning Teek * */ public class ManageUserPicturesPanel extends BricketPanel { @SpringBean private UserPictureService userPictureService; public ManageUserPicturesPanel(String id) { super(id); } @Override protected void initGui() { add(getUserPicturesTable("table")); add(new AjaxLink<Void>("create") { @Override public void onClick(AjaxRequestTarget target) { // feedback getSession().cleanupFeedbackMessages(); target.addComponent(getFeedback()); // create CreateUserPicturePanel create = new CreateUserPicturePanel(ManageUserPicturesPanel.this.getId(), getUser()); ManageUserPicturesPanel.this.getParent().addOrReplace(create.setOutputMarkupId(true)); target.addComponent(create); } }); } @SuppressWarnings("unchecked") private Component getUserPicturesTable(String id) { return AjaxFallbackDefaultDataTableBuilder .getBuilder(ManageUserPicturesPanel.this) .addDataProvider(new UserPictureDataProvider(getUser())) .add(new AbstractColumn(new StringResourceModel("picture.actions.label", ManageUserPicturesPanel.this, null)) { @Override public void populateItem(Item cellItem, String componentId, IModel rowModel) { final ActionPanelBuilder linkBuilder = ActionPanelBuilder.getBuilder(); final UserPicture userPicture = (UserPicture) rowModel.getObject(); // edit link linkBuilder.add(new EditActionLink(true) { @Override public void onClick(AjaxRequestTarget target) { // feedback getSession().cleanupFeedbackMessages(); target.addComponent(getFeedback()); // edit EditUserPicturePanel edit = new EditUserPicturePanel(ManageUserPicturesPanel.this .getId(), userPicture); ManageUserPicturesPanel.this.getParent().addOrReplace(edit.setOutputMarkupId(true)); target.addComponent(edit); } }); DeleteActionLink removeLink = new DeleteActionLink(new StringResourceModel( "picture.actions.delete.confirm", ManageUserPicturesPanel.this, null), true) { @Override public void onClick(AjaxRequestTarget target) { // feedback getSession().cleanupFeedbackMessages(); target.addComponent(getFeedback()); // delete userPictureService.deleteUserPicture(userPicture); // manage ManageUserPicturesPanel manage = new ManageUserPicturesPanel( ManageUserPicturesPanel.this.getId()); ManageUserPicturesPanel.this.getParent().addOrReplace(manage.setOutputMarkupId(true)); target.addComponent(manage); } }; linkBuilder.add(removeLink); cellItem.add(linkBuilder.build(componentId)); } }).addThumbnailImagePropertyColumn("picture", true).addPropertyColumn("picture.title", true) .addPropertyColumn("picture.description", true).setNumberOfRows(10).build(id); } }