You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2007/11/25 20:18:55 UTC
svn commit: r598035 - in /myfaces/tobago/trunk:
core/src/main/java/org/apache/myfaces/tobago/
core/src/main/java/org/apache/myfaces/tobago/component/
core/src/main/java/org/apache/myfaces/tobago/renderkit/html/
core/src/main/java/org/apache/myfaces/tob...
Author: bommel
Date: Sun Nov 25 11:18:53 2007
New Revision: 598035
URL: http://svn.apache.org/viewvc?rev=598035&view=rev
Log:
(TOBAGO-553) Support for click and dblClick action in the sheet
Added:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIColumnEvent.java (with props)
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnEventTag.java (with props)
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnEventTagDeclaration.java (with props)
Modified:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java
myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/list.jsp
myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java?rev=598035&r1=598034&r2=598035&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java Sun Nov 25 11:18:53 2007
@@ -49,6 +49,7 @@
public static final String ATTR_ENCTYPE = "enctype";
public static final String ATTR_ESCAPE = "escape";
public static final String ATTR_EXPANDED = "expanded";
+ public static final String ATTR_EVENT = "event";
public static final String ATTR_FIRST = "first";
public static final String ATTR_FREQUENCY = "frequency";
public static final String ATTR_FOCUS = "focus";
Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIColumnEvent.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIColumnEvent.java?rev=598035&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIColumnEvent.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIColumnEvent.java Sun Nov 25 11:18:53 2007
@@ -0,0 +1,64 @@
+package org.apache.myfaces.tobago.component;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_EVENT;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+import javax.faces.component.UIColumn;
+
+/* User: bommel
+ * Date: 24.11.2007
+ * Time: 23:00:04
+ */
+public class UIColumnEvent extends UIColumn {
+
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.ColumnEvent";
+
+ private String event;
+
+ public Object saveState(FacesContext context) {
+ Object[] values = new Object[2];
+ values[0] = super.saveState(context);
+ values[1] = event;
+ return values;
+ }
+
+ public void restoreState(FacesContext context, Object savedState) {
+ Object[] values = (Object[]) savedState;
+ super.restoreState(context, values[0]);
+ event = (String) values[1];
+ }
+
+ public void setEvent(String event) {
+ this.event = event;
+ }
+
+ public String getEvent() {
+ if (event != null) {
+ return event;
+ }
+ ValueBinding vb = getValueBinding(ATTR_EVENT);
+ if (vb != null) {
+ return (String) vb.getValue(getFacesContext());
+ } else {
+ return null;
+ }
+ }
+}
\ No newline at end of file
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIColumnEvent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIColumnEvent.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java?rev=598035&r1=598034&r2=598035&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java Sun Nov 25 11:18:53 2007
@@ -301,36 +301,6 @@
}
}
}
- /*String[] layoutTokens
- = LayoutInfo.createLayoutTokens(columnLayout, allColumns.size(), "1*");
- if (layoutTokens.length != allColumns.size()) {
- LOG.warn("Count of columnLayout tokens in '" + columnLayout
- + "' != count of columns (" + allColumns.size() + ")! "
- + "Using default token '1*' for all columns");
- layoutTokens
- = LayoutInfo.createLayoutTokens(null, allColumns.size(), "1*");
- } */
-
- // here we have layoutTokens for all columns
- // now remove tokens for unrendered columns
- /*boolean changed = false;
- for (int i = 0; i < layoutTokens.length; i++) {
- if (!allColumns.get(i).isRendered()) {
- layoutTokens[i] = null;
- changed = true;
- }
- }
- if (changed) {
- String[] allTokens = layoutTokens;
- layoutTokens = new String[columns.size()];
- int j = 0;
- for (String allToken : allTokens) {
- if (allToken != null) {
- layoutTokens[j] = allToken;
- j++;
- }
- }
- } */
@@ -555,7 +525,7 @@
public List<UIColumn> getAllColumns() {
List<UIColumn> columns = new ArrayList<UIColumn>();
for (UIComponent kid : (List<UIComponent>) getChildren()) {
- if (kid instanceof UIColumn) {
+ if (kid instanceof UIColumn && !(kid instanceof UIColumnEvent)) {
columns.add((UIColumn) kid);
}
}
@@ -565,7 +535,7 @@
public List<UIColumn> getRenderedColumns() {
List<UIColumn> columns = new ArrayList<UIColumn>();
for (UIComponent kid : (List<UIComponent>) getChildren()) {
- if (kid instanceof UIColumn && kid.isRendered()) {
+ if (kid instanceof UIColumn && kid.isRendered() && !(kid instanceof UIColumnEvent)) {
columns.add((UIColumn) kid);
}
}
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java?rev=598035&r1=598034&r2=598035&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java Sun Nov 25 11:18:53 2007
@@ -655,4 +655,26 @@
writer.writeAttribute(HtmlAttributes.ALT, "", false);
}
}
+
+ public static String getJavascriptString(String str) {
+ if (str != null) {
+ return "\"" + str + "\"" ;
+ }
+ return null;
+ }
+
+ public static String getJavascriptArray(String[] list) {
+ StringBuilder strBuilder = new StringBuilder();
+ strBuilder.append("[");
+ for (int i = 0; i < list.length; i++) {
+ if (i != 0) {
+ strBuilder.append(",");
+ }
+ strBuilder.append("\"");
+ strBuilder.append(list[i]);
+ strBuilder.append("\"");
+ }
+ strBuilder.append("]");
+ return strBuilder.toString();
+ }
}
Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnEventTag.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnEventTag.java?rev=598035&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnEventTag.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnEventTag.java Sun Nov 25 11:18:53 2007
@@ -0,0 +1,60 @@
+package org.apache.myfaces.tobago.taglib.component;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_EVENT;
+import org.apache.myfaces.tobago.component.ComponentUtil;
+import org.apache.myfaces.tobago.component.UIColumnEvent;
+
+import javax.faces.component.UIComponent;
+
+/*
+ * Date: 24.11.2007
+ * Time: 22:46:14
+ */
+public class ColumnEventTag extends TobagoTag implements ColumnEventTagDeclaration {
+ public String getComponentType() {
+ return UIColumnEvent.COMPONENT_TYPE;
+ }
+
+ public String getRendererType() {
+ return null;
+ }
+
+ private String event;
+
+ @Override
+ protected void setProperties(UIComponent component) {
+ super.setProperties(component);
+ ComponentUtil.setStringProperty(component, ATTR_EVENT, event);
+ }
+
+ @Override
+ public void release() {
+ super.release();
+ this.event = null;
+ }
+
+ public String getEvent() {
+ return event;
+ }
+
+ public void setEvent(String event) {
+ this.event = event;
+ }
+}
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnEventTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnEventTag.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnEventTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnEventTagDeclaration.java?rev=598035&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnEventTagDeclaration.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnEventTagDeclaration.java Sun Nov 25 11:18:53 2007
@@ -0,0 +1,43 @@
+package org.apache.myfaces.tobago.taglib.component;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+import org.apache.myfaces.tobago.apt.annotation.Tag;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
+import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
+import org.apache.myfaces.tobago.taglib.decl.HasId;
+import org.apache.myfaces.tobago.taglib.decl.HasBinding;
+
+/*
+ * User: bommel
+ * Date: 24.11.2007
+ * Time: 22:56:49
+ */
+
+@Tag(name = "columnEvent")
+@UIComponentTag(uiComponent = "org.apache.myfaces.tobago.component.UIColumnEvent")
+public interface ColumnEventTagDeclaration extends TobagoTagDeclaration, HasId, HasBinding {
+
+ @TagAttribute
+ @UIComponentTagAttribute()
+ void setEvent(String event);
+
+}
+
+
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnEventTagDeclaration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnEventTagDeclaration.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/list.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/list.jsp?rev=598035&r1=598034&r2=598035&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/list.jsp (original)
+++ myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/list.jsp Sun Nov 25 11:18:53 2007
@@ -100,6 +100,9 @@
var="address" state="#{controller.selectedAddresses}"
sortActionListener="#{controller.sheetSorter}" rows="25"
showRowRange="left" showPageRange="right" showDirectLinks="center">
+ <tc:columnEvent event="dblclick" >
+ <tc:command action="#{controller.editAddress}" />
+ </tc:columnEvent>
<tc:column id="firstName" label="#{bundle.listFirstName}" sortable="true"
rendered="#{controller.renderFirstName}">
<tc:out value="#{address.firstName}" />
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=598035&r1=598034&r2=598035&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 Sun Nov 25 11:18:53 2007
@@ -70,6 +70,7 @@
import org.apache.myfaces.tobago.component.UIMenuCommand;
import org.apache.myfaces.tobago.component.UIPage;
import org.apache.myfaces.tobago.component.UIReload;
+import org.apache.myfaces.tobago.component.UIColumnEvent;
import org.apache.myfaces.tobago.config.TobagoConfig;
import org.apache.myfaces.tobago.context.ResourceManager;
import org.apache.myfaces.tobago.context.ResourceManagerFactory;
@@ -151,9 +152,31 @@
UIReload update = (UIReload) facetReload;
frequency = update.getFrequency();
}
+ UICommand clickAction = null;
+ UICommand dblClickAction = null;
+ for (UIComponent child : (List<UIComponent>)data.getChildren()) {
+ if (child instanceof UIColumnEvent) {
+ UIColumnEvent columnEvent = (UIColumnEvent) child;
+ UIComponent selectionChild = (UIComponent) child.getChildren().get(0);
+ if (selectionChild != null && selectionChild instanceof UICommand && selectionChild.isRendered()) {
+ UICommand action = (UICommand) selectionChild;
+ if ("click".equals(columnEvent.getEvent())) {
+ clickAction = action;
+ }
+ if ("dblclick".equals(columnEvent.getEvent())) {
+ dblClickAction = action;
+ }
+ }
+ }
+ }
final String[] cmds = {
"new Tobago.Sheet(\"" + sheetId + "\", " + ajaxEnabled
- + ", \"" + checked + "\", \"" + unchecked + "\", \"" + data.getSelectable() + "\", "+ frequency + ");"
+ + ", \"" + checked + "\", \"" + unchecked + "\", \"" + data.getSelectable() + "\", "+ frequency
+ + ", " + (clickAction!=null?HtmlRendererUtil.getJavascriptString(clickAction.getId()):null)
+ + ", " + (clickAction!=null?HtmlRendererUtil.getJavascriptArray(clickAction.getRenderedPartially()):null)
+ + ", " + (dblClickAction!=null?HtmlRendererUtil.getJavascriptString(dblClickAction.getId()):null) + ", "
+ + (dblClickAction!=null?HtmlRendererUtil.getJavascriptArray(dblClickAction.getRenderedPartially()):null)
+ + ");"
};
UIPage page = ComponentUtil.findPage(facesContext, data);
page.getStyleFiles().add(styles[0]);
Modified: myfaces/tobago/trunk/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/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js?rev=598035&r1=598034&r2=598035&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js (original)
+++ myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js Sun Nov 25 11:18:53 2007
@@ -40,7 +40,8 @@
};
-Tobago.Sheet = function(sheetId, enableAjax, checkedImage, uncheckedImage, selectable, autoReload) {
+Tobago.Sheet = function(sheetId, enableAjax, checkedImage, uncheckedImage, selectable, autoReload,
+ clickActionId, clickReloadComponentId, dblClickActionId, dblClickReloadComponentId) {
this.startTime = new Date();
this.id = sheetId;
Tobago.Sheets.put(this);
@@ -49,6 +50,10 @@
this.uncheckedImage = uncheckedImage;
this.selectable = selectable;
this.autoReload = autoReload;
+ this.clickActionId = clickActionId;
+ this.clickReloadComponentId = clickReloadComponentId;
+ this.dblClickActionId = dblClickActionId;
+ this.dblClickReloadComponentId = dblClickReloadComponentId;
this.resizerId = undefined;
this.oldX = 0;
@@ -444,6 +449,9 @@
while (row) {
// LOG.debug("rowId = " + row.id + " next i=" + i);
Tobago.addBindEventListener(row, "click", this, "doSelection");
+ if (this.dblClickActionId) {
+ Tobago.addBindEventListener(row, "dblclick", this, "doDblClick");
+ }
row = Tobago.element(this.id + "_data_tr_" + i++ );
}
//LOG.debug("preSelected rows = " + Tobago.element(sheetId + "::selected").value);
@@ -467,7 +475,8 @@
//LOG.debug("event.ctrlKey = " + event.ctrlKey);
//LOG.debug("event.shiftKey = " + event.shiftKey);
//LOG.debug("srcElement = " + srcElement.tagName);
-
+ //LOG.debug("Actionid " + this.clickActionId);
+ //LOG.debug("ID " + this.id);
if (! Tobago.isInputElement(srcElement.tagName)) {
Tobago.clearSelection();
@@ -495,6 +504,55 @@
}
this.updateSelectionView();
//LOG.debug("selected rows = " + hidden.value);
+ if (this.clickActionId) {
+ var action = this.id + ":" + rowIndex + ":" + this.clickActionId;
+ //LOG.debug("Action " + action);
+ if (this.clickReloadComponentId && this.clickReloadComponentId.length > 0) {
+ Tobago.reloadComponent(this.clickReloadComponentId[0], action)
+ } else {
+ Tobago.submitAction(action, true, null);
+ }
+ }
+ }
+ };
+
+Tobago.Sheet.prototype.doDblClick = function(event) {
+ if (! event) {
+ event = window.event;
+ }
+
+ var srcElement;
+ if (event.target) {
+ // W3C DOM level 2
+ srcElement = event.target;
+ } else {
+ // IE
+ srcElement = event.srcElement;
+ }
+
+ //LOG.debug("event.ctrlKey = " + event.ctrlKey);
+ //LOG.debug("event.shiftKey = " + event.shiftKey);
+ //LOG.debug("srcElement = " + srcElement.tagName);
+ //LOG.debug("Actionid " + this.clickActionId);
+ //LOG.debug("ID " + this.id);
+ if (! Tobago.isInputElement(srcElement.tagName)) {
+ var dataRow = Tobago.element(event);
+ while (dataRow.id.search(new RegExp("_data_tr_\\d+$")) == -1) {
+ dataRow = dataRow.parentNode;
+ }
+ var rowId = dataRow.id;
+ //LOG.debug("rowId = " + rowId);
+ var rowIndex = rowId.substring(rowId.lastIndexOf("_data_tr_") + 9);
+ //LOG.debug("selected rows = " + hidden.value);
+ if (this.dblClickActionId) {
+ var action = this.id + ":" + rowIndex + ":" + this.dblClickActionId;
+ //LOG.debug("dblAction " + action);
+ if (this.dblClickReloadComponentId && this.dblClickReloadComponentId.length > 0) {
+ Tobago.reloadComponent(this.dblClickReloadComponentId[0], action)
+ } else {
+ Tobago.submitAction(action, true, null);
+ }
+ }
}
};