Re: [Wicket-user] Modifying attributes of tabs in TabbedPanel

2007-07-04 Thread Timo Rantalaiho
On Wed, 04 Jul 2007, Erik Dreyer wrote:
> 
> 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.
> 
> 
> 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 Oyhttp://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)
-   {
-

Re: [Wicket-user] Modifying attributes of tabs in TabbedPanel

2007-07-04 Thread Erik Dreyer


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.


That would be much appreciated...

item.add(new AttributeAppender("class", true, new Model("tab"+index), " "));

On 7/4/07, Igor Vaynberg <[EMAIL PROTECTED]> wrote:


On 7/4/07, Erik Dreyer <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm trying to update the provided TabbedPanel to be able to provide a
> new CSS style to each tab so I can control the color of each tab.
>
> I tried subclassing TabbedPanel and adding this method:
>
>  @Override
> protected void onBeforeRender() {
> super.onBeforeRender();
>
> // get each tab and add a style
> for (int i = 0; i < getTabs().size(); i++) {
> Component tab = get("tabs-container:tabs:" + i);
> tab.add(new AttributeAppender("class", true, new
> Model("tab"+i), " "));
> }
> }
>
> This doesn't work (Null Pointer) because this method gets called before
> the actual tabs are added.  I tried using onAfterRender().  This time the
> tabs exist, but I can't modify the hierarchy during rendering.
>
> Is there a way I can accomplish what I want without forking the
> TabbedPanel class?


the short answer is: you cannot.

the point of tabbedpanel is to encapsulate a lot of these details so you
do not have to worry about it. the ease of use comes at a price - not
everything is customizable to everyone's content.

so there are two options to solve this

a) you can roll your own tabbed panel (which in wicket is not very hard,
the original has about 30-40 lines of code that make it tick?

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.

-igor



Thanks for your help,
> Erik
>
>
> -
> 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
>
>

-
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


-
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


Re: [Wicket-user] Modifying attributes of tabs in TabbedPanel

2007-07-04 Thread Igor Vaynberg

On 7/4/07, Erik Dreyer <[EMAIL PROTECTED]> wrote:


Hi,

I'm trying to update the provided TabbedPanel to be able to provide a new
CSS style to each tab so I can control the color of each tab.

I tried subclassing TabbedPanel and adding this method:

@Override
protected void onBeforeRender() {
super.onBeforeRender();

// get each tab and add a style
for (int i = 0; i < getTabs().size(); i++) {
Component tab = get("tabs-container:tabs:" + i);
tab.add(new AttributeAppender("class", true, new
Model("tab"+i), " "));
}
}

This doesn't work (Null Pointer) because this method gets called before
the actual tabs are added.  I tried using onAfterRender().  This time the
tabs exist, but I can't modify the hierarchy during rendering.

Is there a way I can accomplish what I want without forking the
TabbedPanel class?



the short answer is: you cannot.

the point of tabbedpanel is to encapsulate a lot of these details so you do
not have to worry about it. the ease of use comes at a price - not
everything is customizable to everyone's content.

so there are two options to solve this

a) you can roll your own tabbed panel (which in wicket is not very hard, the
original has about 30-40 lines of code that make it tick?

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.

-igor



Thanks for your help,

Erik

-
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


-
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


Re: [Wicket-user] Modifying attributes of tabs in TabbedPanel

2007-07-04 Thread Erik Dreyer

On 7/4/07, Erik Dreyer <[EMAIL PROTECTED]> wrote:


Hi,

I'm trying to update the provided TabbedPanel to be able to provide a new
CSS style to each tab so I can control the color of each tab.

I tried subclassing TabbedPanel and adding this method:

@Override
protected void onBeforeRender() {
super.onBeforeRender();

// get each tab and add a style
for (int i = 0; i < getTabs().size(); i++) {
Component tab = get("tabs-container:tabs:" + i);
tab.add(new AttributeAppender("class", true, new
Model("tab"+i), " "));
}
}

This doesn't work (Null Pointer) because this method gets called before
the actual tabs are added.  I tried using onAfterRender().  This time the
tabs exist, but I can't modify the hierarchy during rendering.

Is there a way I can accomplish what I want without forking the
TabbedPanel class?

Thanks for your help,
Erik



No response.  Let me rephrase the question more generally.

How can a component manipulate the component hierarchy of its children if
those children don't expose their inner structure?  It seems the components
render from the top down.  That is, a parent is rendered before its
children.  Is that correct?  What if a parent wants to modify its children
in onBeforeRender(), but can't because performing a get("path:to:child")
results in a NPE?  Is there a way to do so?  See my original post for an
example of why I might want to do this.

Thanks,
Erik
-
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