You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2006/08/01 19:44:01 UTC
svn commit: r427657 [12/42] - in /myfaces:
core/trunk/api/src/main/java/javax/faces/component/
core/trunk/api/src/test/java/javax/faces/
core/trunk/api/src/test/java/javax/faces/application/
core/trunk/api/src/test/java/javax/faces/component/ core/trun...
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlCommandNavigationItem.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlCommandNavigationItem.java?rev=427657&r1=427656&r2=427657&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlCommandNavigationItem.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlCommandNavigationItem.java Tue Aug 1 10:43:28 2006
@@ -1,341 +1,341 @@
-/*
- * Copyright 2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.myfaces.custom.navmenu.htmlnavmenu;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.component.html.ext.HtmlCommandLink;
-import org.apache.myfaces.shared_tomahawk.util._ComponentUtils;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.ActionEvent;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.PhaseId;
-import javax.faces.el.ValueBinding;
-import java.util.*;
-
-/**
- * Many thanks to the guys from Swiss Federal Institute of Intellectual Property & Marc Bouquet
- * for helping to develop this component.
- *
- * @author Manfred Geiler
- * @author Thomas Spiegl
- */
-public class HtmlCommandNavigationItem extends HtmlCommandLink {
- private static final Log log = LogFactory.getLog(HtmlCommandNavigationItem.class);
-
- private Boolean _open = null;
- private Boolean _active = null;
- private String _activeOnViewIds = null;
- private String _externalLink = null;
-
- public boolean isImmediate() {
- //always immediate
- return true;
- }
-
- public void setImmediate(Boolean immediate) {
- if (log.isWarnEnabled()) log.warn("Immediate property of HtmlCommandNavigation cannot be set --> ignored.");
- }
-
- public boolean isOpen() {
- if (_open != null) return _open.booleanValue();
- ValueBinding vb = getValueBinding("open");
- Boolean v = vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
- return v != null && v.booleanValue();
- }
-
- public Boolean getOpenDirectly() {
- return _open;
- }
-
- public void setOpen(boolean open) {
- _open = open ? Boolean.TRUE : Boolean.FALSE;
- }
-
- public boolean isActive() {
- if (_active != null) return _active.booleanValue();
- ValueBinding vb = getValueBinding("active");
- Boolean v = vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
- return v != null && v.booleanValue();
- }
-
- public Boolean getActiveDirectly() {
- return _active;
- }
-
- public void setActive(boolean active) {
- _active = active ? Boolean.TRUE : Boolean.FALSE;
- }
-
- public String getActiveOnViewIds() {
- if (_activeOnViewIds != null) return _activeOnViewIds;
- ValueBinding vb = getValueBinding("activeOnViewIds");
- return vb != null ? _ComponentUtils.getStringValue(getFacesContext(), vb) : null;
- }
-
- public void setActiveOnViewIds(String activeOnViewIds) {
- this._activeOnViewIds = activeOnViewIds;
- }
-
- public String getExternalLink() {
- if (_externalLink != null) return _externalLink;
- ValueBinding vb = getValueBinding("externalLink");
- return vb != null ? _ComponentUtils.getStringValue(getFacesContext(), vb) : null;
- }
-
- public void setExternalLink(String externalLink) {
- this._externalLink = externalLink;
- }
-
- /**
- * @return false, if this item is child of another HtmlCommandNavigation, which is closed
- */
- public boolean isRendered() {
- if (! super.isRendered()) {
- return false;
- }
-
- HtmlPanelNavigationMenu parentPanelNavMenu = getParentPanelNavigation();
- if (parentPanelNavMenu != null && parentPanelNavMenu.isRenderAll())
- return true;
-
- UIComponent parent = getParent();
- while (parent != null) {
- if (parent instanceof HtmlCommandNavigationItem) {
- if (!((HtmlCommandNavigationItem) parent).isOpen()) {
- return false;
- }
- }
-
- if (parent instanceof HtmlPanelNavigationMenu) {
- break;
- }
- else {
- parent = parent.getParent();
- }
- }
-
- return true;
- }
-
- private HtmlPanelNavigationMenu getParentPanelNavigation() {
- UIComponent parent = getParent();
-
- // search HtmlPanelNavigation
- UIComponent p = parent;
- while (p != null && !(p instanceof HtmlPanelNavigationMenu)) {
- p = p.getParent();
- }
- // p is now the HtmlPanelNavigation
- if (!(p instanceof HtmlPanelNavigationMenu)) {
- log.error("HtmlCommandNavigation without parent HtmlPanelNavigation ?!");
- return null;
- }
-
- return (HtmlPanelNavigationMenu) p;
- }
-
- public void toggleOpen() {
- HtmlPanelNavigationMenu menu = getParentPanelNavigation();
- if (isOpen() && menu != null && !menu.isExpandAll()) {
- if (getChildCount() > 0) {
- //item is a menu group --> close item
- setOpen(false);
- }
- }
- else {
- UIComponent parent = getParent();
-
- //close all siblings
- closeAllChildren(parent.getChildren().iterator(), this, true);
-
- //open all parents (to be sure) and search HtmlPanelNavigation
- UIComponent p = parent;
- while (p != null && !(p instanceof HtmlPanelNavigationMenu)) {
- if (p instanceof HtmlCommandNavigationItem) {
- ((HtmlCommandNavigationItem) p).setOpen(true);
- }
- p = p.getParent();
- }
- // p is now the HtmlPanelNavigation
- if (!(p instanceof HtmlPanelNavigationMenu)) {
- log.error("HtmlCommandNavigation without parent HtmlPanelNavigation ?!");
- }
- else {
- if (!hasCommandNavigationChildren() || ((HtmlPanelNavigationMenu) p).isExpandAll()) {
- //item is an end node or Menu always expanded --> deactivate all other nodes, and then...
-
- //deactivate all other items
- deactivateAllChildren(p.getChildren().iterator());
- //...activate this item
- setActive(true);
- }
- else {
- //open item
- setOpen(true);
- }
- }
- }
- }
-
- private boolean hasCommandNavigationChildren() {
- if (getChildCount() == 0) {
- return false;
- }
- List list = getChildren();
- for (int i = 0, sizei = list.size(); i < sizei; i++) {
- if (list.get(i) instanceof HtmlCommandNavigationItem) {
- return true;
- }
- }
- return false;
- }
-
-
- private static void deactivateAllChildren(Iterator children) {
- while (children.hasNext()) {
- UIComponent ni = (UIComponent) children.next();
- if (ni instanceof HtmlCommandNavigationItem) {
- ((HtmlCommandNavigationItem) ni).setActive(false);
- if (ni.getChildCount() > 0) {
- deactivateAllChildren(ni.getChildren().iterator());
- }
- }
- }
- }
-
- private static void closeAllChildren(Iterator children, HtmlCommandNavigationItem current, boolean resetActive) {
- while (children.hasNext()) {
- UIComponent ni = (UIComponent) children.next();
- if (ni instanceof HtmlCommandNavigationItem) {
- ((HtmlCommandNavigationItem) ni).setOpen(false);
- if (resetActive)
- ((HtmlCommandNavigationItem) ni).setActive(false);
- if (ni.getChildCount() > 0) {
- closeAllChildren(ni.getChildren().iterator(), current, current != ni);
- }
- }
- }
- }
-
- public String[] getActiveOnVieIds() {
- String value = getActiveOnViewIds();
- if (value == null)
- return new String[]{};
- return value.split(",");
- }
-
- private void openParents() {
- UIComponent comp = this;
-
- while ((comp = comp.getParent()) instanceof HtmlCommandNavigationItem) {
- HtmlCommandNavigationItem parent = (HtmlCommandNavigationItem) comp;
- if (!parent.isOpen()) {
- parent.setOpen(true);
- }
- else {
- return;
- }
- }
- }
-
- public void deactivateAll() {
- UIComponent parent = this.getParent();
- while (!(parent instanceof HtmlPanelNavigationMenu) && parent != null) {
- parent = parent.getParent();
- }
- if (parent == null) {
- throw new IllegalStateException("no PanelNavigationMenu!");
- }
-
- HtmlPanelNavigationMenu root = (HtmlPanelNavigationMenu) parent;
- for (Iterator it = root.getChildren().iterator(); it.hasNext();) {
- Object o = it.next();
- if (o instanceof HtmlCommandNavigationItem) {
- HtmlCommandNavigationItem navItem = (HtmlCommandNavigationItem) o;
- navItem.setActive(false);
- if (navItem.getChildCount() > 0) {
- navItem.deactivateChildren();
- }
- }
- }
- }
-
- public void deactivateChildren() {
- for (Iterator it = this.getChildren().iterator(); it.hasNext();) {
- Object o = it.next();
- if (o instanceof HtmlCommandNavigationItem) {
- HtmlCommandNavigationItem current = (HtmlCommandNavigationItem) o;
- current.setActive(false);
- if (current.getChildCount() > 0) {
- current.deactivateChildren();
- }
- }
- }
- }
-
- public void broadcast(FacesEvent event) throws AbortProcessingException {
- if (event instanceof ActionEvent) {
- ActionEvent actionEvent = (ActionEvent) event;
- if (actionEvent.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES) {
- HtmlCommandNavigationItem navItem = (HtmlCommandNavigationItem) actionEvent.getComponent();
- navItem.toggleOpen();
- FacesContext.getCurrentInstance().renderResponse();
- }
- }
- super.broadcast(event);
- }
-
-
- public Object saveState(FacesContext context) {
- Object values[] = new Object[5];
- values[0] = super.saveState(context);
- values[1] = _open;
- values[2] = _active;
- values[3] = _activeOnViewIds;
- values[4] = _externalLink;
- return ((Object) (values));
- }
-
- public void restoreState(FacesContext context, Object state) {
- Object values[] = (Object[]) state;
- super.restoreState(context, values[0]);
- _open = ((Boolean) values[1]);
- _active = ((Boolean) values[2]);
- _activeOnViewIds = ((String) values[3]);
- _externalLink = ((String) values[4]);
- }
-
- //------------------ GENERATED CODE BEGIN (do not modify!) --------------------
-
- public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlCommandNavigationItem";
- public static final String COMPONENT_FAMILY = "javax.faces.Command";
- private static final String DEFAULT_RENDERER_TYPE = "javax.faces.Link";
-
-
- public HtmlCommandNavigationItem() {
- setRendererType(DEFAULT_RENDERER_TYPE);
- }
-
- public String getFamily() {
- return COMPONENT_FAMILY;
- }
-
- //------------------ GENERATED CODE END ---------------------------------------
-}
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.custom.navmenu.htmlnavmenu;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.component.html.ext.HtmlCommandLink;
+import org.apache.myfaces.shared_tomahawk.util._ComponentUtils;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.el.ValueBinding;
+import java.util.*;
+
+/**
+ * Many thanks to the guys from Swiss Federal Institute of Intellectual Property & Marc Bouquet
+ * for helping to develop this component.
+ *
+ * @author Manfred Geiler
+ * @author Thomas Spiegl
+ */
+public class HtmlCommandNavigationItem extends HtmlCommandLink {
+ private static final Log log = LogFactory.getLog(HtmlCommandNavigationItem.class);
+
+ private Boolean _open = null;
+ private Boolean _active = null;
+ private String _activeOnViewIds = null;
+ private String _externalLink = null;
+
+ public boolean isImmediate() {
+ //always immediate
+ return true;
+ }
+
+ public void setImmediate(Boolean immediate) {
+ if (log.isWarnEnabled()) log.warn("Immediate property of HtmlCommandNavigation cannot be set --> ignored.");
+ }
+
+ public boolean isOpen() {
+ if (_open != null) return _open.booleanValue();
+ ValueBinding vb = getValueBinding("open");
+ Boolean v = vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
+ return v != null && v.booleanValue();
+ }
+
+ public Boolean getOpenDirectly() {
+ return _open;
+ }
+
+ public void setOpen(boolean open) {
+ _open = open ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ public boolean isActive() {
+ if (_active != null) return _active.booleanValue();
+ ValueBinding vb = getValueBinding("active");
+ Boolean v = vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
+ return v != null && v.booleanValue();
+ }
+
+ public Boolean getActiveDirectly() {
+ return _active;
+ }
+
+ public void setActive(boolean active) {
+ _active = active ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ public String getActiveOnViewIds() {
+ if (_activeOnViewIds != null) return _activeOnViewIds;
+ ValueBinding vb = getValueBinding("activeOnViewIds");
+ return vb != null ? _ComponentUtils.getStringValue(getFacesContext(), vb) : null;
+ }
+
+ public void setActiveOnViewIds(String activeOnViewIds) {
+ this._activeOnViewIds = activeOnViewIds;
+ }
+
+ public String getExternalLink() {
+ if (_externalLink != null) return _externalLink;
+ ValueBinding vb = getValueBinding("externalLink");
+ return vb != null ? _ComponentUtils.getStringValue(getFacesContext(), vb) : null;
+ }
+
+ public void setExternalLink(String externalLink) {
+ this._externalLink = externalLink;
+ }
+
+ /**
+ * @return false, if this item is child of another HtmlCommandNavigation, which is closed
+ */
+ public boolean isRendered() {
+ if (! super.isRendered()) {
+ return false;
+ }
+
+ HtmlPanelNavigationMenu parentPanelNavMenu = getParentPanelNavigation();
+ if (parentPanelNavMenu != null && parentPanelNavMenu.isRenderAll())
+ return true;
+
+ UIComponent parent = getParent();
+ while (parent != null) {
+ if (parent instanceof HtmlCommandNavigationItem) {
+ if (!((HtmlCommandNavigationItem) parent).isOpen()) {
+ return false;
+ }
+ }
+
+ if (parent instanceof HtmlPanelNavigationMenu) {
+ break;
+ }
+ else {
+ parent = parent.getParent();
+ }
+ }
+
+ return true;
+ }
+
+ private HtmlPanelNavigationMenu getParentPanelNavigation() {
+ UIComponent parent = getParent();
+
+ // search HtmlPanelNavigation
+ UIComponent p = parent;
+ while (p != null && !(p instanceof HtmlPanelNavigationMenu)) {
+ p = p.getParent();
+ }
+ // p is now the HtmlPanelNavigation
+ if (!(p instanceof HtmlPanelNavigationMenu)) {
+ log.error("HtmlCommandNavigation without parent HtmlPanelNavigation ?!");
+ return null;
+ }
+
+ return (HtmlPanelNavigationMenu) p;
+ }
+
+ public void toggleOpen() {
+ HtmlPanelNavigationMenu menu = getParentPanelNavigation();
+ if (isOpen() && menu != null && !menu.isExpandAll()) {
+ if (getChildCount() > 0) {
+ //item is a menu group --> close item
+ setOpen(false);
+ }
+ }
+ else {
+ UIComponent parent = getParent();
+
+ //close all siblings
+ closeAllChildren(parent.getChildren().iterator(), this, true);
+
+ //open all parents (to be sure) and search HtmlPanelNavigation
+ UIComponent p = parent;
+ while (p != null && !(p instanceof HtmlPanelNavigationMenu)) {
+ if (p instanceof HtmlCommandNavigationItem) {
+ ((HtmlCommandNavigationItem) p).setOpen(true);
+ }
+ p = p.getParent();
+ }
+ // p is now the HtmlPanelNavigation
+ if (!(p instanceof HtmlPanelNavigationMenu)) {
+ log.error("HtmlCommandNavigation without parent HtmlPanelNavigation ?!");
+ }
+ else {
+ if (!hasCommandNavigationChildren() || ((HtmlPanelNavigationMenu) p).isExpandAll()) {
+ //item is an end node or Menu always expanded --> deactivate all other nodes, and then...
+
+ //deactivate all other items
+ deactivateAllChildren(p.getChildren().iterator());
+ //...activate this item
+ setActive(true);
+ }
+ else {
+ //open item
+ setOpen(true);
+ }
+ }
+ }
+ }
+
+ private boolean hasCommandNavigationChildren() {
+ if (getChildCount() == 0) {
+ return false;
+ }
+ List list = getChildren();
+ for (int i = 0, sizei = list.size(); i < sizei; i++) {
+ if (list.get(i) instanceof HtmlCommandNavigationItem) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ private static void deactivateAllChildren(Iterator children) {
+ while (children.hasNext()) {
+ UIComponent ni = (UIComponent) children.next();
+ if (ni instanceof HtmlCommandNavigationItem) {
+ ((HtmlCommandNavigationItem) ni).setActive(false);
+ if (ni.getChildCount() > 0) {
+ deactivateAllChildren(ni.getChildren().iterator());
+ }
+ }
+ }
+ }
+
+ private static void closeAllChildren(Iterator children, HtmlCommandNavigationItem current, boolean resetActive) {
+ while (children.hasNext()) {
+ UIComponent ni = (UIComponent) children.next();
+ if (ni instanceof HtmlCommandNavigationItem) {
+ ((HtmlCommandNavigationItem) ni).setOpen(false);
+ if (resetActive)
+ ((HtmlCommandNavigationItem) ni).setActive(false);
+ if (ni.getChildCount() > 0) {
+ closeAllChildren(ni.getChildren().iterator(), current, current != ni);
+ }
+ }
+ }
+ }
+
+ public String[] getActiveOnVieIds() {
+ String value = getActiveOnViewIds();
+ if (value == null)
+ return new String[]{};
+ return value.split(",");
+ }
+
+ private void openParents() {
+ UIComponent comp = this;
+
+ while ((comp = comp.getParent()) instanceof HtmlCommandNavigationItem) {
+ HtmlCommandNavigationItem parent = (HtmlCommandNavigationItem) comp;
+ if (!parent.isOpen()) {
+ parent.setOpen(true);
+ }
+ else {
+ return;
+ }
+ }
+ }
+
+ public void deactivateAll() {
+ UIComponent parent = this.getParent();
+ while (!(parent instanceof HtmlPanelNavigationMenu) && parent != null) {
+ parent = parent.getParent();
+ }
+ if (parent == null) {
+ throw new IllegalStateException("no PanelNavigationMenu!");
+ }
+
+ HtmlPanelNavigationMenu root = (HtmlPanelNavigationMenu) parent;
+ for (Iterator it = root.getChildren().iterator(); it.hasNext();) {
+ Object o = it.next();
+ if (o instanceof HtmlCommandNavigationItem) {
+ HtmlCommandNavigationItem navItem = (HtmlCommandNavigationItem) o;
+ navItem.setActive(false);
+ if (navItem.getChildCount() > 0) {
+ navItem.deactivateChildren();
+ }
+ }
+ }
+ }
+
+ public void deactivateChildren() {
+ for (Iterator it = this.getChildren().iterator(); it.hasNext();) {
+ Object o = it.next();
+ if (o instanceof HtmlCommandNavigationItem) {
+ HtmlCommandNavigationItem current = (HtmlCommandNavigationItem) o;
+ current.setActive(false);
+ if (current.getChildCount() > 0) {
+ current.deactivateChildren();
+ }
+ }
+ }
+ }
+
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+ if (event instanceof ActionEvent) {
+ ActionEvent actionEvent = (ActionEvent) event;
+ if (actionEvent.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES) {
+ HtmlCommandNavigationItem navItem = (HtmlCommandNavigationItem) actionEvent.getComponent();
+ navItem.toggleOpen();
+ FacesContext.getCurrentInstance().renderResponse();
+ }
+ }
+ super.broadcast(event);
+ }
+
+
+ public Object saveState(FacesContext context) {
+ Object values[] = new Object[5];
+ values[0] = super.saveState(context);
+ values[1] = _open;
+ values[2] = _active;
+ values[3] = _activeOnViewIds;
+ values[4] = _externalLink;
+ return ((Object) (values));
+ }
+
+ public void restoreState(FacesContext context, Object state) {
+ Object values[] = (Object[]) state;
+ super.restoreState(context, values[0]);
+ _open = ((Boolean) values[1]);
+ _active = ((Boolean) values[2]);
+ _activeOnViewIds = ((String) values[3]);
+ _externalLink = ((String) values[4]);
+ }
+
+ //------------------ GENERATED CODE BEGIN (do not modify!) --------------------
+
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlCommandNavigationItem";
+ public static final String COMPONENT_FAMILY = "javax.faces.Command";
+ private static final String DEFAULT_RENDERER_TYPE = "javax.faces.Link";
+
+
+ public HtmlCommandNavigationItem() {
+ setRendererType(DEFAULT_RENDERER_TYPE);
+ }
+
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ //------------------ GENERATED CODE END ---------------------------------------
+}
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlCommandNavigationItem.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlCommandNavigationItemTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlCommandNavigationItemTag.java?rev=427657&r1=427656&r2=427657&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlCommandNavigationItemTag.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlCommandNavigationItemTag.java Tue Aug 1 10:43:28 2006
@@ -1,69 +1,69 @@
-/*
- * Copyright 2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.myfaces.custom.navmenu.htmlnavmenu;
-
-import org.apache.myfaces.taglib.html.ext.HtmlCommandLinkTag;
-
-import javax.faces.component.UIComponent;
-
-/**
- * @author Manfred Geiler
- * @author Thomas Spiegl
- */
-public class HtmlCommandNavigationItemTag extends HtmlCommandLinkTag {
- private static final String OPEN_ATTR = "open".intern();
- private static final String ACTIVE_ATTR = "active".intern();
- private static final String ACTIVE_ON_VIEW_IDS_ATTR = "activeOnViewIds".intern();
- private static final String EXTERNAL_LINK = "externalLink".intern();
-
- private String _open;
- private String _active;
- private String _activeOnViewIds;
- private String _externalLink;
-
- public String getComponentType() {
- return HtmlCommandNavigationItem.COMPONENT_TYPE;
- }
-
- public String getRendererType() {
- return HtmlNavigationMenuRenderer.RENDERER_TYPE;
- }
-
- protected void setProperties(UIComponent component) {
- super.setProperties(component);
-
- setBooleanProperty(component, OPEN_ATTR, _open);
- setBooleanProperty(component, ACTIVE_ATTR, _active);
- setStringProperty(component, ACTIVE_ON_VIEW_IDS_ATTR, _activeOnViewIds);
- setStringProperty(component, EXTERNAL_LINK, _externalLink);
- }
-
- public void setOpen(String open) {
- _open = open;
- }
-
- public void setActive(String active) {
- _active = active;
- }
-
- public void setActiveOnViewIds(String activeOnViewIds) {
- _activeOnViewIds = activeOnViewIds;
- }
-
- public void setExternalLink(String externalLink) {
- _externalLink = externalLink;
- }
-}
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.custom.navmenu.htmlnavmenu;
+
+import org.apache.myfaces.taglib.html.ext.HtmlCommandLinkTag;
+
+import javax.faces.component.UIComponent;
+
+/**
+ * @author Manfred Geiler
+ * @author Thomas Spiegl
+ */
+public class HtmlCommandNavigationItemTag extends HtmlCommandLinkTag {
+ private static final String OPEN_ATTR = "open".intern();
+ private static final String ACTIVE_ATTR = "active".intern();
+ private static final String ACTIVE_ON_VIEW_IDS_ATTR = "activeOnViewIds".intern();
+ private static final String EXTERNAL_LINK = "externalLink".intern();
+
+ private String _open;
+ private String _active;
+ private String _activeOnViewIds;
+ private String _externalLink;
+
+ public String getComponentType() {
+ return HtmlCommandNavigationItem.COMPONENT_TYPE;
+ }
+
+ public String getRendererType() {
+ return HtmlNavigationMenuRenderer.RENDERER_TYPE;
+ }
+
+ protected void setProperties(UIComponent component) {
+ super.setProperties(component);
+
+ setBooleanProperty(component, OPEN_ATTR, _open);
+ setBooleanProperty(component, ACTIVE_ATTR, _active);
+ setStringProperty(component, ACTIVE_ON_VIEW_IDS_ATTR, _activeOnViewIds);
+ setStringProperty(component, EXTERNAL_LINK, _externalLink);
+ }
+
+ public void setOpen(String open) {
+ _open = open;
+ }
+
+ public void setActive(String active) {
+ _active = active;
+ }
+
+ public void setActiveOnViewIds(String activeOnViewIds) {
+ _activeOnViewIds = activeOnViewIds;
+ }
+
+ public void setExternalLink(String externalLink) {
+ _externalLink = externalLink;
+ }
+}
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlCommandNavigationItemTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlNavigationMenuRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlNavigationMenuRenderer.java?rev=427657&r1=427656&r2=427657&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlNavigationMenuRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlNavigationMenuRenderer.java Tue Aug 1 10:43:28 2006
@@ -1,560 +1,560 @@
-/*
- * Copyright 2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.myfaces.custom.navmenu.htmlnavmenu;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.custom.navmenu.NavigationMenuItem;
-import org.apache.myfaces.custom.navmenu.NavigationMenuUtils;
-import org.apache.myfaces.custom.navmenu.UINavigationMenuItem;
-import org.apache.myfaces.renderkit.html.ext.HtmlLinkRenderer;
-import org.apache.myfaces.renderkit.html.util.AddResource;
-import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
-import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
-import org.apache.myfaces.renderkit.html.ext.HtmlLinkRenderer;
-
-import javax.faces.component.*;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.event.ActionListener;
-import javax.faces.el.ValueBinding;
-import javax.faces.event.ActionListener;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.myfaces.renderkit.html.util.AddResource;
-import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
-
-/**
- * Many thanks to the guys from Swiss Federal Institute of Intellectual Property & Marc Bouquet
- * for helping to develop this component.
- *
- * @author Thomas Spiegl
- * @author Manfred Geiler
- */
-public class HtmlNavigationMenuRenderer extends HtmlLinkRenderer {
- private static final Log log = LogFactory.getLog(HtmlNavigationMenuRenderer.class);
-
- public static final String RENDERER_TYPE = "org.apache.myfaces.NavigationMenu";
-
- private static final Integer ZERO_INTEGER = new Integer(0);
-
- private static final String HORIZ_MENU_SCRIPT = "HMenuIEHover.js";
-
- public boolean getRendersChildren() {
- return true;
- }
-
- public void decode(FacesContext facesContext, UIComponent component) {
- if (component instanceof HtmlCommandNavigationItem) {
- //HtmlCommandNavigation
- super.decode(facesContext, component);
- }
- }
-
- public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
- if (component instanceof HtmlCommandNavigationItem) {
- //HtmlCommandNavigationItem
- super.encodeBegin(facesContext, component);
- }
- }
-
- public void encodeChildren(FacesContext facesContext, UIComponent component) throws IOException {
- if (component instanceof HtmlCommandNavigationItem) {
- //HtmlCommandNavigationItem
- super.encodeChildren(facesContext, component);
- }
- }
-
- public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
- if (component instanceof HtmlCommandNavigationItem) {
- //HtmlCommandNavigationItem
- super.encodeEnd(facesContext, component);
- return;
- }
- RendererUtils.checkParamValidity(facesContext, component, HtmlPanelNavigationMenu.class);
- HtmlPanelNavigationMenu panelNav = (HtmlPanelNavigationMenu) component;
-
- if (HtmlNavigationMenuRendererUtils.isListLayout(panelNav)) {
- boolean preprocess = true;
- boolean clientStateSaving = facesContext.getApplication().getStateManager().isSavingStateInClient(facesContext);
- if (clientStateSaving) {
- // client statesaving
- HtmlPanelNavigationMenu panelNavPrev = findPreviousPanelNav(facesContext, panelNav);
- if (panelNavPrev != null) {
- preprocess = false;
- if (!panelNavPrev.equals(panelNav)) {
- // substitute panelnav
- UIComponent parent = panelNav.getParent();
- int insertPos = parent.getChildren().indexOf(panelNav);
- parent.getChildren().set(insertPos, panelNavPrev);
- panelNavPrev.setParent(parent);
- panelNav.setParent(null);
- panelNav = panelNavPrev;
- }
- }
- }
- else {
- // server statesaving
- if (panelNav.getPreprocessed() != null && panelNav.getPreprocessed().booleanValue())
- preprocess = false;
- }
- if (preprocess) {
- panelNav.setPreprocessed(Boolean.TRUE);
- preprocessNavigationItems(facesContext, panelNav, panelNav.getChildren(), new UniqueId());
- if (!clientStateSaving) {
- HtmlPanelNavigationMenu panelNavPrev = findPreviousPanelNav(facesContext, panelNav);
- if (panelNavPrev != null) {
- restoreOpenActiveStates(facesContext, panelNav, panelNavPrev.getChildren());
- }
- }
- }
- // render list
- if (log.isDebugEnabled())
- HtmlNavigationMenuRendererUtils.debugTree(log, facesContext, panelNav.getChildren(), 0);
- renderListLayout(facesContext, panelNav);
- }
- else {
- renderTableLayout(facesContext, panelNav);
- }
- }
-
- private void restoreOpenActiveStates(FacesContext facesContext,
- HtmlPanelNavigationMenu panelNav, List children) {
- for (int i = 0, size = children.size(); i < size; i++) {
- UIComponent uiComponent = (UIComponent) children.get(i);
- if (uiComponent instanceof HtmlCommandNavigationItem) {
- HtmlCommandNavigationItem prevItem = (HtmlCommandNavigationItem) uiComponent;
- if (prevItem.isOpen() || prevItem.isActive()) {
- HtmlCommandNavigationItem item = (HtmlCommandNavigationItem) panelNav.findComponent(uiComponent.getClientId(facesContext));
- if (item != null) {
- if (item.getActiveDirectly() != null && item.getActiveDirectly().booleanValue()) {
- item.setActive(prevItem.isActive());
- }
- else {
- copyValueBinding(prevItem, item, "active");
- }
-
- if (item.getOpenDirectly() != null && item.getOpenDirectly().booleanValue()) {
- item.setOpen(prevItem.isOpen());
- }
- else {
- copyValueBinding(prevItem, item, "open");
- }
- if (!panelNav.isExpandAll() || prevItem.isActive())
- item.toggleOpen();
- if (prevItem.isOpen())
- restoreOpenActiveStates(facesContext, panelNav, prevItem.getChildren());
- }
- }
- }
- }
- }
-
- private HtmlPanelNavigationMenu findPreviousPanelNav(FacesContext facesContext, HtmlPanelNavigationMenu panelNav) {
- UIViewRoot previousViewRoot = findPreviousRoot(facesContext);
- if (previousViewRoot != null) {
- return (HtmlPanelNavigationMenu) previousViewRoot.findComponent(panelNav.getClientId(facesContext));
- }
- return null;
- }
-
- private UIViewRoot findPreviousRoot(FacesContext facesContext) {
- return (UIViewRoot) facesContext.getExternalContext().getRequestMap().get(HtmlPanelNavigationMenu.PREVIOUS_VIEW_ROOT);
- }
-
- protected void renderListLayout(FacesContext facesContext, HtmlPanelNavigationMenu panelNav) throws IOException {
- if (panelNav.isRenderAll())
- addResourcesToHeader(facesContext);
-
- ResponseWriter writer = facesContext.getResponseWriter();
- if (panelNav.getChildCount() > 0) {
- HtmlRendererUtils.writePrettyLineSeparator(facesContext);
- writer.startElement(HTML.UL_ELEM, panelNav);
-
- HtmlRendererUtils.renderHTMLAttributes(writer, panelNav, HTML.UL_PASSTHROUGH_ATTRIBUTES);
-
- //iterate over the tree and toggleOpen if viewId in item.getActiveOnVieIds()
- activeOnViewId(panelNav, facesContext.getViewRoot().getViewId());
- //iterate over the tree and set every item open if expandAll
- if (panelNav.isExpandAll()) {
- expandAll(panelNav);
- }
-
- HtmlNavigationMenuRendererUtils.renderChildrenListLayout(facesContext, writer, panelNav, panelNav.getChildren(), 0);
-
- HtmlRendererUtils.writePrettyLineSeparator(facesContext);
- writer.endElement(HTML.UL_ELEM);
- }
- else {
- if (log.isWarnEnabled()) log.warn("PanelNavaigationMenu without children.");
- }
- }
-
- private void renderTableLayout(FacesContext facesContext, HtmlPanelNavigationMenu panelNav) throws IOException {
- ResponseWriter writer = facesContext.getResponseWriter();
-
- if (panelNav.getChildCount() > 0) {
- HtmlRendererUtils.writePrettyLineSeparator(facesContext);
- writer.startElement(HTML.TABLE_ELEM, panelNav);
- HtmlRendererUtils.renderHTMLAttributes(writer, panelNav, HTML.TABLE_PASSTHROUGH_ATTRIBUTES);
- if (panelNav.getStyle() == null && panelNav.getStyleClass() == null) {
- writer.writeAttribute(HTML.BORDER_ATTR, ZERO_INTEGER, null);
- }
-
- HtmlNavigationMenuRendererUtils.renderChildrenTableLayout(facesContext, writer, panelNav, panelNav.getChildren(), 0);
-
- HtmlRendererUtils.writePrettyLineSeparator(facesContext);
- writer.endElement(HTML.TABLE_ELEM);
- }
- else {
- if (log.isWarnEnabled()) log.warn("PanelNavaigationMenu without children.");
- }
- }
-
- private void addResourcesToHeader(FacesContext context) {
- AddResource addResource = AddResourceFactory.getInstance(context);
- addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, HtmlPanelNavigationMenu.class, HORIZ_MENU_SCRIPT);
- }
-
- /**
- * look for UINavigationMenuItem && UISelectItems & create components
- */
- private void preprocessNavigationItems(FacesContext facesContext, UIComponent parent,
- List children, UniqueId uniqueId) {
- for (int i = 0; i < children.size(); i++) {
- UIComponent child = (UIComponent) children.get(i);
-
- if (child instanceof HtmlCommandNavigationItem) {
- HtmlCommandNavigationItem navMenuItem = (HtmlCommandNavigationItem) child;
- preprocessNavigationItems(facesContext, navMenuItem, navMenuItem.getChildren(), uniqueId);
- }
- else if (child instanceof UINavigationMenuItem) {
- UINavigationMenuItem uiNavMenuItem = (UINavigationMenuItem) child;
- createHtmlCommandNavigationItem(facesContext, parent, i, uiNavMenuItem, uniqueId);
- }
- else if (child instanceof UISelectItems) {
- List list = new ArrayList();
- if (child.getId() == null) {
- child.setId("testit");
- }
- NavigationMenuUtils.addNavigationMenuItems((UISelectItems) child, list);
- addUINavigationMenuItems(facesContext, parent, children, i + 1, list);
- }
- }
- }
-
- private void addUINavigationMenuItems(FacesContext facesContext, UIComponent parent, List children, int startIndex, List menuItems) {
- String clientId = parent.getClientId(facesContext);
- clientId = clientId.replaceAll(":", "_");
- for (int j = 0, sizej = menuItems.size(); j < sizej; j++) {
- NavigationMenuItem navigationMenuItem = (NavigationMenuItem) menuItems.get(j);
- UINavigationMenuItem uiNavigationMenuItem =
- (UINavigationMenuItem) facesContext.getApplication().createComponent(UINavigationMenuItem.COMPONENT_TYPE);
- uiNavigationMenuItem.setId(clientId + "_uinavmitem" + (startIndex + j));
- uiNavigationMenuItem.getClientId(facesContext); // create clientid
- children.add(startIndex++, uiNavigationMenuItem);
- uiNavigationMenuItem.setParent(parent);
- if (navigationMenuItem.getAction() != null) {
- uiNavigationMenuItem.setAction(HtmlNavigationMenuRendererUtils.getMethodBinding(facesContext, navigationMenuItem.getAction(), false));
- }
- if (navigationMenuItem.getActionListener() != null) {
- uiNavigationMenuItem.setActionListener(HtmlNavigationMenuRendererUtils.getMethodBinding(facesContext,
- navigationMenuItem.getActionListener(), true));
- }
- uiNavigationMenuItem.setIcon(navigationMenuItem.getIcon());
- uiNavigationMenuItem.setRendered(navigationMenuItem.isRendered());
- uiNavigationMenuItem.setActiveOnViewIds(navigationMenuItem.getActiveOnViewIds());
- uiNavigationMenuItem.setSplit(navigationMenuItem.isSplit());
- uiNavigationMenuItem.setItemLabel(navigationMenuItem.getLabel());
- uiNavigationMenuItem.setOpen(navigationMenuItem.isOpen());
- uiNavigationMenuItem.setActive(navigationMenuItem.isActive());
- uiNavigationMenuItem.setValue(navigationMenuItem.getValue());
- HtmlNavigationMenuRendererUtils.setAttributeValue(facesContext, uiNavigationMenuItem,
- "externalLink", navigationMenuItem.getExternalLink());
- //uiNavigationMenuItem.setExternalLink(navigationMenuItem.getExternalLink());
- uiNavigationMenuItem.setTransient(false);
- uiNavigationMenuItem.setTarget(navigationMenuItem.getTarget());
- uiNavigationMenuItem.setDisabled(navigationMenuItem.isDisabled());
- uiNavigationMenuItem.setDisabledStyle(navigationMenuItem.getDisabledStyle());
- uiNavigationMenuItem.setDisabledStyleClass(navigationMenuItem.getDisabledStyleClass());
-
- if (navigationMenuItem.getNavigationMenuItems() != null && navigationMenuItem.getNavigationMenuItems().length > 0)
- {
- addUINavigationMenuItems(facesContext, uiNavigationMenuItem, uiNavigationMenuItem.getChildren(), 0,
- Arrays.asList(navigationMenuItem.getNavigationMenuItems()));
- }
- }
- }
-
- private HtmlPanelNavigationMenu getParentPanelNavigation(UIComponent uiComponent) {
- if (uiComponent instanceof HtmlPanelNavigationMenu) {
- return (HtmlPanelNavigationMenu) uiComponent;
- }
- UIComponent parent = uiComponent.getParent();
-
- // search HtmlPanelNavigation
- UIComponent p = parent;
- while (p != null && !(p instanceof HtmlPanelNavigationMenu)) {
- p = p.getParent();
- }
- // p is now the HtmlPanelNavigation
- if (p == null) {
- log.error("HtmlCommandNavigation without parent HtmlPanelNavigation ?!");
- return null;
- }
- return (HtmlPanelNavigationMenu) p;
- }
-
- private void createHtmlCommandNavigationItem(FacesContext facesContext, UIComponent parent, int i,
- UINavigationMenuItem uiNavMenuItem, UniqueId uniqueId) {
- HtmlPanelNavigationMenu menu = getParentPanelNavigation(parent);
- // Create HtmlCommandNavigationItem
- HtmlCommandNavigationItem newItem = (HtmlCommandNavigationItem)
- facesContext.getApplication().createComponent(HtmlCommandNavigationItem.COMPONENT_TYPE);
- String parentId = parent.getClientId(facesContext);
- parentId = parentId.replaceAll(":", "_");
- int id = uniqueId.next();
- newItem.setId(parentId + "_item" + id);
- newItem.getClientId(facesContext); // create clientid
- newItem.setRendererType(RENDERER_TYPE);
- parent.getChildren().add(i + 1, newItem);
- newItem.setParent(parent);
- // set action & actionListner
- newItem.setAction(uiNavMenuItem.getAction());
- newItem.setActionListener(uiNavMenuItem.getActionListener());
- ActionListener[] listeners = uiNavMenuItem.getActionListeners();
- for (int j = 0; j < listeners.length; j++) {
- newItem.addActionListener(listeners[j]);
- }
- // value
- newItem.setValue(uiNavMenuItem.getValue());
- // immeditate
- if (!copyValueBinding(uiNavMenuItem, newItem, "immediate"))
- newItem.setImmediate(uiNavMenuItem.isImmediate());
- // transient, rendered
- if (!copyValueBinding(uiNavMenuItem, newItem, "transient"))
- newItem.setTransient(uiNavMenuItem.isTransient());
- if (!copyValueBinding(uiNavMenuItem, newItem, "rendered"))
- newItem.setRendered(uiNavMenuItem.isRendered());
- if (!copyValueBinding(uiNavMenuItem, newItem, "externalLink"))
- newItem.setExternalLink(uiNavMenuItem.getExternalLink());
- if (!copyValueBinding(uiNavMenuItem, newItem, "activeOnViewIds"))
- newItem.setActiveOnViewIds(uiNavMenuItem.getActiveOnViewIds());
-
- if (uiNavMenuItem.isOpen() && ! menu.isExpandAll())
- newItem.toggleOpen();
-
- if (uiNavMenuItem.getActiveDirectly() != null) {
- newItem.setActive(uiNavMenuItem.isActive());
- }
- else {
- newItem.setValueBinding("active", uiNavMenuItem.getValueBinding("active"));
- }
-
- if (!copyValueBinding(uiNavMenuItem, newItem, "target"))
- newItem.setTarget(uiNavMenuItem.getTarget());
- if (!copyValueBinding(uiNavMenuItem, newItem, "disabled"))
- newItem.setDisabled(uiNavMenuItem.isDisabled());
- if (!copyValueBinding(uiNavMenuItem, newItem, "disabledStyle"))
- newItem.setDisabledStyle(uiNavMenuItem.getDisabledStyle());
- if (!copyValueBinding(uiNavMenuItem, newItem, "disabledStyleClass"))
- newItem.setDisabledStyleClass(uiNavMenuItem.getDisabledStyleClass());
-
- if (uiNavMenuItem.getActiveOnViewIdsDirectly() != null) {
- newItem.setActiveOnViewIds(uiNavMenuItem.getActiveOnViewIdsDirectly());
- }
-
- // If the parent-Element is disabled the child is disabled as well
- if (parent instanceof HtmlPanelNavigationMenu) {
- if (newItem.getDisabledStyle() == null) {
- newItem.setDisabledStyle(
- ((HtmlPanelNavigationMenu) parent).getDisabledStyle()
- );
- }
- if (newItem.getDisabledStyleClass() == null) {
- newItem.setDisabledStyleClass(
- ((HtmlPanelNavigationMenu) parent).getDisabledStyleClass()
- );
- }
- if (((HtmlPanelNavigationMenu) parent).isDisabled()) {
- newItem.setDisabled(true);
- }
- }
- if (parent instanceof HtmlCommandNavigationItem) {
- if (newItem.getDisabledStyle() == null) {
- newItem.setDisabledStyle(
- ((HtmlCommandNavigationItem) parent).getDisabledStyle()
- );
- }
- if (newItem.getDisabledStyleClass() == null) {
- newItem.setDisabledStyleClass(
- ((HtmlCommandNavigationItem) parent).getDisabledStyleClass()
- );
- }
- if (((HtmlCommandNavigationItem) parent).isDisabled()) {
- newItem.setDisabled(true);
- }
- }
-
- if (uiNavMenuItem.getIcon() != null) {
- UIGraphic uiGraphic = (UIGraphic) facesContext.getApplication().createComponent(UIGraphic.COMPONENT_TYPE);
- uiGraphic.setId(parentId + "_img" + id);
- uiGraphic.getClientId(facesContext);
- newItem.getChildren().add(uiGraphic);
- uiGraphic.setParent(newItem);
- if (HtmlNavigationMenuRendererUtils.isValueReference(uiNavMenuItem.getIcon())) {
- uiGraphic.setValueBinding("value",
- facesContext.getApplication().createValueBinding(uiNavMenuItem.getIcon()));
- }
- else {
- uiGraphic.setValue(uiNavMenuItem.getIcon());
- }
- }
-
- else {
- // Create and add UIOutput
- UIOutput uiOutput = (UIOutput) facesContext.getApplication().createComponent(UIOutput.COMPONENT_TYPE);
- uiOutput.setId(parentId + "_txt" + id);
- uiOutput.getClientId(facesContext); // create clientid
- newItem.getChildren().add(uiOutput);
- uiOutput.setParent(newItem);
- if (uiNavMenuItem.getItemLabel() != null) {
- if (HtmlNavigationMenuRendererUtils.isValueReference(uiNavMenuItem.getItemLabel())) {
- uiOutput.setValueBinding("value",
- facesContext.getApplication().createValueBinding(uiNavMenuItem.getItemLabel()));
- }
- else {
- uiOutput.setValue(uiNavMenuItem.getItemLabel());
- }
- }
- else {
- Object value = uiNavMenuItem.getValue();
- if (value != null &&
- HtmlNavigationMenuRendererUtils.isValueReference(value.toString())) {
- uiOutput.setValueBinding("value",
- facesContext.getApplication().createValueBinding(value.toString()));
- }
- else {
- uiOutput.setValue(uiNavMenuItem.getValue());
- }
- }
- }
- // process next level
- log.debug("Instance of UINavigationMenuItem, preprocess childrens");
- preprocessNavigationItems(facesContext, newItem, uiNavMenuItem.getChildren(), uniqueId);
- }
-
- private boolean copyValueBinding(UIComponent source, UIComponent target, String binding) {
- ValueBinding valueBinding = source.getValueBinding(binding);
- if (valueBinding == null)
- return false;
- target.setValueBinding(binding, valueBinding);
- return true;
- }
-
-// protected
-
- protected String getStyle(FacesContext facesContext, UIComponent link) {
- if (!(link instanceof HtmlCommandNavigationItem)) {
- throw new IllegalArgumentException("expected instance of " + HtmlCommandNavigationItem.class.getName());
- }
-
- UIComponent navPanel = HtmlNavigationMenuRendererUtils.getPanel(link);
-
- HtmlCommandNavigationItem navItem = (HtmlCommandNavigationItem) link;
- if (navItem.isActive()) {
- return ((HtmlPanelNavigationMenu) navPanel).getActiveItemStyle();
- }
- else if (navItem.isOpen()) {
- return ((HtmlPanelNavigationMenu) navPanel).getOpenItemStyle();
- }
- else {
- return ((HtmlPanelNavigationMenu) navPanel).getItemStyle();
- }
- }
-
- protected String getStyleClass(FacesContext facesContext, UIComponent link) {
- if (!(link instanceof HtmlCommandNavigationItem)) {
- throw new IllegalArgumentException();
- }
-
- UIComponent navPanel = HtmlNavigationMenuRendererUtils.getPanel(link);
-
- HtmlCommandNavigationItem navItem = (HtmlCommandNavigationItem) link;
- if (navItem.isActive()) {
- return ((HtmlPanelNavigationMenu) navPanel).getActiveItemClass();
- }
- else if (navItem.isOpen()) {
- return ((HtmlPanelNavigationMenu) navPanel).getOpenItemClass();
- }
- else {
- return ((HtmlPanelNavigationMenu) navPanel).getItemClass();
- }
- }
-
- private static class UniqueId {
- private int _id;
-
- public int next() {
- return _id++;
- }
-
- public void decrease() {
- _id--;
- }
- }
-
- private void expandAll(UIComponent parent) {
- //Recurse over all Children setOpen if child is HtmlCommandNavigationItem
- if (parent instanceof HtmlCommandNavigationItem) {
- HtmlCommandNavigationItem navItem = (HtmlCommandNavigationItem) parent;
- navItem.setOpen(true);
- }
- List children = parent.getChildren();
- UIComponent child;
- for (int i = 0; i < children.size(); i++) {
- child = (UIComponent) children.get(i);
- expandAll(child);
- }
- }
-
- private void activeOnViewId(UIComponent parent, String viewId) {
- //Recurse over all Children setOpen if child is HtmlCommandNavigationItem
- if (parent instanceof HtmlCommandNavigationItem) {
- HtmlCommandNavigationItem navItem = (HtmlCommandNavigationItem) parent;
- String[] viewIds = navItem.getActiveOnVieIds();
- for (int i = 0; i < viewIds.length; i++) {
- if (viewId.equals(viewIds[i])) {
- navItem.toggleOpen();
- navItem.setActive(true);
- return;
- }
- }
- ;
- }
- List children = parent.getChildren();
- UIComponent child;
- for (int i = 0; i < children.size(); i++) {
- child = (UIComponent) children.get(i);
- activeOnViewId(child, viewId);
- }
- }
-}
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.custom.navmenu.htmlnavmenu;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.custom.navmenu.NavigationMenuItem;
+import org.apache.myfaces.custom.navmenu.NavigationMenuUtils;
+import org.apache.myfaces.custom.navmenu.UINavigationMenuItem;
+import org.apache.myfaces.renderkit.html.ext.HtmlLinkRenderer;
+import org.apache.myfaces.renderkit.html.util.AddResource;
+import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
+import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
+import org.apache.myfaces.renderkit.html.ext.HtmlLinkRenderer;
+
+import javax.faces.component.*;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.event.ActionListener;
+import javax.faces.el.ValueBinding;
+import javax.faces.event.ActionListener;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.myfaces.renderkit.html.util.AddResource;
+import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
+
+/**
+ * Many thanks to the guys from Swiss Federal Institute of Intellectual Property & Marc Bouquet
+ * for helping to develop this component.
+ *
+ * @author Thomas Spiegl
+ * @author Manfred Geiler
+ */
+public class HtmlNavigationMenuRenderer extends HtmlLinkRenderer {
+ private static final Log log = LogFactory.getLog(HtmlNavigationMenuRenderer.class);
+
+ public static final String RENDERER_TYPE = "org.apache.myfaces.NavigationMenu";
+
+ private static final Integer ZERO_INTEGER = new Integer(0);
+
+ private static final String HORIZ_MENU_SCRIPT = "HMenuIEHover.js";
+
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+ public void decode(FacesContext facesContext, UIComponent component) {
+ if (component instanceof HtmlCommandNavigationItem) {
+ //HtmlCommandNavigation
+ super.decode(facesContext, component);
+ }
+ }
+
+ public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
+ if (component instanceof HtmlCommandNavigationItem) {
+ //HtmlCommandNavigationItem
+ super.encodeBegin(facesContext, component);
+ }
+ }
+
+ public void encodeChildren(FacesContext facesContext, UIComponent component) throws IOException {
+ if (component instanceof HtmlCommandNavigationItem) {
+ //HtmlCommandNavigationItem
+ super.encodeChildren(facesContext, component);
+ }
+ }
+
+ public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
+ if (component instanceof HtmlCommandNavigationItem) {
+ //HtmlCommandNavigationItem
+ super.encodeEnd(facesContext, component);
+ return;
+ }
+ RendererUtils.checkParamValidity(facesContext, component, HtmlPanelNavigationMenu.class);
+ HtmlPanelNavigationMenu panelNav = (HtmlPanelNavigationMenu) component;
+
+ if (HtmlNavigationMenuRendererUtils.isListLayout(panelNav)) {
+ boolean preprocess = true;
+ boolean clientStateSaving = facesContext.getApplication().getStateManager().isSavingStateInClient(facesContext);
+ if (clientStateSaving) {
+ // client statesaving
+ HtmlPanelNavigationMenu panelNavPrev = findPreviousPanelNav(facesContext, panelNav);
+ if (panelNavPrev != null) {
+ preprocess = false;
+ if (!panelNavPrev.equals(panelNav)) {
+ // substitute panelnav
+ UIComponent parent = panelNav.getParent();
+ int insertPos = parent.getChildren().indexOf(panelNav);
+ parent.getChildren().set(insertPos, panelNavPrev);
+ panelNavPrev.setParent(parent);
+ panelNav.setParent(null);
+ panelNav = panelNavPrev;
+ }
+ }
+ }
+ else {
+ // server statesaving
+ if (panelNav.getPreprocessed() != null && panelNav.getPreprocessed().booleanValue())
+ preprocess = false;
+ }
+ if (preprocess) {
+ panelNav.setPreprocessed(Boolean.TRUE);
+ preprocessNavigationItems(facesContext, panelNav, panelNav.getChildren(), new UniqueId());
+ if (!clientStateSaving) {
+ HtmlPanelNavigationMenu panelNavPrev = findPreviousPanelNav(facesContext, panelNav);
+ if (panelNavPrev != null) {
+ restoreOpenActiveStates(facesContext, panelNav, panelNavPrev.getChildren());
+ }
+ }
+ }
+ // render list
+ if (log.isDebugEnabled())
+ HtmlNavigationMenuRendererUtils.debugTree(log, facesContext, panelNav.getChildren(), 0);
+ renderListLayout(facesContext, panelNav);
+ }
+ else {
+ renderTableLayout(facesContext, panelNav);
+ }
+ }
+
+ private void restoreOpenActiveStates(FacesContext facesContext,
+ HtmlPanelNavigationMenu panelNav, List children) {
+ for (int i = 0, size = children.size(); i < size; i++) {
+ UIComponent uiComponent = (UIComponent) children.get(i);
+ if (uiComponent instanceof HtmlCommandNavigationItem) {
+ HtmlCommandNavigationItem prevItem = (HtmlCommandNavigationItem) uiComponent;
+ if (prevItem.isOpen() || prevItem.isActive()) {
+ HtmlCommandNavigationItem item = (HtmlCommandNavigationItem) panelNav.findComponent(uiComponent.getClientId(facesContext));
+ if (item != null) {
+ if (item.getActiveDirectly() != null && item.getActiveDirectly().booleanValue()) {
+ item.setActive(prevItem.isActive());
+ }
+ else {
+ copyValueBinding(prevItem, item, "active");
+ }
+
+ if (item.getOpenDirectly() != null && item.getOpenDirectly().booleanValue()) {
+ item.setOpen(prevItem.isOpen());
+ }
+ else {
+ copyValueBinding(prevItem, item, "open");
+ }
+ if (!panelNav.isExpandAll() || prevItem.isActive())
+ item.toggleOpen();
+ if (prevItem.isOpen())
+ restoreOpenActiveStates(facesContext, panelNav, prevItem.getChildren());
+ }
+ }
+ }
+ }
+ }
+
+ private HtmlPanelNavigationMenu findPreviousPanelNav(FacesContext facesContext, HtmlPanelNavigationMenu panelNav) {
+ UIViewRoot previousViewRoot = findPreviousRoot(facesContext);
+ if (previousViewRoot != null) {
+ return (HtmlPanelNavigationMenu) previousViewRoot.findComponent(panelNav.getClientId(facesContext));
+ }
+ return null;
+ }
+
+ private UIViewRoot findPreviousRoot(FacesContext facesContext) {
+ return (UIViewRoot) facesContext.getExternalContext().getRequestMap().get(HtmlPanelNavigationMenu.PREVIOUS_VIEW_ROOT);
+ }
+
+ protected void renderListLayout(FacesContext facesContext, HtmlPanelNavigationMenu panelNav) throws IOException {
+ if (panelNav.isRenderAll())
+ addResourcesToHeader(facesContext);
+
+ ResponseWriter writer = facesContext.getResponseWriter();
+ if (panelNav.getChildCount() > 0) {
+ HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+ writer.startElement(HTML.UL_ELEM, panelNav);
+
+ HtmlRendererUtils.renderHTMLAttributes(writer, panelNav, HTML.UL_PASSTHROUGH_ATTRIBUTES);
+
+ //iterate over the tree and toggleOpen if viewId in item.getActiveOnVieIds()
+ activeOnViewId(panelNav, facesContext.getViewRoot().getViewId());
+ //iterate over the tree and set every item open if expandAll
+ if (panelNav.isExpandAll()) {
+ expandAll(panelNav);
+ }
+
+ HtmlNavigationMenuRendererUtils.renderChildrenListLayout(facesContext, writer, panelNav, panelNav.getChildren(), 0);
+
+ HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+ writer.endElement(HTML.UL_ELEM);
+ }
+ else {
+ if (log.isWarnEnabled()) log.warn("PanelNavaigationMenu without children.");
+ }
+ }
+
+ private void renderTableLayout(FacesContext facesContext, HtmlPanelNavigationMenu panelNav) throws IOException {
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ if (panelNav.getChildCount() > 0) {
+ HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+ writer.startElement(HTML.TABLE_ELEM, panelNav);
+ HtmlRendererUtils.renderHTMLAttributes(writer, panelNav, HTML.TABLE_PASSTHROUGH_ATTRIBUTES);
+ if (panelNav.getStyle() == null && panelNav.getStyleClass() == null) {
+ writer.writeAttribute(HTML.BORDER_ATTR, ZERO_INTEGER, null);
+ }
+
+ HtmlNavigationMenuRendererUtils.renderChildrenTableLayout(facesContext, writer, panelNav, panelNav.getChildren(), 0);
+
+ HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+ writer.endElement(HTML.TABLE_ELEM);
+ }
+ else {
+ if (log.isWarnEnabled()) log.warn("PanelNavaigationMenu without children.");
+ }
+ }
+
+ private void addResourcesToHeader(FacesContext context) {
+ AddResource addResource = AddResourceFactory.getInstance(context);
+ addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, HtmlPanelNavigationMenu.class, HORIZ_MENU_SCRIPT);
+ }
+
+ /**
+ * look for UINavigationMenuItem && UISelectItems & create components
+ */
+ private void preprocessNavigationItems(FacesContext facesContext, UIComponent parent,
+ List children, UniqueId uniqueId) {
+ for (int i = 0; i < children.size(); i++) {
+ UIComponent child = (UIComponent) children.get(i);
+
+ if (child instanceof HtmlCommandNavigationItem) {
+ HtmlCommandNavigationItem navMenuItem = (HtmlCommandNavigationItem) child;
+ preprocessNavigationItems(facesContext, navMenuItem, navMenuItem.getChildren(), uniqueId);
+ }
+ else if (child instanceof UINavigationMenuItem) {
+ UINavigationMenuItem uiNavMenuItem = (UINavigationMenuItem) child;
+ createHtmlCommandNavigationItem(facesContext, parent, i, uiNavMenuItem, uniqueId);
+ }
+ else if (child instanceof UISelectItems) {
+ List list = new ArrayList();
+ if (child.getId() == null) {
+ child.setId("testit");
+ }
+ NavigationMenuUtils.addNavigationMenuItems((UISelectItems) child, list);
+ addUINavigationMenuItems(facesContext, parent, children, i + 1, list);
+ }
+ }
+ }
+
+ private void addUINavigationMenuItems(FacesContext facesContext, UIComponent parent, List children, int startIndex, List menuItems) {
+ String clientId = parent.getClientId(facesContext);
+ clientId = clientId.replaceAll(":", "_");
+ for (int j = 0, sizej = menuItems.size(); j < sizej; j++) {
+ NavigationMenuItem navigationMenuItem = (NavigationMenuItem) menuItems.get(j);
+ UINavigationMenuItem uiNavigationMenuItem =
+ (UINavigationMenuItem) facesContext.getApplication().createComponent(UINavigationMenuItem.COMPONENT_TYPE);
+ uiNavigationMenuItem.setId(clientId + "_uinavmitem" + (startIndex + j));
+ uiNavigationMenuItem.getClientId(facesContext); // create clientid
+ children.add(startIndex++, uiNavigationMenuItem);
+ uiNavigationMenuItem.setParent(parent);
+ if (navigationMenuItem.getAction() != null) {
+ uiNavigationMenuItem.setAction(HtmlNavigationMenuRendererUtils.getMethodBinding(facesContext, navigationMenuItem.getAction(), false));
+ }
+ if (navigationMenuItem.getActionListener() != null) {
+ uiNavigationMenuItem.setActionListener(HtmlNavigationMenuRendererUtils.getMethodBinding(facesContext,
+ navigationMenuItem.getActionListener(), true));
+ }
+ uiNavigationMenuItem.setIcon(navigationMenuItem.getIcon());
+ uiNavigationMenuItem.setRendered(navigationMenuItem.isRendered());
+ uiNavigationMenuItem.setActiveOnViewIds(navigationMenuItem.getActiveOnViewIds());
+ uiNavigationMenuItem.setSplit(navigationMenuItem.isSplit());
+ uiNavigationMenuItem.setItemLabel(navigationMenuItem.getLabel());
+ uiNavigationMenuItem.setOpen(navigationMenuItem.isOpen());
+ uiNavigationMenuItem.setActive(navigationMenuItem.isActive());
+ uiNavigationMenuItem.setValue(navigationMenuItem.getValue());
+ HtmlNavigationMenuRendererUtils.setAttributeValue(facesContext, uiNavigationMenuItem,
+ "externalLink", navigationMenuItem.getExternalLink());
+ //uiNavigationMenuItem.setExternalLink(navigationMenuItem.getExternalLink());
+ uiNavigationMenuItem.setTransient(false);
+ uiNavigationMenuItem.setTarget(navigationMenuItem.getTarget());
+ uiNavigationMenuItem.setDisabled(navigationMenuItem.isDisabled());
+ uiNavigationMenuItem.setDisabledStyle(navigationMenuItem.getDisabledStyle());
+ uiNavigationMenuItem.setDisabledStyleClass(navigationMenuItem.getDisabledStyleClass());
+
+ if (navigationMenuItem.getNavigationMenuItems() != null && navigationMenuItem.getNavigationMenuItems().length > 0)
+ {
+ addUINavigationMenuItems(facesContext, uiNavigationMenuItem, uiNavigationMenuItem.getChildren(), 0,
+ Arrays.asList(navigationMenuItem.getNavigationMenuItems()));
+ }
+ }
+ }
+
+ private HtmlPanelNavigationMenu getParentPanelNavigation(UIComponent uiComponent) {
+ if (uiComponent instanceof HtmlPanelNavigationMenu) {
+ return (HtmlPanelNavigationMenu) uiComponent;
+ }
+ UIComponent parent = uiComponent.getParent();
+
+ // search HtmlPanelNavigation
+ UIComponent p = parent;
+ while (p != null && !(p instanceof HtmlPanelNavigationMenu)) {
+ p = p.getParent();
+ }
+ // p is now the HtmlPanelNavigation
+ if (p == null) {
+ log.error("HtmlCommandNavigation without parent HtmlPanelNavigation ?!");
+ return null;
+ }
+ return (HtmlPanelNavigationMenu) p;
+ }
+
+ private void createHtmlCommandNavigationItem(FacesContext facesContext, UIComponent parent, int i,
+ UINavigationMenuItem uiNavMenuItem, UniqueId uniqueId) {
+ HtmlPanelNavigationMenu menu = getParentPanelNavigation(parent);
+ // Create HtmlCommandNavigationItem
+ HtmlCommandNavigationItem newItem = (HtmlCommandNavigationItem)
+ facesContext.getApplication().createComponent(HtmlCommandNavigationItem.COMPONENT_TYPE);
+ String parentId = parent.getClientId(facesContext);
+ parentId = parentId.replaceAll(":", "_");
+ int id = uniqueId.next();
+ newItem.setId(parentId + "_item" + id);
+ newItem.getClientId(facesContext); // create clientid
+ newItem.setRendererType(RENDERER_TYPE);
+ parent.getChildren().add(i + 1, newItem);
+ newItem.setParent(parent);
+ // set action & actionListner
+ newItem.setAction(uiNavMenuItem.getAction());
+ newItem.setActionListener(uiNavMenuItem.getActionListener());
+ ActionListener[] listeners = uiNavMenuItem.getActionListeners();
+ for (int j = 0; j < listeners.length; j++) {
+ newItem.addActionListener(listeners[j]);
+ }
+ // value
+ newItem.setValue(uiNavMenuItem.getValue());
+ // immeditate
+ if (!copyValueBinding(uiNavMenuItem, newItem, "immediate"))
+ newItem.setImmediate(uiNavMenuItem.isImmediate());
+ // transient, rendered
+ if (!copyValueBinding(uiNavMenuItem, newItem, "transient"))
+ newItem.setTransient(uiNavMenuItem.isTransient());
+ if (!copyValueBinding(uiNavMenuItem, newItem, "rendered"))
+ newItem.setRendered(uiNavMenuItem.isRendered());
+ if (!copyValueBinding(uiNavMenuItem, newItem, "externalLink"))
+ newItem.setExternalLink(uiNavMenuItem.getExternalLink());
+ if (!copyValueBinding(uiNavMenuItem, newItem, "activeOnViewIds"))
+ newItem.setActiveOnViewIds(uiNavMenuItem.getActiveOnViewIds());
+
+ if (uiNavMenuItem.isOpen() && ! menu.isExpandAll())
+ newItem.toggleOpen();
+
+ if (uiNavMenuItem.getActiveDirectly() != null) {
+ newItem.setActive(uiNavMenuItem.isActive());
+ }
+ else {
+ newItem.setValueBinding("active", uiNavMenuItem.getValueBinding("active"));
+ }
+
+ if (!copyValueBinding(uiNavMenuItem, newItem, "target"))
+ newItem.setTarget(uiNavMenuItem.getTarget());
+ if (!copyValueBinding(uiNavMenuItem, newItem, "disabled"))
+ newItem.setDisabled(uiNavMenuItem.isDisabled());
+ if (!copyValueBinding(uiNavMenuItem, newItem, "disabledStyle"))
+ newItem.setDisabledStyle(uiNavMenuItem.getDisabledStyle());
+ if (!copyValueBinding(uiNavMenuItem, newItem, "disabledStyleClass"))
+ newItem.setDisabledStyleClass(uiNavMenuItem.getDisabledStyleClass());
+
+ if (uiNavMenuItem.getActiveOnViewIdsDirectly() != null) {
+ newItem.setActiveOnViewIds(uiNavMenuItem.getActiveOnViewIdsDirectly());
+ }
+
+ // If the parent-Element is disabled the child is disabled as well
+ if (parent instanceof HtmlPanelNavigationMenu) {
+ if (newItem.getDisabledStyle() == null) {
+ newItem.setDisabledStyle(
+ ((HtmlPanelNavigationMenu) parent).getDisabledStyle()
+ );
+ }
+ if (newItem.getDisabledStyleClass() == null) {
+ newItem.setDisabledStyleClass(
+ ((HtmlPanelNavigationMenu) parent).getDisabledStyleClass()
+ );
+ }
+ if (((HtmlPanelNavigationMenu) parent).isDisabled()) {
+ newItem.setDisabled(true);
+ }
+ }
+ if (parent instanceof HtmlCommandNavigationItem) {
+ if (newItem.getDisabledStyle() == null) {
+ newItem.setDisabledStyle(
+ ((HtmlCommandNavigationItem) parent).getDisabledStyle()
+ );
+ }
+ if (newItem.getDisabledStyleClass() == null) {
+ newItem.setDisabledStyleClass(
+ ((HtmlCommandNavigationItem) parent).getDisabledStyleClass()
+ );
+ }
+ if (((HtmlCommandNavigationItem) parent).isDisabled()) {
+ newItem.setDisabled(true);
+ }
+ }
+
+ if (uiNavMenuItem.getIcon() != null) {
+ UIGraphic uiGraphic = (UIGraphic) facesContext.getApplication().createComponent(UIGraphic.COMPONENT_TYPE);
+ uiGraphic.setId(parentId + "_img" + id);
+ uiGraphic.getClientId(facesContext);
+ newItem.getChildren().add(uiGraphic);
+ uiGraphic.setParent(newItem);
+ if (HtmlNavigationMenuRendererUtils.isValueReference(uiNavMenuItem.getIcon())) {
+ uiGraphic.setValueBinding("value",
+ facesContext.getApplication().createValueBinding(uiNavMenuItem.getIcon()));
+ }
+ else {
+ uiGraphic.setValue(uiNavMenuItem.getIcon());
+ }
+ }
+
+ else {
+ // Create and add UIOutput
+ UIOutput uiOutput = (UIOutput) facesContext.getApplication().createComponent(UIOutput.COMPONENT_TYPE);
+ uiOutput.setId(parentId + "_txt" + id);
+ uiOutput.getClientId(facesContext); // create clientid
+ newItem.getChildren().add(uiOutput);
+ uiOutput.setParent(newItem);
+ if (uiNavMenuItem.getItemLabel() != null) {
+ if (HtmlNavigationMenuRendererUtils.isValueReference(uiNavMenuItem.getItemLabel())) {
+ uiOutput.setValueBinding("value",
+ facesContext.getApplication().createValueBinding(uiNavMenuItem.getItemLabel()));
+ }
+ else {
+ uiOutput.setValue(uiNavMenuItem.getItemLabel());
+ }
+ }
+ else {
+ Object value = uiNavMenuItem.getValue();
+ if (value != null &&
+ HtmlNavigationMenuRendererUtils.isValueReference(value.toString())) {
+ uiOutput.setValueBinding("value",
+ facesContext.getApplication().createValueBinding(value.toString()));
+ }
+ else {
+ uiOutput.setValue(uiNavMenuItem.getValue());
+ }
+ }
+ }
+ // process next level
+ log.debug("Instance of UINavigationMenuItem, preprocess childrens");
+ preprocessNavigationItems(facesContext, newItem, uiNavMenuItem.getChildren(), uniqueId);
+ }
+
+ private boolean copyValueBinding(UIComponent source, UIComponent target, String binding) {
+ ValueBinding valueBinding = source.getValueBinding(binding);
+ if (valueBinding == null)
+ return false;
+ target.setValueBinding(binding, valueBinding);
+ return true;
+ }
+
+// protected
+
+ protected String getStyle(FacesContext facesContext, UIComponent link) {
+ if (!(link instanceof HtmlCommandNavigationItem)) {
+ throw new IllegalArgumentException("expected instance of " + HtmlCommandNavigationItem.class.getName());
+ }
+
+ UIComponent navPanel = HtmlNavigationMenuRendererUtils.getPanel(link);
+
+ HtmlCommandNavigationItem navItem = (HtmlCommandNavigationItem) link;
+ if (navItem.isActive()) {
+ return ((HtmlPanelNavigationMenu) navPanel).getActiveItemStyle();
+ }
+ else if (navItem.isOpen()) {
+ return ((HtmlPanelNavigationMenu) navPanel).getOpenItemStyle();
+ }
+ else {
+ return ((HtmlPanelNavigationMenu) navPanel).getItemStyle();
+ }
+ }
+
+ protected String getStyleClass(FacesContext facesContext, UIComponent link) {
+ if (!(link instanceof HtmlCommandNavigationItem)) {
+ throw new IllegalArgumentException();
+ }
+
+ UIComponent navPanel = HtmlNavigationMenuRendererUtils.getPanel(link);
+
+ HtmlCommandNavigationItem navItem = (HtmlCommandNavigationItem) link;
+ if (navItem.isActive()) {
+ return ((HtmlPanelNavigationMenu) navPanel).getActiveItemClass();
+ }
+ else if (navItem.isOpen()) {
+ return ((HtmlPanelNavigationMenu) navPanel).getOpenItemClass();
+ }
+ else {
+ return ((HtmlPanelNavigationMenu) navPanel).getItemClass();
+ }
+ }
+
+ private static class UniqueId {
+ private int _id;
+
+ public int next() {
+ return _id++;
+ }
+
+ public void decrease() {
+ _id--;
+ }
+ }
+
+ private void expandAll(UIComponent parent) {
+ //Recurse over all Children setOpen if child is HtmlCommandNavigationItem
+ if (parent instanceof HtmlCommandNavigationItem) {
+ HtmlCommandNavigationItem navItem = (HtmlCommandNavigationItem) parent;
+ navItem.setOpen(true);
+ }
+ List children = parent.getChildren();
+ UIComponent child;
+ for (int i = 0; i < children.size(); i++) {
+ child = (UIComponent) children.get(i);
+ expandAll(child);
+ }
+ }
+
+ private void activeOnViewId(UIComponent parent, String viewId) {
+ //Recurse over all Children setOpen if child is HtmlCommandNavigationItem
+ if (parent instanceof HtmlCommandNavigationItem) {
+ HtmlCommandNavigationItem navItem = (HtmlCommandNavigationItem) parent;
+ String[] viewIds = navItem.getActiveOnVieIds();
+ for (int i = 0; i < viewIds.length; i++) {
+ if (viewId.equals(viewIds[i])) {
+ navItem.toggleOpen();
+ navItem.setActive(true);
+ return;
+ }
+ }
+ ;
+ }
+ List children = parent.getChildren();
+ UIComponent child;
+ for (int i = 0; i < children.size(); i++) {
+ child = (UIComponent) children.get(i);
+ activeOnViewId(child, viewId);
+ }
+ }
+}
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/htmlnavmenu/HtmlNavigationMenuRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native