You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2009/11/19 17:38:05 UTC
svn commit: r882196 [2/2] - in /myfaces/tobago/trunk:
core/src/main/java/org/apache/myfaces/tobago/component/
core/src/main/java/org/apache/myfaces/tobago/config/
core/src/main/java/org/apache/myfaces/tobago/layout/
core/src/main/java/org/apache/myface...
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/DatePickerRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/DatePickerRenderer.java?rev=882196&r1=882195&r2=882196&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/DatePickerRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/DatePickerRenderer.java Thu Nov 19 16:38:01 2009
@@ -186,19 +186,20 @@
public void prepareRender(FacesContext facesContext, UIComponent component) throws IOException {
+ UIDatePicker picker = (UIDatePicker) component;
// todo: use Measure instead of int
- component.getAttributes().put(
+ picker.getAttributes().put(
Attributes.LAYOUT_WIDTH,
- ThemeConfig.getMeasure(facesContext, component.getRendererType(), "pickerWidth").getPixel());
+ ThemeConfig.getMeasure(facesContext, picker, "pickerWidth").getPixel());
if (facesContext instanceof TobagoFacesContext) {
- UIPopup popup = (UIPopup) component.getFacets().get(Facets.PICKER_POPUP);
+ UIPopup popup = (UIPopup) picker.getFacets().get(Facets.PICKER_POPUP);
if (popup != null) {
- popup.setWidth(ThemeConfig.getMeasure(facesContext, component.getRendererType(), "CalendarPopupWidth"));
- popup.setHeight(ThemeConfig.getMeasure(facesContext, component.getRendererType(), "CalendarPopupHeight"));
+ popup.setWidth(ThemeConfig.getMeasure(facesContext, picker, "CalendarPopupWidth"));
+ popup.setHeight(ThemeConfig.getMeasure(facesContext, picker, "CalendarPopupHeight"));
((TobagoFacesContext) facesContext).getPopups().add(popup);
}
}
- super.prepareRender(facesContext, component);
+ super.prepareRender(facesContext, picker);
}
public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
@@ -264,7 +265,7 @@
if (converterPattern != null && (converterPattern.indexOf('h') > -1 || converterPattern.indexOf('H') > -1)) {
UITime time = (UITime) timePanel.findComponent("time");
Measure popupHeight = popup.getHeight();
- popupHeight = popupHeight.add(ThemeConfig.getMeasure(facesContext, time.getRendererType(), "preferredHeight"));
+ popupHeight = popupHeight.add(ThemeConfig.getMeasure(facesContext, time, "preferredHeight"));
popup.setHeight(popupHeight);
DateTimeConverter dateTimeConverter
= (DateTimeConverter) facesContext.getApplication().createConverter(CONVERTER_ID);
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/GridLayoutRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/GridLayoutRenderer.java?rev=882196&r1=882195&r2=882196&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/GridLayoutRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/GridLayoutRenderer.java Thu Nov 19 16:38:01 2009
@@ -21,6 +21,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.tobago.component.Attributes;
import org.apache.myfaces.tobago.component.UIGridLayout;
+import org.apache.myfaces.tobago.config.Configurable;
import org.apache.myfaces.tobago.config.ThemeConfig;
import org.apache.myfaces.tobago.layout.Measure;
import org.apache.myfaces.tobago.renderkit.RendererBase;
@@ -59,12 +60,12 @@
writer.endElement(HtmlConstants.DIV);
}
- public Measure getColumnSpacing(FacesContext facesContext, UIComponent component) {
- return ThemeConfig.getMeasure(facesContext, component.getRendererType(), Attributes.COLUMN_SPACING);
+ public Measure getColumnSpacing(FacesContext facesContext, Configurable component) {
+ return ThemeConfig.getMeasure(facesContext, component, Attributes.COLUMN_SPACING);
}
- public Measure getRowSpacing(FacesContext facesContext, UIComponent component) {
- return ThemeConfig.getMeasure(facesContext, component.getRendererType(), Attributes.ROW_SPACING);
+ public Measure getRowSpacing(FacesContext facesContext, Configurable component) {
+ return ThemeConfig.getMeasure(facesContext, component, Attributes.ROW_SPACING);
}
}
Copied: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuRenderer.java (from r882081, myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuRenderer.java?p2=myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuRenderer.java&p1=myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java&r1=882081&r2=882196&rev=882196&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuRenderer.java Thu Nov 19 16:38:01 2009
@@ -17,544 +17,7 @@
* limitations under the License.
*/
-/*
- * Created 28.04.2003 at 15:29:36.
- * $Id$
- */
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.tobago.component.AbstractUIPage;
-import org.apache.myfaces.tobago.component.Attributes;
-import org.apache.myfaces.tobago.component.CreateComponentUtils;
-import org.apache.myfaces.tobago.component.Facets;
-import org.apache.myfaces.tobago.component.UICommandBase;
-import org.apache.myfaces.tobago.component.UIMenu;
-import org.apache.myfaces.tobago.component.UIMenuCommand;
-import org.apache.myfaces.tobago.component.UIMenuSeparator;
-import org.apache.myfaces.tobago.component.UISelectBooleanCommand;
-import org.apache.myfaces.tobago.component.UISelectOneCommand;
-import org.apache.myfaces.tobago.config.TobagoConfig;
-import org.apache.myfaces.tobago.context.ResourceManagerUtil;
-import org.apache.myfaces.tobago.context.TobagoFacesContext;
-import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
import org.apache.myfaces.tobago.renderkit.LayoutComponentRendererBase;
-import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
-import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
-import org.apache.myfaces.tobago.renderkit.html.StyleClasses;
-import org.apache.myfaces.tobago.renderkit.html.util.CommandRendererHelper;
-import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
-import org.apache.myfaces.tobago.renderkit.util.RenderUtil;
-import org.apache.myfaces.tobago.util.AccessKeyMap;
-import org.apache.myfaces.tobago.util.ComponentUtils;
-import org.apache.myfaces.tobago.util.FastStringWriter;
-import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIForm;
-import javax.faces.component.UIPanel;
-import javax.faces.component.UISelectBoolean;
-import javax.faces.component.UISelectOne;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.model.SelectItem;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import static org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
-
-public class MenuBarRenderer extends LayoutComponentRendererBase {
-
- private static final Log LOG = LogFactory.getLog(MenuBarRenderer.class);
-
- public static final String SEARCH_ID_POSTFIX = SUBCOMPONENT_SEP + "popup";
- private static final String MENU_ACCELERATOR_KEYS = "menuAcceleratorKeys";
-
- public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
- String clientId;
-
- Map attributes = component.getAttributes();
- if (ComponentUtils.getBooleanAttribute(component, Attributes.MENU_POPUP)) {
- clientId = component.getParent().getClientId(facesContext);
- } else {
- clientId = component.getClientId(facesContext);
- TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
-
- writer.startElement(HtmlConstants.DIV, component);
- writer.writeIdAttribute(clientId);
- HtmlRendererUtils.renderDojoDndItem(component, writer, true);
- StyleClasses styleClasses = StyleClasses.ensureStyleClasses(component);
- if (ComponentUtils.getBooleanAttribute(component, Attributes.PAGE_MENU)) {
- styleClasses.addClass("menuBar", "page-facet"); // XXX not a standard compliant name
- } else {
- // todo
-// Style style = new Style(facesContext, component);
-// writer.writeStyleAttribute(style);
- }
- writer.writeClassAttribute(styleClasses);
-
-/*
-
- writer.startElement(HtmlConstants.SPAN);
- writer.writeAttribute(HtmlAttributes.STYLE, "position: relative", null);
-// writer.writeClassAttribute("tobago-menuBar-container");
-
- renderTopLevelItems(facesContext, writer, component);
-
- writer.endElement(HtmlConstants.SPAN);
-
-*/
- writer.endElement(HtmlConstants.DIV);
- }
- attributes.put(MENU_ACCELERATOR_KEYS, new ArrayList<String>());
-
- addScriptsAndStyles(facesContext, component, clientId);
- List<String> accKeyFunctions
- = (List<String>) attributes.remove(MENU_ACCELERATOR_KEYS);
- if (!accKeyFunctions.isEmpty()) {
- HtmlRendererUtils.writeScriptLoader(facesContext, null,
- accKeyFunctions.toArray(new String[accKeyFunctions.size()]));
- }
- }
-
- private void renderTopLevelItems(FacesContext facesContext,
- TobagoResponseWriter writer, UIComponent component) throws IOException {
- String bac = "green;";
- for (Object o : component.getChildren()) {
- if (o instanceof UIMenu) {
- writer.startElement(HtmlConstants.SPAN, null);
- writer.writeAttribute(HtmlAttributes.STYLE, "position: relative; background: " + bac + ";", false);
- writeMenuEntry(facesContext, writer, (UIMenu) o);
- writer.endElement(HtmlConstants.SPAN);
- bac = "lime";
- }
- }
- }
-
- public void prepareRender(FacesContext facesContext, UIComponent component) throws IOException {
- super.prepareRender(facesContext, component);
- if (facesContext instanceof TobagoFacesContext) {
- if (!ComponentUtils.getBooleanAttribute(component, Attributes.MENU_POPUP)) {
- HtmlRendererUtils.renderDojoDndSource(facesContext, component);
- }
-
- final String[] scripts = new String[]{"script/tobago-menu.js"};
-
- ((TobagoFacesContext) facesContext).getScriptFiles().add(scripts[0]);
- if (!TobagoConfig.getInstance(facesContext).isAjaxEnabled()) {
- final AbstractUIPage page = ComponentUtils.findPage(facesContext, component);
- String clientId = component.getClientId(facesContext);
- String setupFunction = createSetupFunction(clientId);
- String function = setupFunction + "('" + clientId + "', '"
- + page.getClientId(facesContext) + "');";
- String scriptBlock = createJavascriptFunction(facesContext, component, setupFunction);
- ((TobagoFacesContext) facesContext).getScriptBlocks().add(scriptBlock);
- ((TobagoFacesContext) facesContext).getOnloadScripts().add(function);
- }
- }
- }
-
- protected void addScriptsAndStyles(FacesContext facesContext,
- UIComponent component, final String clientId) throws IOException {
-
- if (TobagoConfig.getInstance(facesContext).isAjaxEnabled()) {
- final AbstractUIPage page = ComponentUtils.findPage(facesContext, component);
- String setupFunction = createSetupFunction(clientId);
- String function = setupFunction + "('" + clientId + "', '" + page.getClientId(facesContext) + "');";
- String scriptBlock = createJavascriptFunction(facesContext, component, setupFunction);
- StringTokenizer st = new StringTokenizer(scriptBlock, "\n");
- ArrayList<String> lines = new ArrayList<String>();
- while (st.hasMoreTokens()) {
- lines.add(st.nextToken());
- }
- lines.add(function);
- HtmlRendererUtils.writeScriptLoader(facesContext,
- new String[]{"script/tobago-menu.js"},
- lines.toArray(new String[lines.size()]));
- }
- }
-
- protected String createJavascriptFunction(FacesContext facesContext,
- UIComponent component, String setupFunction)
- throws IOException {
- StringBuilder sb = new StringBuilder(256);
-
- sb.append("function ");
- sb.append(setupFunction);
- sb.append("(id, pageId) {\n");
- sb.append(" var menuStart = new Date();\n");
- sb.append(" var searchId = id + '" + SEARCH_ID_POSTFIX + "';\n");
- sb.append(" var menubar = document.getElementById(searchId);\n");
- sb.append(" if (! menubar) {\n");
- sb.append(" searchId = id;\n");
- sb.append(" menubar = document.getElementById(searchId);\n");
- sb.append(" }\n");
- sb.append(" if (menubar) {\n");
- sb.append(" var menu = createMenuRoot(searchId);\n");
- sb.append(" menubar.menu = menu;\n");
-
- sb.append(" menu.setSubitemArrowImage(\"");
- sb.append(
- ResourceManagerUtil.getImageWithPath(facesContext, "image/MenuArrow.gif"));
- sb.append("\");\n");
-
- if (ComponentUtils.getBooleanAttribute(component, Attributes.MENU_POPUP)) {
- addMenu(sb, "menu", facesContext, (UIPanel) component, 0);
- sb.append(" initMenuPopUp(searchId, pageId, \"");
- sb.append(component.getAttributes().get(Attributes.MENU_POPUP_TYPE));
- sb.append("\");\n");
- } else {
- addMenuEntrys(sb, "menu", facesContext, component, true);
- sb.append(" initMenuBar(searchId, pageId);\n");
- }
-
- sb.append(" }\n");
- sb.append(" else {\n");
- sb.append(
- " LOG.debug('kein Element mit id: ' + searchId + ' gefunden!');\n");
- sb.append(" }\n");
- sb.append(" LOG.debug('Menu Total Time : ' + (new Date().getTime() - menuStart.getTime()));\n");
- sb.append("}\n");
- return sb.toString();
- }
-
- private String createSetupFunction(String clientId) {
- return "setupMenu" + clientId.replaceAll(":", "_").replaceAll("\\.", "_").replaceAll("-", "_");
- }
-
- private int addMenu(StringBuilder sb, String var, FacesContext facesContext,
- UIPanel menu, int i) throws IOException {
- if (!menu.isRendered()) {
- return i;
- }
-
- String name = var + "_" + i++;
- sb.append(" var ").append(name).append(" = ").append(createMenuEntry(facesContext, menu)).append(";\n");
- sb.append(" ").append(var).append(".addMenuItem(").append(name).append(");\n");
- addMenuEntrys(sb, name, facesContext, menu, false);
- return i;
- }
-
- private String createMenuEntry(FacesContext facesContext, UIPanel uiPanel)
- throws IOException {
- ResponseWriter savedWriter = facesContext.getResponseWriter();
- FastStringWriter stringWriter = new FastStringWriter();
- ResponseWriter newWriter = savedWriter.cloneWithWriter(stringWriter);
- facesContext.setResponseWriter(newWriter);
- TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
-
- writeMenuEntry(facesContext, writer, uiPanel);
-
- facesContext.setResponseWriter(savedWriter);
-
-
- return "new Tobago.Menu.Item('" + prepareForScript(stringWriter.toString()) + "', null)";
- }
-
- private void writeMenuEntry(FacesContext facesContext, TobagoResponseWriter writer, UIPanel uiPanel)
- throws IOException {
- final boolean disabled
- = ComponentUtils.getBooleanAttribute(uiPanel, Attributes.DISABLED);
- final boolean topMenu = (uiPanel.getParent().getRendererType() != null)
- || ComponentUtils.getBooleanAttribute(uiPanel, Attributes.MENU_POPUP);
- final boolean pageMenu = (uiPanel.getParent().getRendererType() != null)
- &&
- ComponentUtils.getBooleanAttribute(uiPanel.getParent(), Attributes.PAGE_MENU);
- String spanClass
- = "tobago-menuBar-item-span tobago-menuBar-item-span-"
- + (disabled ? "disabled" : "enabled")
- + (topMenu ? " tobago-menuBar-item-span-top" : "")
- + (pageMenu ? " tobago-menuBar-item-page-top" : "");
-
- final LabelWithAccessKey label = new LabelWithAccessKey(uiPanel);
- String image = (String) uiPanel.getAttributes().get(Attributes.IMAGE);
-
-
- addImage(writer, facesContext, image, disabled);
-
- writer.startElement(HtmlConstants.A, null);
- writer.writeClassAttribute(spanClass);
- writer.writeAttribute(HtmlAttributes.HREF, "#", false);
- writer.writeAttribute(HtmlAttributes.ONFOCUS, "tobagoMenuFocus(event)", false);
- writer.writeAttribute(HtmlAttributes.ONBLUR, "tobagoMenuBlur(event)", false);
- writer.writeAttribute(HtmlAttributes.ONKEYDOWN, "tobagoMenuKeyDown(event)", false);
- writer.writeAttribute(HtmlAttributes.ONKEYPRESS, "tobagoMenuKeyPress(event)", false);
- writer.writeIdAttribute(uiPanel.getClientId(facesContext));
- if (label.getText() != null) {
- if (label.getAccessKey() != null) {
- if (LOG.isInfoEnabled()
- && !AccessKeyMap.addAccessKey(facesContext, label.getAccessKey())) {
- LOG.info("dublicated accessKey : " + label.getAccessKey());
- }
- if (!disabled) {
- addAcceleratorKey(facesContext, uiPanel, label.getAccessKey());
- }
- }
- HtmlRendererUtils.writeLabelWithAccessKey(writer, label);
- }
- writer.endElement(HtmlConstants.A);
- }
-
- private void addAcceleratorKey(
- FacesContext facesContext, UIComponent component, Character accessKey) {
- String clientId = component.getClientId(facesContext);
- while (component != null && !component.getAttributes().containsKey(MENU_ACCELERATOR_KEYS)) {
- component = component.getParent();
- }
- if (component != null) {
- List<String> keys
- = (List<String>) component.getAttributes().get(MENU_ACCELERATOR_KEYS);
- String jsStatement = HtmlRendererUtils.createOnclickAcceleratorKeyJsStatement(
- clientId, accessKey, null);
- keys.add(jsStatement);
- } else {
- LOG.warn("Can't find menu root component!");
- }
- }
-
- private void addImage(TobagoResponseWriter writer, FacesContext facesContext,
- String image, boolean disabled) throws IOException {
- if (image != null) {
- String disabledImage = null;
- if (disabled) {
- disabledImage = ResourceManagerUtil.getDisabledImageWithPath(facesContext, image);
- }
- if (disabledImage != null) {
- image = disabledImage;
- } else {
- image = ResourceManagerUtil.getImageWithPath(facesContext, image);
- }
- } else {
- image = ResourceManagerUtil.getImageWithPath(facesContext, "image/blank.gif");
- }
- writer.startElement(HtmlConstants.IMG, null);
- writer.writeClassAttribute("tobago-menu-item-image");
- writer.writeAttribute(HtmlAttributes.SRC, image, false);
- writer.endElement(HtmlConstants.IMG);
- }
-
- private int addMenuEntrys(StringBuilder sb, String var,
- FacesContext facesContext, UIComponent component, boolean warn) throws IOException {
- return addMenuEntrys(sb, var, facesContext, component, warn, 0);
- }
-
- private int addMenuEntrys(
- StringBuilder sb, String var, FacesContext facesContext, UIComponent component, boolean warn, int index)
- throws IOException {
- for (Object o : component.getChildren()) {
- UIComponent entry = (UIComponent) o;
- if (entry instanceof UICommandBase) {
- addMenuEntry(sb, var, facesContext, (UICommandBase) entry);
- } else if (entry instanceof UIMenuSeparator) {
- addMenuSeparator(sb, var);
- } else if (entry instanceof UIMenu) {
- index = addMenu(sb, var, facesContext, (UIPanel) entry, index);
- } else if (entry instanceof UIForm) {
- index = addMenuEntrys(sb, var, facesContext, entry, warn, index);
- } else if (warn) {
- LOG.error("Illegal UIComponent class in menuBar (not UICommandBase): " + entry.getClass().getName());
- }
- }
- return index;
- }
-
- private void addMenuEntry(StringBuilder sb, String var, FacesContext facesContext, UICommandBase command)
- throws IOException {
- CommandRendererHelper helper = new CommandRendererHelper(facesContext, command);
- String onclick = helper.getOnclick();
- if (command instanceof UIMenuCommand) {
- if (command.getFacet(Facets.ITEMS) != null) {
- UIComponent facet = command.getFacet(Facets.ITEMS);
- if (facet instanceof UISelectOne) {
- addSelectOne(sb, var, facesContext, command, onclick);
- } else if (facet instanceof UISelectBoolean) {
- addSelectBoolean(sb, var, facesContext, command, onclick);
- }
- } else {
- addCommand(sb, var, facesContext, command, onclick);
- }
- } else if (command instanceof UISelectBooleanCommand) {
- addSelectBoolean(sb, var, facesContext, command, onclick);
- } else if (command instanceof UISelectOneCommand) {
- addSelectOne(sb, var, facesContext, command, onclick);
- }
- }
-
- private void addCommand(
- StringBuilder sb, String var, FacesContext facesContext, UICommandBase command, String onClick)
- throws IOException {
- String image = (String) command.getAttributes().get(Attributes.IMAGE);
- addMenuItem(sb, var, facesContext, command, image, onClick);
- }
-
- private void addSelectBoolean(
- StringBuilder sb, String var, FacesContext facesContext, UICommandBase command, String onClick)
- throws IOException {
-
- UIComponent checkbox = command.getFacet(Facets.ITEMS);
- if (checkbox == null) {
- checkbox = CreateComponentUtils.createUISelectBooleanFacetWithId(facesContext, command);
- }
-
- final boolean checked = ComponentUtils.getBooleanAttribute(checkbox, Attributes.VALUE);
-
- String clientId = checkbox.getClientId(facesContext);
- onClick = RenderUtil.addMenuCheckToggle(clientId, onClick);
- if (checked) {
- sb.append(" menuCheckToggle('").append(clientId).append("');\n");
- }
- String image = checked ? "image/MenuCheckmark.gif" : null;
- addMenuItem(sb, var, facesContext, command, image, onClick);
- }
-
- private void addMenuItem(
- StringBuilder sb, String var, FacesContext facesContext, UICommandBase command, String image, String onclick)
- throws IOException {
- LabelWithAccessKey label = new LabelWithAccessKey(command);
- addMenuItem(sb, var, facesContext, command, label, image, onclick);
- }
-
- private void addSelectOne(
- StringBuilder sb, String var, FacesContext facesContext, UICommandBase command, String onclick)
- throws IOException {
- List<SelectItem> items;
- LabelWithAccessKey label = new LabelWithAccessKey(command);
-
- UISelectOne radio = (UISelectOne) command.getFacet(Facets.ITEMS);
- if (radio == null) {
- items = RenderUtil.getSelectItems(command);
- radio = CreateComponentUtils.createUIMenuSelectOneFacet(facesContext, command);
- radio.setId(facesContext.getViewRoot().createUniqueId());
- } else {
- items = RenderUtil.getSelectItems(radio);
- }
-
- Object value = radio.getValue();
-
- boolean markFirst = !ComponentUtils.hasSelectedValue(items, value);
- String radioId = radio.getClientId(facesContext);
- String onClickPrefix = "menuSetRadioValue('" + radioId + "', '";
- String onClickPostfix = onclick != null ? "') ; " + onclick : "";
- for (SelectItem item : items) {
- final String labelText = item.getLabel();
- label.reset();
- if (labelText != null) {
- if (labelText.indexOf(LabelWithAccessKey.INDICATOR) > -1) {
- label.setup(labelText);
- } else {
- label.setText(labelText);
- }
- } else {
- LOG.warn("Menu item has label=null. UICommandBase.getClientId()="
- + command.getClientId(facesContext));
- }
- String formattedValue
- = RenderUtil.getFormattedValue(facesContext, radio, item.getValue());
- onclick = onClickPrefix + formattedValue + onClickPostfix;
- String image;
- if (item.getValue().equals(value) || markFirst) {
- image = "image/MenuRadioChecked.gif";
- markFirst = false;
- sb.append(" ").append(onClickPrefix).append(formattedValue).append("');");
- } else {
- image = "image/MenuRadioUnchecked.gif";
- }
- addMenuItem(sb, var, facesContext, command, label, image, onclick);
- }
- }
-
- private void addMenuItem(
- StringBuilder sb, String var, FacesContext facesContext, UICommandBase command,
- LabelWithAccessKey label, String image, String onClick)
- throws IOException {
- if (!command.isRendered()) {
- return;
- }
- final boolean disabled
- = ComponentUtils.getBooleanAttribute(command, Attributes.DISABLED);
- String spanClass
- = "tobago-menuBar-item-span tobago-menuBar-item-span-"
- + (disabled ? "disabled" : "enabled");
-
- ResponseWriter savedWriter = facesContext.getResponseWriter();
- FastStringWriter stringWriter = new FastStringWriter();
- ResponseWriter newWriter = savedWriter.cloneWithWriter(stringWriter);
- facesContext.setResponseWriter(newWriter);
- TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
- addImage(writer, facesContext, image, disabled);
-
- writer.startElement(HtmlConstants.A, null);
- writer.writeClassAttribute(spanClass);
- if (label.getAccessKey() != null) {
- if (LOG.isInfoEnabled()
- && !AccessKeyMap.addAccessKey(facesContext, label.getAccessKey())) {
- LOG.info("duplicate accessKey : " + label.getAccessKey() + " in " + label.getText());
- }
-
- if (!disabled) {
- writer.writeIdAttribute(command.getClientId(facesContext));
- addAcceleratorKey(facesContext, command, label.getAccessKey());
- }
- }
- writer.writeAttribute(HtmlAttributes.HREF, "#", false);
- writer.writeAttribute(HtmlAttributes.ONFOCUS, "tobagoMenuFocus(event)", false);
- writer.writeAttribute(HtmlAttributes.ONBLUR, "tobagoMenuBlur(event)", false);
- writer.writeAttribute(HtmlAttributes.ONKEYDOWN, "tobagoMenuKeyDown(event)", false);
- writer.writeAttribute(HtmlAttributes.ONKEYPRESS, "tobagoMenuKeyPress(event)", false);
- if (label.getText() != null) {
- HtmlRendererUtils.writeLabelWithAccessKey(writer, label);
- }
- writer.endElement(HtmlConstants.A);
-
- facesContext.setResponseWriter(savedWriter);
- final String html = stringWriter.toString();
-
- sb.append(" ");
- sb.append(var);
- sb.append(".addMenuItem(new Tobago.Menu.Item('");
- sb.append(prepareForScript(html));
- sb.append("', ");
- if (!disabled) {
- sb.append("\"");
- sb.append(onClick);
- sb.append("\"");
- } else {
- sb.append("null");
- }
- sb.append(", ");
- sb.append(disabled ? "true" : "false");
- sb.append("));\n");
- }
-
- private void addMenuSeparator(StringBuilder sb, String var) {
- String html = "<div style=\"text-align: center;\">"
- + "<hr class=\"tobago-menuBar-separator\"></div>";
-
- sb.append(" ");
- sb.append(var);
- sb.append(".addMenuItem(new Tobago.Menu.Item('");
- sb.append(prepareForScript(html));
- sb.append("', ");
- sb.append("null");
- sb.append(", ");
- sb.append("true");
- sb.append(", ");
- sb.append("true");
- sb.append("));\n");
- }
-
- private String prepareForScript(String s) {
- return s.replaceAll("\n", " ").replaceAll("'", "\\\\'");
- }
-
- public void encodeChildren(FacesContext facesContext, UIComponent component)
- throws IOException {
- }
- public boolean getRendersChildren() {
- return true;
- }
+public class MenuRenderer extends LayoutComponentRendererBase {
}
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectManyCheckboxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectManyCheckboxRenderer.java?rev=882196&r1=882195&r2=882196&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectManyCheckboxRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectManyCheckboxRenderer.java Thu Nov 19 16:38:01 2009
@@ -20,6 +20,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.tobago.component.UISelectManyCheckbox;
+import org.apache.myfaces.tobago.config.Configurable;
import org.apache.myfaces.tobago.layout.Measure;
import org.apache.myfaces.tobago.renderkit.SelectManyRendererBase;
import org.apache.myfaces.tobago.renderkit.css.Style;
@@ -111,7 +112,7 @@
}
@Override
- public Measure getHeight(FacesContext facesContext, UIComponent component) {
+ public Measure getHeight(FacesContext facesContext, Configurable component) {
UISelectManyCheckbox select = (UISelectManyCheckbox) component;
Measure heightOfOne = super.getHeight(facesContext, component);
if (select.isInline()) {
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectOneRadioRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectOneRadioRenderer.java?rev=882196&r1=882195&r2=882196&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectOneRadioRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectOneRadioRenderer.java Thu Nov 19 16:38:01 2009
@@ -20,6 +20,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.tobago.component.UISelectOneRadio;
+import org.apache.myfaces.tobago.config.Configurable;
import org.apache.myfaces.tobago.context.TobagoFacesContext;
import org.apache.myfaces.tobago.layout.Measure;
import org.apache.myfaces.tobago.renderkit.SelectOneRendererBase;
@@ -123,7 +124,7 @@
}
@Override
- public Measure getHeight(FacesContext facesContext, UIComponent component) {
+ public Measure getHeight(FacesContext facesContext, Configurable component) {
UISelectOneRadio select = (UISelectOneRadio) component;
Measure heightOfOne = super.getHeight(facesContext, component);
if (select.isInline()) {
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java?rev=882196&r1=882195&r2=882196&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java Thu Nov 19 16:38:01 2009
@@ -102,8 +102,8 @@
public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException {
- storeFooterHeight(facesContext, uiComponent);
UIData data = (UIData) uiComponent;
+ storeFooterHeight(facesContext, data);
Style style = new Style(facesContext, data);
@@ -655,26 +655,26 @@
}
}
- private Measure getRowPadding(FacesContext facesContext, UIComponent component) {
- return ThemeConfig.getMeasure(facesContext, component.getRendererType(), "rowPadding");
+ private Measure getRowPadding(FacesContext facesContext, UIData data) {
+ return ThemeConfig.getMeasure(facesContext, data, "rowPadding");
}
- private Measure getScrollbarWidth(FacesContext facesContext, UIComponent component) {
- return ThemeConfig.getMeasure(facesContext, component.getRendererType(), "scrollbarWidth");
+ private Measure getScrollbarWidth(FacesContext facesContext, UIData data) {
+ return ThemeConfig.getMeasure(facesContext, data, "scrollbarWidth");
}
- private void storeFooterHeight(FacesContext facesContext, UIComponent component) {
- component.getAttributes().put(Attributes.FOOTER_HEIGHT, getFooterHeight(facesContext, component));
+ private void storeFooterHeight(FacesContext facesContext, UIData data) {
+ data.getAttributes().put(Attributes.FOOTER_HEIGHT, getFooterHeight(facesContext, data));
}
- private Measure getFooterHeight(FacesContext facesContext, UIComponent component) {
+ private Measure getFooterHeight(FacesContext facesContext, UIData data) {
// todo: use Measure instead of int
Measure footerHeight;
- if (isValidPagingAttribute((UIData) component, Attributes.SHOW_ROW_RANGE)
- || isValidPagingAttribute((UIData) component, Attributes.SHOW_PAGE_RANGE)
- || isValidPagingAttribute((UIData) component, Attributes.SHOW_DIRECT_LINKS)) {
+ if (isValidPagingAttribute(data, Attributes.SHOW_ROW_RANGE)
+ || isValidPagingAttribute(data, Attributes.SHOW_PAGE_RANGE)
+ || isValidPagingAttribute(data, Attributes.SHOW_DIRECT_LINKS)) {
footerHeight =
- ThemeConfig.getMeasure(facesContext, component.getRendererType(), "footerHeight");
+ ThemeConfig.getMeasure(facesContext, data, "footerHeight");
} else {
footerHeight = PixelMeasure.ZERO;
}
@@ -703,8 +703,8 @@
|| "right".equals(value);
}
- private Measure getAscendingMarkerWidth(FacesContext facesContext, UIComponent component) {
- return ThemeConfig.getMeasure(facesContext, component.getRendererType(), "ascendingMarkerWidth");
+ private Measure getAscendingMarkerWidth(FacesContext facesContext, UIData data) {
+ return ThemeConfig.getMeasure(facesContext, data, "ascendingMarkerWidth");
}
public boolean getRendersChildren() {
@@ -1077,7 +1077,7 @@
}
private Measure getContentBorder(FacesContext facesContext, UIData data) {
- return ThemeConfig.getMeasure(facesContext, data.getRendererType(), "contentBorder");
+ return ThemeConfig.getMeasure(facesContext, data, "contentBorder");
}
public void encodeAjax(FacesContext facesContext, UIComponent component) throws IOException {
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java?rev=882196&r1=882195&r2=882196&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java Thu Nov 19 16:38:01 2009
@@ -138,7 +138,7 @@
int virtualTab = 0;
Measure currentWidth = PixelMeasure.ZERO;
- Measure navigationBarWidth = ThemeConfig.getMeasure(facesContext, tabGroup.getRendererType(), "navigationBarWidth");
+ Measure navigationBarWidth = ThemeConfig.getMeasure(facesContext, tabGroup, "navigationBarWidth");
for (UIComponent tab : (List<UIComponent>) tabGroup.getChildren()) {
if (tab instanceof UIPanelBase) {
if (tab.isRendered()) {
@@ -194,7 +194,7 @@
int index = 0;
// todo: use Measure instead of int
int tabLabelExtraWidth
- = ThemeConfig.getMeasure(facesContext, component.getRendererType(), "tabLabelExtraWidth").getPixel();
+ = ThemeConfig.getMeasure(facesContext, component, "tabLabelExtraWidth").getPixel();
boolean first = true;
for (UIComponent child : (List<UIComponent>) component.getChildren()) {
@@ -277,7 +277,7 @@
writer.startElement(HtmlConstants.TD, tabGroup);
Measure width = tabGroup.getWidth();
- Measure headerHeight = ThemeConfig.getMeasure(facesContext, tabGroup.getRendererType(), "headerHeight");
+ Measure headerHeight = ThemeConfig.getMeasure(facesContext, tabGroup, "headerHeight");
Style header = new Style();
header.setPosition(Position.RELATIVE);
header.setWidth(width);
@@ -534,14 +534,15 @@
}
public void encodeAjax(FacesContext context, UIComponent component) throws IOException {
- AjaxUtils.checkParamValidity(context, component, UITabGroup.class);
- TabList tabList = getTabList(context, (UITabGroup) component);
- int index = ensureRenderedActiveIndex(context, (UITabGroup) component);
+ UITabGroup tabGroup = (UITabGroup) component;
+ AjaxUtils.checkParamValidity(context, tabGroup, UITabGroup.class);
+ TabList tabList = getTabList(context, tabGroup);
+ int index = ensureRenderedActiveIndex(context, tabGroup);
Measure currentWidth = new PixelMeasure(getCurrentWidth(tabList, index));
renderTabGroupView(context, HtmlRendererUtils.getTobagoResponseWriter(context),
- (UITabGroup) component, index, SWITCH_TYPE_RELOAD_TAB,
+ tabGroup, index, SWITCH_TYPE_RELOAD_TAB,
ResourceManagerUtil.getImageWithPath(context, "image/1x1.gif"),
- ThemeConfig.getMeasure(context, component.getRendererType(), "navigationBarWidth"), currentWidth, tabList);
+ ThemeConfig.getMeasure(context, tabGroup, "navigationBarWidth"), currentWidth, tabList);
}
private static class TabList {
Modified: myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/BoxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/BoxRenderer.java?rev=882196&r1=882195&r2=882196&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/BoxRenderer.java (original)
+++ myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/BoxRenderer.java Thu Nov 19 16:38:01 2009
@@ -102,7 +102,7 @@
private void encodeBox(FacesContext facesContext, TobagoResponseWriter writer, UIBox box) throws IOException {
// todo: shadow = 0px means, that shadow is disabled, but it may be better, if we can set a boolean in the config.
- Measure measure = ThemeConfig.getMeasure(facesContext, box.getRendererType(), "shadow");
+ Measure measure = ThemeConfig.getMeasure(facesContext, box, "shadow");
boolean hasShadow = measure.greaterThan(PixelMeasure.ZERO);
if (hasShadow) {
Modified: myfaces/tobago/trunk/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtil.java?rev=882196&r1=882195&r2=882196&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtil.java (original)
+++ myfaces/tobago/trunk/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtil.java Thu Nov 19 16:38:01 2009
@@ -20,6 +20,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.tobago.component.Attributes;
+import org.apache.myfaces.tobago.config.Configurable;
import org.apache.myfaces.tobago.config.ThemeConfig;
import org.apache.myfaces.tobago.context.ResourceManagerUtil;
import org.apache.myfaces.tobago.layout.Measure;
@@ -183,20 +184,20 @@
}
public static Measure calculateStringWidth(FacesContext facesContext, UIComponent component, String text) {
- return calculateStringWidth(facesContext, component, text, "tobago.font.widths");
+ return calculateStringWidth(facesContext, (Configurable) component, text, "tobago.font.widths");
}
public static Measure calculateStringWidth2(FacesContext facesContext, UIComponent component, String text) {
- return calculateStringWidth(facesContext, component, text, "tobago.font2.widths");
+ return calculateStringWidth(facesContext, (Configurable) component, text, "tobago.font2.widths");
}
private static Measure calculateStringWidth(
- FacesContext facesContext, UIComponent component, String text, String type) {
+ FacesContext facesContext, Configurable component, String text, String type) {
int width = 0;
int defaultCharWidth = 0;
try {
// todo: use Measure instead of int
- defaultCharWidth = ThemeConfig.getMeasure(facesContext, component.getRendererType(), "fontWidth").getPixel();
+ defaultCharWidth = ThemeConfig.getMeasure(facesContext, component, "fontWidth").getPixel();
} catch (NullPointerException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("no value for \"fontWidth\" found in theme-config");