001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.extensions.ajax.markup.html.repeater.data.sort; 018 019import org.apache.wicket.ajax.AjaxEventBehavior; 020import org.apache.wicket.ajax.AjaxRequestTarget; 021import org.apache.wicket.ajax.attributes.AjaxRequestAttributes; 022import org.apache.wicket.ajax.markup.html.IAjaxLink; 023import org.apache.wicket.extensions.markup.html.repeater.data.sort.ISortStateLocator; 024import org.apache.wicket.extensions.markup.html.repeater.data.sort.OrderByLink; 025 026 027/** 028 * Ajaxified {@link OrderByLink} 029 * 030 * @param <S> 031 * the type of the sort property 032 * @see OrderByLink 033 */ 034public abstract class AjaxOrderByLink<S> extends OrderByLink<S> implements IAjaxLink 035{ 036 /** 037 * 038 */ 039 private static final long serialVersionUID = 1L; 040 041 /** 042 * Constructor 043 * 044 * @param id 045 * @param sortProperty 046 * @param stateLocator 047 */ 048 public AjaxOrderByLink(final String id, final S sortProperty, 049 final ISortStateLocator<S> stateLocator) 050 { 051 super(id, sortProperty, stateLocator); 052 } 053 054 @Override 055 public void onInitialize() 056 { 057 super.onInitialize(); 058 059 add(newAjaxEventBehavior("click")); 060 } 061 062 /** 063 * @param event 064 * the name of the default event on which this link will listen to 065 * @return the ajax behavior which will be executed when the user clicks the link 066 */ 067 protected AjaxEventBehavior newAjaxEventBehavior(final String event) 068 { 069 return new AjaxEventBehavior(event) 070 { 071 private static final long serialVersionUID = 1L; 072 073 @Override 074 protected void onEvent(final AjaxRequestTarget target) 075 { 076 onClick(); 077 AjaxOrderByLink.this.onClick(target); 078 } 079 080 @Override 081 protected void updateAjaxAttributes(AjaxRequestAttributes attributes) 082 { 083 super.updateAjaxAttributes(attributes); 084 attributes.setPreventDefault(true); 085 086 AjaxOrderByLink.this.updateAjaxAttributes(attributes); 087 } 088 }; 089 } 090 091 protected void updateAjaxAttributes(AjaxRequestAttributes attributes) 092 { 093 } 094 095 /** 096 * Callback method when an ajax click occurs. All the behavior of changing the sort, etc is 097 * already performed before this is called so this method should primarily be used to configure 098 * the target. 099 * 100 * @param target 101 */ 102 @Override 103 public abstract void onClick(AjaxRequestTarget target); 104 105}