Java tutorial
/******************************************************************************* * Copyright 2015 DANS - Data Archiving and Networked Services * * 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 nl.knaw.dans.common.wicket.components; import java.util.List; import org.apache.wicket.Component; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.list.ListView; /** * <p> * Where {@link ListView<T>} rather works with a TABLE, UL or OL, this repeater uses a prefix as * separator. The first occurrence of the prefix is not rendered. Though the repeater is not restricted * to links, a typical example would be: * </p> * HTML * * <pre> * <span wicket:id="list"> * <span wicket:id="separator">|</span> * <a href="#" wicket:id="link"> * <span wicket:id="label"> </span> * </a> * </span> * </pre> * * java * * <pre> * SeparatedListView createListView(final String[] labels) * { * final List<Component> links = new ArrayList<Component>(); * for (String label : labels) * links.add(new MyLink(new Model<String>(label))); * return new SeparatedListView("list", "separator", links); * } * class MyLink extends Link<String> * { * public MyLink(final IModel<String> model) * { * super("link", model); * add(new Label("label", model.getObject())); * } * } * } * </pre> */ public class SeparatedListView extends ListView<Component> { // TODO move to commons? private static final long serialVersionUID = 3720302690110935794L; private final String separatorId; public SeparatedListView(final String id, final String separatorId, final List<? extends Component> list) { super(id, list); this.separatorId = separatorId; } @Override protected void populateItem(final ListItem<Component> item) { final boolean showSeparator = item.getIndex() != 0; item.add(item.getModelObject()); item.add(new WebMarkupContainer(separatorId).setVisible(showSeparator)); } }