All pastes #486397 Raw Edit

Mine

public java v1 · immutable
·published 2007-05-13 21:43 UTC
rendered paste body
package com.optsystem.page.rank;import java.text.DateFormat;import java.util.List;import java.util.Locale;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.wicket.Component;import org.apache.wicket.ajax.AjaxEventBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;import org.apache.wicket.markup.html.basic.Label;import org.apache.wicket.markup.html.form.Button;import org.apache.wicket.markup.html.form.ChoiceRenderer;import org.apache.wicket.markup.html.form.DropDownChoice;import org.apache.wicket.markup.html.list.ListItem;import org.apache.wicket.markup.html.list.ListView;import org.apache.wicket.markup.html.panel.Panel;import org.apache.wicket.model.Model;import org.apache.wicket.model.PropertyModel;import org.apache.wicket.spring.injection.annot.SpringBean;import org.apache.wicket.util.convert.IConverter;import org.apache.wicket.util.convert.converters.DateConverter;import com.optsystem.model.Rank;import com.optsystem.model.RankItem;import com.optsystem.model.Website;import com.optsystem.page.OptSystemPage;import com.optsystem.service.RankService;import com.optsystem.service.WebsiteService;public class RankReportPage extends OptSystemPage {	private static final Log log = LogFactory.getLog(RankReportPage.class);		@SpringBean	private WebsiteService websiteService;		@SpringBean	private RankService rankService;		private Website website;	private final List<Rank> ranks;	private Rank selectedRank;	public RankReportPage(Long websiteId){		super();		this.website = websiteService.find(websiteId);		this.ranks = rankService.getRanksForWebsite(websiteId);		this.selectedRank = ranks.isEmpty()?null:ranks.get(0);				setOutputMarkupId(true);		//Label showing the website's name		add( new Label("websiteName",website.getUrl()));				//DateConverter		final IConverter dateConverter = new DateConverter(){			@Override			public DateFormat getDateFormat(Locale locale){				return DateFormat.getDateTimeInstance(						DateFormat.SHORT, 						DateFormat.SHORT,						locale);			}		};				//Label showing the selected date we're viewing a report for		final Label rankDateLabel = new Label("rankDate", new PropertyModel(RankReportPage.this,"selectedRank.rankDate")){			public IConverter getConverter(Class type){				return dateConverter;			}		};		rankDateLabel.setOutputMarkupId(true);		add( rankDateLabel );		//Had to put it in a panel because Ajax can't update ListView		final RankTablePanel rankTablePanel = new RankTablePanel("rankTablePanel");		rankTablePanel.setOutputMarkupId(true);		add( rankTablePanel );				//Dropdown letting you choose between dates		final DropDownChoice rankDates = new DropDownChoice("rankDates",									new PropertyModel(this,"selectedRank"),									new PropertyModel(this,"ranks"),									new ChoiceRenderer("rankDate","id")){				@Override				public IConverter getConverter(Class type){					return dateConverter;				}					};		rankDates.add( new AjaxFormComponentUpdatingBehavior("onchange"){			@Override			protected void onUpdate(AjaxRequestTarget target) {				target.addComponent(rankDateLabel);				target.addComponent(rankTablePanel);			}					});		rankDates.setOutputMarkupId(true);		add( rankDates );						//Button to create a new rank		final Button rankButton = new Button("rankButton");		rankButton.add(new AjaxEventBehavior("onclick"){			@Override			protected void onEvent(AjaxRequestTarget target) {								Rank rank = rankService.rankWebsite(website);								//Must do this, since Wicket has no way to know the model actually changed since its internal to the list				RankReportPage.this.modelChanging();				ranks.add(rank);				RankReportPage.this.modelChanged();								selectedRank = rank;												target.addComponent(rankButton);				target.addComponent(rankTablePanel);				target.addComponent(rankDates);				target.addComponent(rankDateLabel);			}					});		rankButton.setOutputMarkupId(true);		add(rankButton);			}	public void setWebsiteService(WebsiteService websiteService) {		this.websiteService = websiteService;	}	public void setRankService(RankService rankService) {		this.rankService = rankService;	}		class RankTablePanel extends Panel{		public RankTablePanel(String componentId){			super( componentId );			//Table showing the rankings for a specific date			final ListView rankTable = new ListView("rankTable",new PropertyModel(RankReportPage.this,"selectedRank.rankItems")){				@Override				protected void populateItem(ListItem item) {					RankItem ri = (RankItem) item.getModelObject();					item.add( new Label("keyword",ri.getKeyword()));					item.add( new Label("google",new Model(ri.getGoogle())));					item.add( new Label("msn",new Model(ri.getMsn())));					item.add( new Label("yahoo",new Model(ri.getYahoo())));					item.add( new Label("aol",new Model(ri.getAol())));					item.add( new Label("altavista",new Model(ri.getAltaVista())));					item.add( new Label("alltheweb",new Model(ri.getAllTheWeb())));									item.add( new Label("teoma",new Model(ri.getTeoma())));				}							};			add( rankTable );		}	}	public List<Rank> getRanks() {		return ranks;	}	public Rank getSelectedRank() {		return selectedRank;	}	public void setSelectedRank(Rank selectedRank) {		this.selectedRank = selectedRank;	}	public Website getWebsite() {		return website;	}	public void setWebsite(Website website) {		this.website = website;	}}