/**
* 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_gallery.web;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
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_gallery.domain.UserGallery;
import org.bricket.plugin.user_gallery.service.UserGalleryService;
import org.bricket.service.BricketServiceException;
import org.bricket.web.BricketManagePanel;
import org.bricket.web.common.ActionPanelBuilder;
import org.bricket.web.common.DeleteActionLink;
import org.bricket.web.common.EditActionBricketLink;
import org.bricket.web.common.table.AjaxFallbackDefaultDataTableBuilder;
import brix.jcr.wrapper.BrixNode;
import brix.web.nodepage.BrixPageParameters;
/**
* @author Ingo Renner
* @author Henning Teek
*
*/
public class ManageUserGalleriesPanel extends BricketManagePanel {
@SpringBean
private UserGalleryService userGalleryService;
public ManageUserGalleriesPanel(String id, IModel<BrixNode> tileNode) {
super(id, tileNode);
}
@Override
protected Component getTable(final String id) {
return AjaxFallbackDefaultDataTableBuilder
.getBuilder(ManageUserGalleriesPanel.this)
.addDataProvider(new UserGalleryDataProvider(getUser()))
.add(new AbstractColumn<Object>(new StringResourceModel("actions.label", ManageUserGalleriesPanel.this,
null)) {
@Override
public void populateItem(Item<ICellPopulator<Object>> cellItem, String componentId,
IModel<Object> rowModel) {
final ActionPanelBuilder linkBuilder = ActionPanelBuilder.getBuilder();
final UserGallery userGallery = (UserGallery) rowModel.getObject();
// edit link
linkBuilder.add(new EditActionBricketLink(getConfig().getUrlBrixNodeModel()) {
@Override
protected void constructUrl(BrixPageParameters params) {
params.setQueryParam(UserGalleryPageParameterDefinition.USER_GALLERY_PAGE_PARAMETER,
userGallery.getId());
}
});
DeleteActionLink removeLink = new DeleteActionLink(new StringResourceModel(
"gallery.actions.delete.confirm", ManageUserGalleriesPanel.this, null), true) {
@Override
public void onClick(AjaxRequestTarget target) {
try {
// feedback
getSession().cleanupFeedbackMessages();
target.addComponent(getFeedback());
// delete
userGalleryService.deleteUserGallery(userGallery);
// manage
Component table = getTable(id);
ManageUserGalleriesPanel.this.addOrReplace(table);
target.addComponent(table);
} catch (BricketServiceException e) {
error(new StringResourceModel(e.getKey(), ManageUserGalleriesPanel.this, null)
.getString());
target.addComponent(getFeedback());
}
}
};
linkBuilder.add(removeLink);
cellItem.add(linkBuilder.build(componentId));
}
}).addPropertyColumn("gallery.title", true).addPropertyColumn("gallery.description", true)
.setNumberOfRows(10).build(id);
}
}