KARAF-2090 Mark module tab as active when needed
authorŁukasz Dywicki <ldywicki@apache.org>
Fri, 28 Dec 2012 17:36:56 +0000 (17:36 +0000)
committerŁukasz Dywicki <ldywicki@apache.org>
Fri, 28 Dec 2012 17:36:56 +0000 (17:36 +0000)
Signed-off-by: Lukasz Dywicki <luke@code-house.org>
git-svn-id: https://svn.apache.org/repos/asf/karaf/webconsole/trunk@1426589 13f79535-47bb-0310-9956-ffa450edef68

core/src/main/java/org/apache/karaf/webconsole/core/navigation/markup/ModuleTabPanel.java
core/src/main/java/org/apache/karaf/webconsole/core/navigation/markup/NavigationTopPanel.java
core/src/main/resources/org/apache/karaf/webconsole/core/navigation/markup/NavigationTopPanel.html

index 96c7ccb..e4f49df 100644 (file)
@@ -16,7 +16,6 @@
  */
 package org.apache.karaf.webconsole.core.navigation.markup;
 
-import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.karaf.webconsole.core.navigation.ConsoleTabProvider;
@@ -49,16 +48,7 @@ public class ModuleTabPanel extends Panel {
         IModel<List<Link<Page>>> links = new LoadableDetachableModel<List<Link<Page>>>() {
             @Override
             protected List<Link<Page>> load() {
-                if (tabs == null) {
-                    return new ArrayList<Link<Page>>();
-                }
-                for (ConsoleTabProvider provider : tabs) {
-                    Link<Page> moduleLink = provider.getModuleLink("moduleLink", "moduleLabel");
-                    if (LinkUtils.isActiveTrail(moduleLink)) {
-                        return provider.getItems("link", "label");
-                    }
-                }
-                return new ArrayList<Link<Page>>();
+                return findActiveModuleLinks();
             }
         };
 
@@ -68,10 +58,26 @@ public class ModuleTabPanel extends Panel {
                 Link<Page> link = item.getModelObject();
                 item.add(link);
                 if (LinkUtils.isActiveTrail(link)) {
-                    item.add(new AttributeModifier("class", "active"));
+                    item.getParent().add(new AttributeModifier("class", "active"));
                 }
             }
         });
     }
 
+    private List<Link<Page>> findActiveModuleLinks() {
+        for (ConsoleTabProvider provider : tabs) {
+            Link<Page> moduleLink = provider.getModuleLink("moduleLink", "moduleLabel");
+            if (LinkUtils.isActiveTrail(moduleLink)) {
+                return provider.getItems("link", "label");
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public boolean isVisible() {
+        List<Link<Page>> activeModuleLinks = findActiveModuleLinks();
+        return activeModuleLinks != null && activeModuleLinks.size() > 0;
+    }
+
 }
index c44ca65..f69840a 100644 (file)
@@ -28,14 +28,11 @@ import org.apache.karaf.webconsole.core.util.LinkUtils;
 import org.apache.wicket.AttributeModifier;
 import org.apache.wicket.Component;
 import org.apache.wicket.Page;
-import org.apache.wicket.behavior.AttributeAppender;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.link.Link;
 import org.apache.wicket.markup.html.list.ListItem;
 import org.apache.wicket.markup.html.list.ListView;
-import org.apache.wicket.markup.repeater.RepeatingView;
 import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
 import org.ops4j.pax.wicket.api.PaxWicketBean;
 import org.osgi.service.prefs.PreferencesService;
 
@@ -73,35 +70,15 @@ public class NavigationTopPanel extends LanguageTopPanel {
 
             @Override
             protected void populateItem(ListItem<ConsoleTabProvider> item) {
-                populateTabItem(item, item.getModelObject());
+                Link<Page> link = item.getModelObject().getModuleLink("moduleLink", "moduleLabel");
+                item.add(link);
+
+                if (LinkUtils.isActiveTrail(link)) {
+                    item.add(AttributeModifier.append("class", "active"));
+                }
             }
         };
     }
 
-    protected void populateTabItem(ListItem<ConsoleTabProvider> item, ConsoleTabProvider provider) {
-        Link<Page> link = provider.getModuleLink("moduleLink", "moduleLabel");
-        item.add(link);
-
-        if (LinkUtils.isActiveTrail(link)) {
-            item.add(new AttributeAppender("class", Model.of("active"), " "));
-        }
-    }
-
-    protected void populateSingleTabItem(ListItem<ConsoleTabProvider> item, ConsoleTabProvider provider) {
-        Link<Page> moduleLink = provider.getModuleLink("moduleLink", "moduleLabel");
-
-        // remove dropdown stuff
-        item.add(new AttributeModifier("class", ""));
-        moduleLink.add(new AttributeModifier("data-toggle", ""));
-        moduleLink.add(new AttributeModifier("class", ""));
-
-        if (LinkUtils.isActiveTrail(moduleLink)) {
-            item.add(new AttributeAppender("class", Model.of("active"), " "));
-        }
-
-        item.add(moduleLink);
-        item.add(new RepeatingView("moduleLinks"));
-    }
-
 
 }
index 062c2e8..0670587 100644 (file)
 <wicket:extend xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
 
     <ul class="nav">
-        <wicket:container wicket:id="tabs">
-            <li>
-                <a wicket:id="moduleLink">
-                    <span wicket:id="moduleLabel"></span>
-                </a>
-            </li>
-            <li class="divider-vertical"></li>
-        </wicket:container>
+        <li wicket:id="tabs">
+            <a wicket:id="moduleLink">
+                <span wicket:id="moduleLabel"></span>
+            </a>
+        </li>
+        <li class="divider-vertical"></li>
     </ul>
 
     <wicket:child />