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 2011/06/30 00:04:39 UTC
svn commit: r1141267 - in /myfaces/tobago/trunk/tobago-theme:
tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/
tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/st...
Author: lofwyr
Date: Wed Jun 29 22:04:39 2011
New Revision: 1141267
URL: http://svn.apache.org/viewvc?rev=1141267&view=rev
Log:
TOBAGO-1008: Impossible to select a row in tc:sheet by keyboard
- patch applied
- minor cleanup
Modified:
myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
Modified: myfaces/tobago/trunk/tobago-theme/tobago-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/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java?rev=1141267&r1=1141266&r2=1141267&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java Wed Jun 29 22:04:39 2011
@@ -132,12 +132,6 @@ public class SheetRenderer extends Layou
&& !(((TobagoFacesContext) facesContext).isAjax()
&& sheetId.equals(((TobagoFacesContext) facesContext).getAjaxComponentId()))) {
- ResourceManager resourceManager = ResourceManagerFactory.getResourceManager(facesContext);
- String contextPath = facesContext.getExternalContext().getRequestContextPath();
-
- String unchecked = contextPath + resourceManager.getImage(facesContext, "image/sheetUnchecked.gif");
- String checked = contextPath + resourceManager.getImage(facesContext, "image/sheetChecked.gif");
-
Integer frequency = null;
UIComponent facetReload = sheet.getFacet(Facets.RELOAD);
if (facetReload != null && facetReload instanceof UIReload && facetReload.isRendered()) {
@@ -145,8 +139,7 @@ public class SheetRenderer extends Layou
frequency = update.getFrequency();
}
final String[] cmds = {
- "new Tobago.Sheet(\"" + sheetId + "\", " + sheet.getFirst()
- + ", \"" + checked + "\", \"" + unchecked + "\", \"" + sheet.getSelectable()
+ "new Tobago.Sheet(\"" + sheetId + "\", " + sheet.getFirst() + ", \"" + sheet.getSelectable()
+ "\", " + columnSelectorIndex + ", " + frequency
+ ", " + (clickAction != null ? HtmlRendererUtils.getJavascriptString(clickAction.getId()) : null)
+ ", " + HtmlRendererUtils.getRenderedPartiallyJavascriptArray(facesContext, clickAction)
@@ -166,12 +159,6 @@ public class SheetRenderer extends Layou
String contextPath = facesContext.getExternalContext().getRequestContextPath();
String sheetId = sheet.getClientId(facesContext);
- String selectorDisabled = contextPath + resourceManager.getImage(facesContext, "image/sheetUncheckedDisabled.gif");
- String unchecked = contextPath + resourceManager.getImage(facesContext, "image/sheetUnchecked.gif");
-
- //Style headerStyle = (Style) attributes.get(STYLE_HEADER);
-// String sheetWidthString = LayoutUtils.getStyleAttributeValue(style,
-// "width");
Measure sheetHeight;
if (style.getHeight() == null) {
// FIXME: nullpointer if height not defined
@@ -337,15 +324,12 @@ public class SheetRenderer extends Layou
if (column instanceof UIColumnSelector) {
final boolean disabled = ComponentUtils.getBooleanAttribute(column, Attributes.DISABLED);
- writer.startElement(HtmlElements.IMG, null);
+ writer.startElement(HtmlElements.INPUT, null);
+ writer.writeAttribute(HtmlAttributes.TYPE, "checkbox", false);
+ writer.writeAttribute(HtmlAttributes.DISABLED, disabled);
+ writer.writeIdAttribute(sheetId + "_data_row_selector_" + rowIndex);
writer.writeClassAttribute(Classes.create(sheet, "columnSelector"));
- if (disabled) {
- writer.writeAttribute(HtmlAttributes.SRC, selectorDisabled, false);
- writer.writeAttribute(HtmlAttributes.DISABLED, "true", false);
- } else {
- writer.writeAttribute(HtmlAttributes.SRC, unchecked, false);
- }
- writer.endElement(HtmlElements.IMG);
+ writer.endElement(HtmlElements.INPUT);
} else {
List<UIComponent> children = sheet.getRenderedChildrenOf(column);
for (UIComponent grandKid : children) {
@@ -403,11 +387,6 @@ public class SheetRenderer extends Layou
writer.endElement(HtmlElements.TABLE);
writer.endElement(HtmlElements.DIV);
-/*
- final String initFirstRowIndex = "Tobago.Sheets.get('" + sheetId + "').firstRowIndex = " + sheet.getFirst() + ";";
- HtmlRendererUtils.writeScriptLoader(facesContext, null, new String[]{initFirstRowIndex});
-*/
-
// END RENDER BODY CONTENT
if (showHeader) {
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js?rev=1141267&r1=1141266&r2=1141267&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js Wed Jun 29 22:04:39 2011
@@ -28,13 +28,11 @@ Tobago.Sheets = {
};
// Info: 2nd parameter "enableAjax" was rededicated to "firstRowIndex"
-Tobago.Sheet = function(sheetId, firstRowIndex, checkedImage, uncheckedImage, selectable, columnSelectorIndex, autoReload,
+Tobago.Sheet = function(sheetId, firstRowIndex, selectable, columnSelectorIndex, autoReload,
clickActionId, clickReloadComponentId, dblClickActionId, dblClickReloadComponentId, renderedPartially) {
this.startTime = new Date(); // @DEV_ONLY
this.id = sheetId;
Tobago.Sheets.put(this);
- this.checkedImage = checkedImage;
- this.uncheckedImage = uncheckedImage;
this.selectable = selectable;
this.columnSelectorIndex = columnSelectorIndex;
this.autoReload = autoReload;
@@ -58,6 +56,9 @@ Tobago.Sheet = function(sheetId, firstRo
this.headerWidthsId = this.id + Tobago.SUB_COMPONENT_SEP + "widths";
this.scrollPositionId = this.id + Tobago.SUB_COMPONENT_SEP + "scrollPosition";
+ this.mouseDownX = undefined;
+ this.mouseDownY = undefined;
+
Tobago.addAjaxComponent(this.id, this);
// option are only used for ajax request
this.options = {
@@ -373,6 +374,7 @@ Tobago.Sheet.prototype.addSelectionListe
currentSheet.getRows().each(function() {
var row = this;
Tobago.addBindEventListener(row, "mousedown", currentSheet, "doMouseDownSelect");
+ Tobago.addBindEventListener(row, "mouseup", currentSheet, "doMouseUpSelect");
Tobago.addBindEventListener(row, "click", currentSheet, "doSelection");
if (currentSheet.dblClickActionId) {
Tobago.addBindEventListener(row, "dblclick", currentSheet, "doDblClick");
@@ -388,6 +390,14 @@ Tobago.Sheet.prototype.doMouseDownSelect
this.mouseDownY = event.clientY;
};
+Tobago.Sheet.prototype.doMouseUpSelect = function(event) {
+ if (!event) {
+ event = window.event;
+ }
+ this.mouseDownX = undefined;
+ this.mouseDownY = undefined;
+};
+
Tobago.Sheet.prototype.doSelection = function(event) {
if (! event) {
event = window.event;
@@ -407,9 +417,10 @@ Tobago.Sheet.prototype.doSelection = fun
//LOG.debug("srcElement = " + srcElement.tagName);
//LOG.debug("Actionid " + this.clickActionId);
//LOG.debug("ID " + this.id);
- if (! Tobago.isInputElement(srcElement.tagName)) {
+ if (srcElement.id.search(/_data_row_selector_/) > -1 || !Tobago.isInputElement(srcElement.tagName)) {
- if (Math.abs(this.mouseDownX - event.clientX) + Math.abs(this.mouseDownY - event.clientY) > 5) {
+ if (this.mouseDownX != undefined &&
+ Math.abs(this.mouseDownX - event.clientX) + Math.abs(this.mouseDownY - event.clientY) > 5) {
// The user has moved the mouse. We assume, the user want to select some text inside the sheet,
// so we doesn't select the row.
return;
@@ -419,7 +430,7 @@ Tobago.Sheet.prototype.doSelection = fun
// find the row, if the has clicked on an element inside the row
var row = jQuery(Tobago.element(event)).closest("tr");
- var selector = this.getSelectorImage(row.get(0));
+ var selector = this.getSelectorCheckbox(row.get(0));
var rowIndex = row.index() + this.firstRowIndex;
var wasSelected = this.isSelected(rowIndex);
@@ -486,10 +497,10 @@ Tobago.Sheet.prototype.doDblClick = func
};
/**
- * Get the image-element, which indicates the selection
+ * Get the element, which indicates the selection
* @param row
*/
-Tobago.Sheet.prototype.getSelectorImage = function(row) {
+Tobago.Sheet.prototype.getSelectorCheckbox = function(row) {
if (this.columnSelectorIndex >= 0) {
return row.childNodes[this.columnSelectorIndex].childNodes[0];
} else {
@@ -501,12 +512,12 @@ Tobago.Sheet.prototype.getSiblingRow = f
return row.parentNode.childNodes[i];
};
-Tobago.Sheet.prototype.isEnabled = function(image) {
- return image == null
- || image.attributes == null
- || image.attributes.disabled === undefined
- || image.attributes.disabled == null
- || image.attributes.disabled.value != "true";
+Tobago.Sheet.prototype.isEnabled = function(checkbox) {
+ return checkbox == null
+ || checkbox.attributes == null
+ || checkbox.attributes.disabled === undefined
+ || checkbox.attributes.disabled == null
+ || checkbox.attributes.disabled.value != "true";
};
Tobago.Sheet.prototype.getRows = function() {
@@ -525,9 +536,9 @@ Tobago.Sheet.prototype.updateSelectionVi
var indexB = this.firstRowIndex + rows.size();
for (var rowIndex = indexA; rowIndex < indexB; rowIndex++) {
var row = rows.get(rowIndex - this.firstRowIndex);
- var image = this.getSelectorImage(row);
+ var checkbox = this.getSelectorCheckbox(row);
if (selected.value.indexOf("," + rowIndex + ",") >= 0) {
- this.selectRow(selected, rowIndex, row, image);
+ this.selectRow(selected, rowIndex, row, checkbox);
}
}
@@ -539,14 +550,14 @@ Tobago.Sheet.prototype.isSelected = func
return selected.value.indexOf("," + rowIndex + ",") >= 0;
};
-Tobago.Sheet.prototype.toggleSelection = function(rowIndex, row, image) {
+Tobago.Sheet.prototype.toggleSelection = function(rowIndex, row, checkbox) {
this.lastClickedRowIndex = rowIndex;
- if (this.isEnabled(image)) {
+ if (this.isEnabled(checkbox)) {
var selected = Tobago.element(this.selectedId);
if (selected.value.indexOf("," + rowIndex + ",") < 0) {
- this.selectRow(selected, rowIndex, row, image);
+ this.selectRow(selected, rowIndex, row, checkbox);
} else {
- this.deselectRow(selected, rowIndex, row, image);
+ this.deselectRow(selected, rowIndex, row, checkbox);
}
}
};
@@ -571,12 +582,12 @@ Tobago.Sheet.prototype.selectRange = fun
var rows = this.getRows();
for (var rowIndex = indexA; rowIndex < indexB; rowIndex++) {
var row = rows.get(rowIndex - this.firstRowIndex);
- var image = this.getSelectorImage(row);
- if (this.isEnabled(image)) {
+ var checkbox = this.getSelectorCheckbox(row);
+ if (this.isEnabled(checkbox)) {
if (selectDeselected && selected.value.indexOf("," + rowIndex + ",") < 0) {
- this.selectRow(selected, rowIndex, row, image);
+ this.selectRow(selected, rowIndex, row, checkbox);
} else if (deselectSelected && selected.value.indexOf("," + rowIndex + ",") >= 0) {
- this.deselectRow(selected, rowIndex, row, image);
+ this.deselectRow(selected, rowIndex, row, checkbox);
}
}
}
@@ -588,13 +599,13 @@ Tobago.Sheet.prototype.selectRange = fun
* @param selected input-element type=hidden: Hidden field with the selection state information
* @param rowIndex int: zero based index of the row.
* @param row tr-element: the row.
- * @param image img-element: selector in the row.
+ * @param checkbox input-element: selector in the row.
*/
-Tobago.Sheet.prototype.selectRow = function(selected, rowIndex, row, image) {
+Tobago.Sheet.prototype.selectRow = function(selected, rowIndex, row, checkbox) {
selected.value = selected.value + rowIndex + ",";
row.className = row.className + " tobago-sheet-row-markup-selected";
- if (image != null) {
- image.src = this.checkedImage;
+ if (checkbox != null) {
+ checkbox.checked = true;
}
};
@@ -602,15 +613,15 @@ Tobago.Sheet.prototype.selectRow = funct
* @param selected input-element type=hidden: Hidden field with the selection state information
* @param rowIndex int: zero based index of the row.
* @param row tr-element: the row.
- * @param image img-element: selector in the row.
+ * @param checkbox input-element: selector in the row.
*/
-Tobago.Sheet.prototype.deselectRow = function(selected, rowIndex, row, image) {
+Tobago.Sheet.prototype.deselectRow = function(selected, rowIndex, row, checkbox) {
selected.value = selected.value.replace(new RegExp("," + rowIndex + ","), ",");
var c = " " + row.className + " ";
c = c.replace(/ tobago-sheet-row-markup-selected /, " ");
row.className = c.substring(1, c.length - 1);
- if (image != null) {
- image.src = this.uncheckedImage;
+ if (checkbox != null) {
+ checkbox.checked = false;
}
};