Skip to content
Browse files

KARAF-2090 Mark module tab as active when needed

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
  • Loading branch information...
1 parent b4bfe58 commit b3af01800dc61c4d3cf6dfe3fb861dbb4d9cbf98 @splatch splatch committed
View
30 core/src/main/java/org/apache/karaf/webconsole/core/navigation/markup/ModuleTabPanel.java
@@ -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 ModuleTabPanel(String id) {
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 @@ protected void populateItem(ListItem<Link<Page>> item) {
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;
+ }
+
}
View
35 .../src/main/java/org/apache/karaf/webconsole/core/navigation/markup/NavigationTopPanel.java
@@ -28,14 +28,11 @@
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 @@ protected Component createTabList() {
@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"));
- }
-
}
View
14 ...main/resources/org/apache/karaf/webconsole/core/navigation/markup/NavigationTopPanel.html
@@ -18,14 +18,12 @@
<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 />

0 comments on commit b3af018

Please sign in to comment.
Something went wrong with that request. Please try again.