Java tutorial
/* * Copyright (c) 2011 by Martin Simons. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package net.lunikon.rethul.web.pages; import java.util.Locale; import net.lunikon.rethul.model.File; import net.lunikon.rethul.web.components.LocaleLabel; import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.link.BookmarkablePageLink; import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.model.AbstractReadOnlyModel; import org.apache.wicket.model.CompoundPropertyModel; import org.apache.wicket.model.IModel; /** * AbstractFilePage. * * @author Martin Simons */ public class AbstractFilePage extends BasePage { /** * The locale of the file. */ protected final Locale fileLocale; /** * Constructs a new instance of this class. * * @param model * @param locale */ public AbstractFilePage(IModel<File> model, Locale locale) { super(model); this.fileLocale = locale; buildCaption(); // link back to project page Link<File> projectLink = new BookmarkablePageLink<File>("projectLink", ProjectPage.class) { @Override public PageParameters getPageParameters() { String name = getModelObject().getProject().getName(); PageParameters ps = super.getPageParameters(); ps.add(ProjectPage.NAME_PARAM, name); return ps; } }; projectLink.setModel(model); add(projectLink); } private void buildCaption() { WebMarkupContainer caption = new WebMarkupContainer("caption"); caption.setDefaultModel(new CompoundPropertyModel<File>(getModel())); add(caption); caption.add(new Label("project.name")); caption.add(new Label("name")); caption.add(new LocaleLabel("locale", new AbstractReadOnlyModel<Locale>() { @Override public Locale getObject() { return getFileLocale(); } })); } /** * Returns the fileLocale. * * @return the fileLocale */ public Locale getFileLocale() { return fileLocale; } @SuppressWarnings("unchecked") public IModel<File> getModel() { return (IModel<File>) getDefaultModel(); } public File getModelObject() { return (File) getDefaultModelObject(); } }