Author: abelevich
Date: 2008-03-25 12:31:53 -0400 (Tue, 25 Mar 2008)
New Revision: 7208
Modified:
trunk/ui/pickList/src/main/java/org/richfaces/renderkit/PickListRenderer.java
Log:
http://jira.jboss.com/jira/browse/RF-2606
Modified: trunk/ui/pickList/src/main/java/org/richfaces/renderkit/PickListRenderer.java
===================================================================
---
trunk/ui/pickList/src/main/java/org/richfaces/renderkit/PickListRenderer.java 2008-03-25
16:30:59 UTC (rev 7207)
+++
trunk/ui/pickList/src/main/java/org/richfaces/renderkit/PickListRenderer.java 2008-03-25
16:31:53 UTC (rev 7208)
@@ -38,9 +38,9 @@
public class PickListRenderer extends HeaderResourcesRendererBase {
private static final String HIDDEN_SUFFIX = "valueKeeper";
- protected static final OrderingComponentRendererBase.ControlsHelper[] SHUTTLE_HELPERS
= ListShuttleControlsHelper.HELPERS;
+ protected static final OrderingComponentRendererBase.ControlsHelper[] SHUTTLE_HELPERS
= PickListControlsHelper.HELPERS;
protected final static String SHOW_LABELS_ATTRIBUTE_NAME =
"showButtonsLabel";
- private static final String MESSAGE_BUNDLE_NAME =
OrderingListRendererBase.class.getPackage().getName() + "ListShuttle";
+ private static final String MESSAGE_BUNDLE_NAME =
PickListRenderer.class.getPackage().getName() + ".pickList";
private boolean isSelectedList;
private boolean isAvailableList;
@@ -71,11 +71,8 @@
return SelectUtils.getSelectItems(context, component);
}
- private final String bundleName;
-
public PickListRenderer() {
super();
- this.bundleName = MESSAGE_BUNDLE_NAME;
}
public void decode(FacesContext context, UIComponent component) {
@@ -302,21 +299,21 @@
public void encodePickListControlsFacets(FacesContext context, UIComponent component)
throws IOException {
String clientId = component.getClientId(context);
ResponseWriter writer = context.getResponseWriter();
- int divider = SHUTTLE_HELPERS.length / 2;
boolean enable = false;
+
for (int i = 0; i < SHUTTLE_HELPERS.length; i++) {
OrderingComponentRendererBase.ControlsHelper helper = SHUTTLE_HELPERS[i];
boolean isDisabled =
helper.getButtonStyleClass().equals(ListShuttleControlsHelper.DISABLED_STYLE_PREF);
if
(helper.getBundlePropertyName().equals(ListShuttleControlsHelper.BUNDLE_REMOVE_ALL_LABEL))
{
enable = isSelectedList;
- if ((!enable && isDisabled) || (enable && !isDisabled)) {
+ if(enable != isDisabled) {
enable = true;
} else {
enable = false;
}
} else if
(helper.getBundlePropertyName().equals(ListShuttleControlsHelper.BUNDLE_COPY_ALL_LABEL))
{
enable = isAvailableList;
- if ((!enable && isDisabled) || (enable && !isDisabled)) {
+ if(enable != isDisabled) {
enable = true;
} else {
enable = false;
@@ -334,35 +331,61 @@
protected void encodeControlFacet(FacesContext context, UIComponent component,
OrderingComponentRendererBase.ControlsHelper helper, String clientId,
ResponseWriter writer, boolean enabled, String baseStyle, String baseControlStyle)
throws IOException {
+ renderDefaultControl(context, component, writer, helper, clientId, enabled, baseStyle,
baseControlStyle);
+ }
+
+ protected ClassLoader getCurrentLoader(Object fallbackClass) {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if (loader == null) {
+ loader = fallbackClass.getClass().getClassLoader();
+ }
+ return loader;
+ }
+
+ protected String findLocalisedLabel(FacesContext context, String propertyId, String
bundleName) {
+ String label = null;
Locale locale = null;
+ String userBundleName = null;
+ ResourceBundle bundle = null;
UIViewRoot viewRoot = context.getViewRoot();
- if (viewRoot != null) {
- locale = viewRoot.getLocale();
+ if ( viewRoot != null) {
+ locale = viewRoot.getLocale();
+ } else {
+ locale = Locale.getDefault();
}
-
- ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- ResourceBundle bundle = null;
-
- if (locale != null) {
+
+ try {
+ if( null != (userBundleName = context.getApplication().getMessageBundle())) {
+ bundle = ResourceBundle.getBundle(userBundleName,locale,
getCurrentLoader(userBundleName));
+ if (bundle != null) {
+ label = bundle.getString(propertyId);
+ }
+ }
+ } catch (MissingResourceException e) {
+ }
+
+ if(label == null && bundleName != null) {
try {
- bundle = ResourceBundle.getBundle(bundleName, locale, contextClassLoader);
+ bundle = ResourceBundle.getBundle(bundleName ,locale, getCurrentLoader(bundleName));
+ if (bundle != null) {
+ label = bundle.getString(propertyId);
+ }
} catch (MissingResourceException e) {
}
}
-
- Map attributes = component.getAttributes();
+
+ return label;
+ }
+
+ protected void renderDefaultControl(FacesContext context, UIComponent component,
ResponseWriter writer,
+ OrderingComponentRendererBase.ControlsHelper helper, String clientId, boolean enabled,
String baseStyle,
+ String baseControlStyle) throws IOException {
UIComponent facet = component.getFacet(helper.getFacetName());
boolean useFacet = (facet != null && facet.isRendered());
- renderDefaultControl(context, component, writer, useFacet, helper, clientId, bundle,
enabled, baseStyle, baseControlStyle);
- }
- protected void renderDefaultControl(FacesContext context, UIComponent orderingList,
ResponseWriter writer, boolean useFacet,
- OrderingComponentRendererBase.ControlsHelper helper, String clientId, ResourceBundle
bundle, boolean enabled, String baseStyle,
- String baseControlStyle) throws IOException {
- UIComponent facet = orderingList.getFacet(helper.getFacetName());
String customEvent = null;
- Map attributes = orderingList.getAttributes();
+ Map attributes = component.getAttributes();
if (helper.customEvent != null) {
customEvent = (String) attributes.get(helper.customEvent);
@@ -377,7 +400,7 @@
currentStyle = styleFromAttribute.concat(currentStyle);
}
- writer.startElement(HTML.DIV_ELEM, orderingList);
+ writer.startElement(HTML.DIV_ELEM, component);
String controlId = clientId + helper.getIdSuffix();
writer.writeAttribute(HTML.id_ATTRIBUTE, controlId, null); // FIXME:
writer.writeAttribute(HTML.class_ATTRIBUTE, currentStyle, null);
@@ -392,7 +415,7 @@
writer.writeAttribute(HTML.style_ATTRIBUTE, style, null);
if (!useFacet) {
- writer.startElement(HTML.DIV_ELEM, orderingList);
+ writer.startElement(HTML.DIV_ELEM, component);
writer.writeAttribute(HTML.class_ATTRIBUTE, baseStyle +
helper.getButtonStyleClass(), null);
if (helper.enable) {
@@ -402,7 +425,7 @@
writer.writeAttribute(HTML.onmouseout_ATTRIBUTE, "this.className='" +
baseStyle + "'", null);
}
- writer.startElement(HTML.a_ELEMENT, orderingList);
+ writer.startElement(HTML.a_ELEMENT, component);
writer.writeAttribute(HTML.id_ATTRIBUTE, controlId + "link", null); //
FIXME:
writer.writeAttribute(HTML.HREF_ATTR, "#", null);
writer.writeAttribute(HTML.onclick_ATTRIBUTE, "return false;", null);
@@ -410,14 +433,14 @@
if (!helper.enable) {
writer.writeAttribute(HTML.DISABLED_ATTR, "disabled", null);
writer.writeAttribute(HTML.class_ATTRIBUTE, baseStyle + "-a-disabled",
null);
- writer.startElement(HTML.a_ELEMENT, orderingList);
+ writer.startElement(HTML.a_ELEMENT, component);
} else {
writer.writeAttribute(HTML.class_ATTRIBUTE, baseStyle + "-selection", null);
writer.writeAttribute(HTML.onblur_ATTRIBUTE, "Control.onblur(this);", null);
writer.writeAttribute(HTML.onfocus_ATTRIBUTE, "Control.onfocus(this);",
null);
}
- writer.startElement(HTML.DIV_ELEM, orderingList);
+ writer.startElement(HTML.DIV_ELEM, component);
writer.writeAttribute(HTML.class_ATTRIBUTE, baseStyle + "-content",
null);
}
@@ -428,30 +451,23 @@
if (useFacet) {
renderChild(context, facet);
} else {
- writer.startElement(HTML.IMG_ELEMENT, orderingList);
+ writer.startElement(HTML.IMG_ELEMENT, component);
writer.writeAttribute(HTML.width_ATTRIBUTE, "15", null);
writer.writeAttribute(HTML.height_ATTRIBUTE, "15", null);
writer.writeAttribute(HTML.border_ATTRIBUTE, "0", null);
writer.writeAttribute(HTML.alt_ATTRIBUTE, helper.getFacetName(), null);
writer.writeAttribute(HTML.src_ATTRIBUTE,
getResource(helper.getImageURI()).getUri(context, null), null);
writer.endElement(HTML.IMG_ELEMENT);
- // TODO check properties!!!
- // writer.write(helper.getDefaultText());
- if (getUtils().isBooleanAttribute(orderingList, SHOW_LABELS_ATTRIBUTE_NAME)) {
-
+ if (getUtils().isBooleanAttribute(component, SHOW_LABELS_ATTRIBUTE_NAME)) {
String label = (String) attributes.get(helper.getLabelAttributeName());
- if (label == null && bundle != null) {
- try {
- label = bundle.getString(helper.getBundlePropertyName());
- } catch (MissingResourceException e) {
- }
+ if (label == null || label.equals("")) {
+ label = findLocalisedLabel(context, helper.getBundlePropertyName(),
MESSAGE_BUNDLE_NAME);
}
if (label == null || label.equals("")) {
label = helper.getDefaultText();
}
-
writer.write(label);
}
}