Author: amarkhel
Date: 2010-12-17 02:18:43 -0500 (Fri, 17 Dec 2010)
New Revision: 20633
Added:
trunk/ui/common/api/src/main/java/org/richfaces/component/Mode.java
Removed:
trunk/ui/output/ui/src/main/java/org/richfaces/component/MenuComponent.java
Modified:
trunk/core/api/src/test/java/org/richfaces/renderkit/util/HtmlDimensionsTest.java
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractDropDownMenu.java
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractMenuGroup.java
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractMenuItem.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/DropDownMenuRendererBase.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/MenuGroupRendererBase.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java
Log:
RF-9789 Dropdown menu component: pre-promotion code review
- HtmlDimensionsTest was updated.
Modified:
trunk/core/api/src/test/java/org/richfaces/renderkit/util/HtmlDimensionsTest.java
===================================================================
---
trunk/core/api/src/test/java/org/richfaces/renderkit/util/HtmlDimensionsTest.java 2010-12-17
01:27:58 UTC (rev 20632)
+++
trunk/core/api/src/test/java/org/richfaces/renderkit/util/HtmlDimensionsTest.java 2010-12-17
07:18:43 UTC (rev 20633)
@@ -21,7 +21,8 @@
*/
package org.richfaces.renderkit.util;
-import org.junit.Assert;
+import static org.junit.Assert.*;
+
import org.junit.Test;
/**
@@ -32,22 +33,23 @@
@Test
public void testFormatSize() {
- Assert.assertEquals("100px",
HtmlDimensions.formatSize("100"));
- Assert.assertEquals("100px", HtmlDimensions.formatSize("100
"));
- Assert.assertEquals("100px", HtmlDimensions.formatSize("
100"));
- Assert.assertEquals("100px", HtmlDimensions.formatSize(" 100
"));
- Assert.assertEquals("t100px",
HtmlDimensions.formatSize("t100"));
- Assert.assertEquals("r100px", HtmlDimensions.formatSize("r100
"));
- Assert.assertEquals("100px ", HtmlDimensions.formatSize("100px
"));
- Assert.assertEquals(" 100px", HtmlDimensions.formatSize("
100px"));
- Assert.assertEquals(" 100px ", HtmlDimensions.formatSize(" 100px
"));
- Assert.assertEquals("100px",
HtmlDimensions.formatSize("100px"));
- Assert.assertEquals("100 px", HtmlDimensions.formatSize("100
px"));
- Assert.assertEquals("99%",
HtmlDimensions.formatSize("99%"));
- Assert.assertEquals("99 %", HtmlDimensions.formatSize("99
%"));
- Assert.assertEquals("100em",
HtmlDimensions.formatSize("100em"));
- Assert.assertEquals("size",
HtmlDimensions.formatSize("size"));
- Assert.assertEquals("", HtmlDimensions.formatSize(""));
- Assert.assertEquals(" ", HtmlDimensions.formatSize("
"));
+ assertEquals("100px", HtmlDimensions.formatSize("100"));
+ assertEquals("100px", HtmlDimensions.formatSize("100 "));
+ assertEquals("100px", HtmlDimensions.formatSize(" 100"));
+ assertEquals("100px", HtmlDimensions.formatSize(" 100
"));
+ assertEquals("t100px", HtmlDimensions.formatSize("t100"));
+ assertEquals("r100px", HtmlDimensions.formatSize("r100 "));
+ assertEquals("100px ", HtmlDimensions.formatSize("100px
"));
+ assertEquals(" 100px", HtmlDimensions.formatSize("
100px"));
+ assertEquals(" 100px ", HtmlDimensions.formatSize(" 100px
"));
+ assertEquals("100px", HtmlDimensions.formatSize("100px"));
+ assertEquals("100 px", HtmlDimensions.formatSize("100 px"));
+ assertEquals("99%", HtmlDimensions.formatSize("99%"));
+ assertEquals("99 %", HtmlDimensions.formatSize("99 %"));
+ assertEquals("100em", HtmlDimensions.formatSize("100em"));
+ assertEquals("size", HtmlDimensions.formatSize("size"));
+ assertEquals("", HtmlDimensions.formatSize(""));
+ assertEquals(" ", HtmlDimensions.formatSize(" "));
+ assertEquals(null, HtmlDimensions.formatSize(null));
}
}
Added: trunk/ui/common/api/src/main/java/org/richfaces/component/Mode.java
===================================================================
--- trunk/ui/common/api/src/main/java/org/richfaces/component/Mode.java
(rev 0)
+++ trunk/ui/common/api/src/main/java/org/richfaces/component/Mode.java 2010-12-17
07:18:43 UTC (rev 20633)
@@ -0,0 +1,28 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.component;
+
+public enum Mode {
+ ajax,
+ client,
+ server;
+}
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractDropDownMenu.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractDropDownMenu.java 2010-12-17
01:27:58 UTC (rev 20632)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractDropDownMenu.java 2010-12-17
07:18:43 UTC (rev 20633)
@@ -13,8 +13,7 @@
renderer=@JsfRenderer(type = DropDownMenuRendererBase.RENDERER_TYPE),
tag = @Tag(name="dropDownMenu"),
attributes = {"events-props.xml", "core-props.xml",
"i18n-props.xml"})
-public abstract class AbstractDropDownMenu extends UIComponentBase
- implements MenuComponent {
+public abstract class AbstractDropDownMenu extends UIComponentBase {
public static final String COMPONENT_TYPE = "org.richfaces.DropDownMenu";
@@ -23,7 +22,7 @@
@Attribute
public abstract String getShowEvent();
- @Attribute(defaultValue = MenuComponent.MODE_SERVER)
+ @Attribute(defaultValue = "server")
public abstract String getMode();
@Attribute
@@ -60,16 +59,7 @@
public abstract String getOnitemclick();
public enum Facets {
- LABEL("label"), LABEL_DISABLED("labelDisabled");
-
- private String facetName;
- private Facets(String name) {
- this.facetName = name;
- }
-
- @Override
- public String toString() {
- return facetName;
- }
+ label,
+ labelDisabled
}
}
Modified: trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractMenuGroup.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractMenuGroup.java 2010-12-17
01:27:58 UTC (rev 20632)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractMenuGroup.java 2010-12-17
07:18:43 UTC (rev 20633)
@@ -54,16 +54,7 @@
public abstract String getOnhide();
public enum Facets {
- ICON("icon"), ICON_DISABLED("iconDisabled");
-
- private String facetName;
- private Facets(String name) {
- this.facetName = name;
- }
-
- @Override
- public String toString() {
- return facetName;
- }
+ icon,
+ iconDisabled
}
}
Modified: trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractMenuItem.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractMenuItem.java 2010-12-17
01:27:58 UTC (rev 20632)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractMenuItem.java 2010-12-17
07:18:43 UTC (rev 20633)
@@ -12,8 +12,7 @@
renderer=@JsfRenderer(type = MenuItemRendererBase.RENDERER_TYPE),
tag = @Tag(name="menuItem"),
attributes = {"events-props.xml", "core-props.xml",
"i18n-props.xml", "ajax-props.xml"})
-public abstract class AbstractMenuItem extends AbstractActionComponent
- implements MenuComponent {
+public abstract class AbstractMenuItem extends AbstractActionComponent {
public static final String COMPONENT_TYPE = "org.richfaces.MenuItem";
@@ -33,16 +32,7 @@
public abstract boolean isDisabled();
public enum Facets {
- ICON("icon"), ICON_DISABLED("iconDisabled");
-
- private String facetName;
- private Facets(String name) {
- this.facetName = name;
- }
-
- @Override
- public String toString() {
- return facetName;
- }
+ icon,
+ iconDisabled
}
}
Deleted: trunk/ui/output/ui/src/main/java/org/richfaces/component/MenuComponent.java
===================================================================
--- trunk/ui/output/ui/src/main/java/org/richfaces/component/MenuComponent.java 2010-12-17
01:27:58 UTC (rev 20632)
+++ trunk/ui/output/ui/src/main/java/org/richfaces/component/MenuComponent.java 2010-12-17
07:18:43 UTC (rev 20633)
@@ -1,44 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.component;
-
-
-/**
- * Interface which main menu must implements in order to menu components could works
correctly.
- * @author F. Antonov
- *
- */
-public interface MenuComponent {
-
- /**
- * Possible values for submit mode property.
- */
- public static final String MODE_AJAX = "ajax";
- public static final String MODE_SERVER = "server";
- public static final String MODE_CLIENT = "client";
-
- /**
- * Getter for submit mode property.
- */
- public String getMode();
- public void setMode(String mode);
-}
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/DropDownMenuRendererBase.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/DropDownMenuRendererBase.java 2010-12-17
01:27:58 UTC (rev 20632)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/DropDownMenuRendererBase.java 2010-12-17
07:18:43 UTC (rev 20633)
@@ -64,9 +64,9 @@
if (ddmenu != null) {
if (ddmenu.isDisabled()) {
- facet =
ddmenu.getFacet(AbstractDropDownMenu.Facets.LABEL_DISABLED.toString());
+ facet =
ddmenu.getFacet(AbstractDropDownMenu.Facets.labelDisabled.toString());
} else {
- facet = ddmenu.getFacet(AbstractDropDownMenu.Facets.LABEL.toString());
+ facet = ddmenu.getFacet(AbstractDropDownMenu.Facets.label.toString());
}
}
return facet;
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/MenuGroupRendererBase.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/MenuGroupRendererBase.java 2010-12-17
01:27:58 UTC (rev 20632)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/MenuGroupRendererBase.java 2010-12-17
07:18:43 UTC (rev 20633)
@@ -39,9 +39,9 @@
if (menuGroup != null) {
if (menuGroup.isDisabled()) {
- facet =
menuGroup.getFacet(AbstractMenuGroup.Facets.ICON_DISABLED.toString());
+ facet =
menuGroup.getFacet(AbstractMenuGroup.Facets.iconDisabled.toString());
} else {
- facet = menuGroup.getFacet(AbstractMenuGroup.Facets.ICON.toString());
+ facet = menuGroup.getFacet(AbstractMenuGroup.Facets.icon.toString());
}
}
return facet;
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java 2010-12-17
01:27:58 UTC (rev 20632)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java 2010-12-17
07:18:43 UTC (rev 20633)
@@ -11,7 +11,7 @@
import org.richfaces.component.AbstractDropDownMenu;
import org.richfaces.component.AbstractMenuGroup;
import org.richfaces.component.AbstractMenuItem;
-import org.richfaces.component.MenuComponent;
+import org.richfaces.component.Mode;
import org.richfaces.renderkit.AjaxCommandRendererBase;
public class MenuItemRendererBase extends AjaxCommandRendererBase {
@@ -31,9 +31,9 @@
if (menuItem != null) {
if (menuItem.isDisabled()) {
- facet =
menuItem.getFacet(AbstractMenuItem.Facets.ICON_DISABLED.toString());
+ facet =
menuItem.getFacet(AbstractMenuItem.Facets.iconDisabled.toString());
} else {
- facet = menuItem.getFacet(AbstractMenuItem.Facets.ICON.toString());
+ facet = menuItem.getFacet(AbstractMenuItem.Facets.icon.toString());
}
}
return facet;
@@ -58,8 +58,8 @@
AbstractMenuItem menuItem = (AbstractMenuItem) component;
if (menuItem != null) {
- String mode = resolveSubmitMode(menuItem);
- if (!MenuComponent.MODE_CLIENT.equalsIgnoreCase(mode)) {
+ Mode mode = resolveSubmitMode(menuItem);
+ if (!Mode.client.equals(mode)) {
super.doDecode(context, component);
}
}
@@ -96,39 +96,35 @@
protected String getOnClickFunction(FacesContext facesContext, UIComponent component)
{
AbstractMenuItem menuItem = (AbstractMenuItem) component;
- String subminMode = resolveSubmitMode(menuItem);
+ Mode subminMode = resolveSubmitMode(menuItem);
if (menuItem.isDisabled()) {
return "";
- } else if (subminMode == null ||
MenuComponent.MODE_SERVER.equalsIgnoreCase(subminMode)) {
+ } else if (subminMode == null || Mode.server.equals(subminMode)) {
return getServerSubmitFunction(menuItem);
- } else if (MenuComponent.MODE_AJAX.equalsIgnoreCase(subminMode)) {
+ } else if (Mode.ajax.equals(subminMode)) {
return getOnClick(facesContext, menuItem);
- } else if (MenuComponent.MODE_CLIENT.equalsIgnoreCase(subminMode)) {
+ } else if (Mode.client.equals(subminMode)) {
return "";
}
return "";
}
- protected String resolveSubmitMode(AbstractMenuItem menuItem) {
+ protected Mode resolveSubmitMode(AbstractMenuItem menuItem) {
String submitMode = menuItem.getMode();
if (null != submitMode) {
- return submitMode;
+ return Mode.valueOf(submitMode);
}
- UIComponent parent = menuItem.getParent();
- while (null != parent) {
- if (parent instanceof MenuComponent) {
- return ((MenuComponent) parent).getMode();
- }
- parent = parent.getParent();
+ AbstractDropDownMenu parent = getDDMenu(menuItem);
+ if (parent != null) {
+ return Mode.valueOf(parent.getMode());
}
-
- return MenuComponent.MODE_SERVER;
+ return Mode.server;
}
protected String getStyleClass(FacesContext facesContext, UIComponent component,
String ddMenuStyle, String menuGroupStyle, String menuItemStyle) {
- UIComponent ddMenu = getDDMenu(facesContext, component);
- UIComponent menuGroup = getMenuGroup(facesContext, component);
+ UIComponent ddMenu = getDDMenu(component);
+ UIComponent menuGroup = getMenuGroup(component);
Object styleClass = null;
if (ddMenu != null && ddMenuStyle != null && ddMenuStyle.length()
> 0) {
styleClass = ddMenu.getAttributes().get(ddMenuStyle);
@@ -140,38 +136,35 @@
return concatClasses(styleClass, component.getAttributes().get(menuItemStyle));
}
+ private UIComponent getParent(UIComponent component, Class<?> parentClass) {
+ if (component != null && parentClass != null) {
+ UIComponent parent = component.getParent();
+ while (parent != null) {
+ if (parentClass.isInstance(parent)) {
+ return parent;
+ }
+ parent = parent.getParent();
+ }
+ }
+ return null;
+ }
+
/**
* Returns a parent <code>AbstractDropDownMenu</code> object of the given
component.
- * @param facesContext
* @param component
- * @return <code>UIComponent</code>
+ * @return <code>AbstractDropDownMenu</code>
*/
- protected UIComponent getDDMenu(FacesContext facesContext, UIComponent component) {
- UIComponent parent = component.getParent();
- while (parent != null) {
- if (parent instanceof AbstractDropDownMenu) {
- return parent;
- }
- parent = parent.getParent();
- }
- return null;
+ protected AbstractDropDownMenu getDDMenu(UIComponent component) {
+ return (AbstractDropDownMenu) getParent(component, AbstractDropDownMenu.class);
}
/**
* Returns a parent <code>AbstractMenuGroup</code> object of the given
component.
- * @param facesContext
* @param component
- * @return <code>UIComponent</code>
+ * @return <code>AbstractMenuGroup</code>
*/
- protected UIComponent getMenuGroup(FacesContext facesContext, UIComponent component)
{
- UIComponent parent = component.getParent();
- while (parent != null) {
- if (parent instanceof AbstractMenuGroup) {
- return parent;
- }
- parent = parent.getParent();
- }
- return null;
+ protected AbstractMenuGroup getMenuGroup(UIComponent component) {
+ return (AbstractMenuGroup) getParent(component, AbstractMenuGroup.class);
}
/**