package org.apache.wicket.examples.compref;
import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.examples.WicketExamplePage;
import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
import org.apache.wicket.extensions.markup.html.tabs.TabbedPanel;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;
@see
@author
public class TabbedPanelPage extends WicketExamplePage
{
private static final long serialVersionUID = 1L;
public TabbedPanelPage()
{
setDefaultModel(new Model<>("tabpanel"));
addCssSwitchingLinks();
final List<ITab> tabs = new ArrayList<>();
tabs.add(new AbstractTab(new Model<>("first tab"))
{
private static final long serialVersionUID = 1L;
@Override
public Panel getPanel(String panelId)
{
return new TabPanel1(panelId);
}
});
tabs.add(new AbstractTab(new Model<>("second tab"))
{
private static final long serialVersionUID = 1L;
@Override
public Panel getPanel(String panelId)
{
return new TabPanel2(panelId);
}
});
tabs.add(new AbstractTab(new Model<>("third tab"))
{
private static final long serialVersionUID = 1L;
@Override
public Panel getPanel(String panelId)
{
return new TabPanel3(panelId);
}
});
final TabbedPanel<ITab> tabbedPanel = new TabbedPanel<>("tabs", tabs);
tabbedPanel.add(AttributeModifier.replace("class", TabbedPanelPage.this.getDefaultModel()));
add(tabbedPanel);
}
private void addCssSwitchingLinks()
{
add(new CssSwitchingLink("var0", "tabpanel"));
add(new CssSwitchingLink("var1", "tabpanel1"));
add(new CssSwitchingLink("var2", "tabpanel2"));
add(new CssSwitchingLink("var3", "tabpanel3"));
add(new CssSwitchingLink("var4", "tabpanel4"));
}
protected class CssSwitchingLink extends Link<Void>
{
private static final long serialVersionUID = 1L;
private final String clazz;
@param
@param
public CssSwitchingLink(String id, String clazz)
{
super(id);
this.clazz = clazz;
}
@Override
public void onClick()
{
TabbedPanelPage.this.setDefaultModelObject(clazz);
}
@Override
public boolean isEnabled()
{
return !TabbedPanelPage.this.getDefaultModelObjectAsString().equals(clazz);
}
}
@author
private static class TabPanel1 extends Panel
{
private static final long serialVersionUID = 1L;
@param
public TabPanel1(String id)
{
super(id);
}
}
@author
private static class TabPanel2 extends Panel
{
private static final long serialVersionUID = 1L;
@param
public TabPanel2(String id)
{
super(id);
}
}
@author
private static class TabPanel3 extends Panel
{
private static final long serialVersionUID = 1L;
@param
public TabPanel3(String id)
{
super(id);
}
}
@Override
protected void explain()
{
String html = "<span wicket:id=\"tabs\" class=\"tabpanel\">[tabbed panel will be here]</span>\n";
String code = " List tabs=new ArrayList();<br/>"
+ " tabs.add(new AbstractTab(new Model<String>(\"first tab\")) {<br/>"
+ " public Panel getPanel(String panelId) { return new TabPanel1(panelId); }<br/>"
+ " });<br/>"
+ " tabs.add(new AbstractTab(new Model<String>(\"second tab\")) {<br/>"
+ " public Panel getPanel(String panelId) { return new TabPanel2(panelId); }<br/>"
+ " });<br/>"
+ " tabs.add(new AbstractTab(new Model<String>(\"third tab\")) {<br/>"
+ " public Panel getPanel(String panelId) { return new TabPanel3(panelId); }<br/>"
+ " });<br/>"
+ " add(new TabbedPanel(\"tabs\", tabs)<br/>";
add(new ExplainPanel(html, code));
}
}