On Wed, 04 Jul 2007, Erik Dreyer wrote:
> <snip>
> b) we can add this functionality to the tabbed pael in core, making it a bit
> more bloated.
> i dont mind (b) if its just adding "tab1", "tab2" class attributes.
> </snip>
>
> That would be much appreciated...
>
> item.add(new AttributeAppender("class", true, new Model("tab"+index), " "));
Or maybe there could just be a hook in the
protected void populateItem(LoopItem item) method inside
TabbedPanel, something like in the attached patch.
- Timo
--
Timo Rantalaiho
Reaktor Innovations Oy <URL: http://www.ri.fi/ >
Index:
wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/tabs/TabbedPanelTest.java
===================================================================
---
wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/tabs/TabbedPanelTest.java
(revision 0)
+++
wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/tabs/TabbedPanelTest.java
(revision 0)
@@ -0,0 +1,80 @@
+package org.apache.wicket.extensions.markup.html.tabs;
+
+import junit.framework.TestCase;
+import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.html.list.Loop;
+import org.apache.wicket.markup.html.panel.EmptyPanel;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.util.tester.TestPanelSource;
+import org.apache.wicket.util.tester.WicketTester;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Timo Rantalaiho
+ */
+public class TabbedPanelTest extends TestCase {
+ private WicketTester wicket;
+
+ protected void setUp() throws Exception
+ {
+ wicket = new WicketTester();
+ }
+
+ public void testAllowsCustomCssClassesForTabs()
+ {
+ wicket.startPanel(new TestPanelSource() {
+ public Panel getTestPanel(final String panelId)
+ {
+ return new TabbedPanel(panelId, createTabs())
+ {
+ protected void afterPopulateItem(Loop.LoopItem item, final
boolean selected, boolean last)
+ {
+ int index = item.getIteration();
+ item.add(new AttributeAppender("class", true, new
Model("tab" + index), " "));
+ }
+ };
+ }
+ });
+ String dogsClass = "class=\"tab0\"";
+ String catsClass = "class=\"tab1\"";
+
+ wicket.assertContains("Dogs");
+ wicket.assertContains("Cats");
+ wicket.assertContains(dogsClass);
+ wicket.assertContains(catsClass);
+
+ clickCatsLink();
+ wicket.assertContains(dogsClass);
+ wicket.assertContains(catsClass);
+ }
+
+ private void clickCatsLink()
+ {
+ TabbedPanel panel = (TabbedPanel)
wicket.getComponentFromLastRenderedPage("panel");
+ Link catsLink = (Link) panel.get("tabs-container:tabs:1:link");
+ wicket.clickLink(catsLink.getPageRelativePath());
+ }
+
+ private List createTabs()
+ {
+ List tabs = new ArrayList();
+ tabs.add(createTestTab("Dogs"));
+ tabs.add(createTestTab("Cats"));
+ return tabs;
+ }
+
+ private ITab createTestTab(final String title)
+ {
+ return new AbstractTab(new Model(title))
+ {
+ public Panel getPanel(final String panelId)
+ {
+ return new EmptyPanel(panelId);
+ }
+ };
+ }
+}
Index:
wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/tabs/TabbedPanel.java
===================================================================
---
wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/tabs/TabbedPanel.java
(revision 553372)
+++
wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/tabs/TabbedPanel.java
(working copy)
@@ -16,8 +16,6 @@
*/
package org.apache.wicket.extensions.markup.html.tabs;
-import java.util.List;
-
import org.apache.wicket.Component;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.behavior.AttributeAppender;
@@ -32,7 +30,9 @@
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
+import java.util.List;
+
/**
* TabbedPanel component represets a panel with tabs that are used to switch
* between different content panels inside the TabbedPanel panel.
@@ -155,21 +155,9 @@
titleLink.add(newTitle("title", tab.getTitle(),
index));
item.add(titleLink);
- item.add(new SimpleAttributeModifier("class",
"selected")
- {
- private static final long
serialVersionUID = 1L;
-
- public boolean isEnabled(Component
component)
- {
- return index == selected;
- }
-
- });
- if (item.getIteration() == getIterations() - 1)
- {
- item.add(new AttributeAppender("class",
true, new Model("last"), " "));
- }
-
+ final boolean isSelected = index == selected;
+ boolean isLast = item.getIteration() == getIterations() - 1;
+ afterPopulateItem(item, isSelected, isLast);
}
});
@@ -179,7 +167,24 @@
}
- /**
+ /**
+ * Adds CSS classes to <code>item</code>, override as needed.
+ */
+ protected void afterPopulateItem(Loop.LoopItem item, final boolean
selected, boolean last) {
+ item.add(new SimpleAttributeModifier("class", "selected") {
+ private static final long serialVersionUID = 1L;
+
+ public boolean isEnabled(Component component) {
+ return selected;
+ }
+
+ });
+ if (last) {
+ item.add(new AttributeAppender("class", true, new Model("last"), "
"));
+ }
+ }
+
+ /**
* @return the value of css class attribute that will be added to a div
* containing the tabs. The default value is
<code>tab-row</code>
*/
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user