Author: konstantin.mishin
Date: 2009-04-23 13:06:33 -0400 (Thu, 23 Apr 2009)
New Revision: 13804
Added:
trunk/framework/api/src/main/java/org/richfaces/model/SelectionMode.java
Modified:
trunk/ui/scrollableDataTable/src/main/config/component/scrollable-data-table.xml
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/Selection.js
Log:
RF-2282
Added: trunk/framework/api/src/main/java/org/richfaces/model/SelectionMode.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/SelectionMode.java
(rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/model/SelectionMode.java 2009-04-23
17:06:33 UTC (rev 13804)
@@ -0,0 +1,36 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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.model;
+/**
+ *
+ * @author Konstantin Mishin
+ *
+ */
+public enum SelectionMode {
+ none,
+ single,
+ multi;
+
+ public boolean isSelectionEnabled() {
+ return !equals(none);
+ }
+
+}
Modified:
trunk/ui/scrollableDataTable/src/main/config/component/scrollable-data-table.xml
===================================================================
---
trunk/ui/scrollableDataTable/src/main/config/component/scrollable-data-table.xml 2009-04-23
17:02:12 UTC (rev 13803)
+++
trunk/ui/scrollableDataTable/src/main/config/component/scrollable-data-table.xml 2009-04-23
17:06:33 UTC (rev 13804)
@@ -201,6 +201,13 @@
</description>
</property>
+ <property>
+ <name>selectionMode</name>
+ <classname>org.richfaces.model.SelectionMode</classname>
+ <description>SelectionMode is an enumeration of the possible selection modes.
Default value is "multi"</description>
+ <defaultvalue>SelectionMode.multi</defaultvalue>
+ </property>
+
<property hidden="true" existintag="false"
exist="false" >
<name>rowKey</name>
<classname>java.lang.Object</classname>
Modified:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java 2009-04-23
17:02:12 UTC (rev 13803)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java 2009-04-23
17:06:33 UTC (rev 13804)
@@ -64,6 +64,7 @@
import org.richfaces.model.Ordering;
import org.richfaces.model.ScrollableTableDataModel;
import org.richfaces.model.ScrollableTableDataRange;
+import org.richfaces.model.SelectionMode;
import org.richfaces.model.SortField;
import org.richfaces.model.SortField2;
import org.richfaces.model.SortOrder;
@@ -454,6 +455,13 @@
public abstract String getSortMode();
public abstract void setSortMode(String mode);
+ public abstract SelectionMode getSelectionMode();
+ public abstract void setSelectionMode(SelectionMode mode);
+
+ public boolean isSelectionEnabled() {
+ return getSelectionMode().isSelectionEnabled();
+ }
+
public abstract Object getActiveRowKey();
public abstract void setActiveRowKey(Object activeRowKey);
Modified:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java 2009-04-23
17:02:12 UTC (rev 13803)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java 2009-04-23
17:06:33 UTC (rev 13804)
@@ -64,83 +64,68 @@
final UIScrollableDataTable grid = (UIScrollableDataTable) component;
- ExternalContext externalContext = context.getExternalContext();
- Map<String, String> requestParamMap = externalContext.getRequestParameterMap();
- Application application = context.getApplication();
-
- String id = getSelectionInputName(context, grid);
-
- String value = (String) requestParamMap.get(id);
-
- Converter converter = application.createConverter(ClientSelection.class);
-
- ClientSelection _oldClientSelection =
- (ClientSelection) grid.getAttributes().get(CLIENT_SELECTION);
-
- final ClientSelection oldClientSelection =
- _oldClientSelection == null ?
- new ClientSelection() :
- _oldClientSelection;
-
- final ClientSelection clientSelection =
- (ClientSelection) converter.getAsObject(context, grid, value);
+ if (grid.isSelectionEnabled()) {
+ ExternalContext externalContext = context.getExternalContext();
+ Map<String, String> requestParamMap = externalContext
+ .getRequestParameterMap();
+ Application application = context.getApplication();
+ String id = getSelectionInputName(context, grid);
+ String value = (String) requestParamMap.get(id);
+ Converter converter = application
+ .createConverter(ClientSelection.class);
+ ClientSelection _oldClientSelection = (ClientSelection) grid
+ .getAttributes().get(CLIENT_SELECTION);
+ final ClientSelection oldClientSelection = _oldClientSelection == null ? new
ClientSelection()
+ : _oldClientSelection;
+ final ClientSelection clientSelection = (ClientSelection) converter
+ .getAsObject(context, grid, value);
+ final ScrollableDataTableRendererState state = ScrollableDataTableRendererState
+ .createState(context, grid);
+ state.setRowIndex(ScrollableDataTableUtils.getClientRowIndex(grid));
+ final SimpleSelection simpleSelection = grid.getSelection() == null ? new
SimpleSelection()
+ : (SimpleSelection) grid.getSelection();
+ if (clientSelection.isReset() || clientSelection.isSelectAll()) {
+ simpleSelection.clear();
+ simpleSelection.setSelectAll(clientSelection.isSelectAll());
+ }
+ try {
+ grid.walk(context, new DataVisitor() {
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
-
-
-
- final ScrollableDataTableRendererState state =
- ScrollableDataTableRendererState.createState(context, grid);
-
- state.setRowIndex(ScrollableDataTableUtils.getClientRowIndex(grid));
-
- final SimpleSelection simpleSelection = grid.getSelection() == null ? new
SimpleSelection()
- : (SimpleSelection) grid.getSelection();
+ int i = state.getRowIndex();
-
-
- if (clientSelection.isReset() || clientSelection.isSelectAll()) {
- simpleSelection.clear();
- simpleSelection.setSelectAll(clientSelection.isSelectAll());
- }
-
- try {
- grid.walk(context,
- new DataVisitor() {
- public void process(FacesContext context, Object rowKey,
- Object argument) throws IOException {
-
- int i = state.getRowIndex();
-
- if (shouldAddToSelection(i, oldClientSelection, clientSelection)) {
-
- simpleSelection.addKey(rowKey);
-
- } else if (shouldRemoveFromSelection(i, oldClientSelection, clientSelection)){
-
- simpleSelection.removeKey(rowKey);
-
- }
-
- if(i == clientSelection.getActiveRowIndex()) {
- grid.setActiveRowKey(rowKey);
- }
- state.nextRow();
-
+ if (shouldAddToSelection(i, oldClientSelection,
+ clientSelection)) {
+
+ simpleSelection.addKey(rowKey);
+
+ } else if (shouldRemoveFromSelection(i,
+ oldClientSelection, clientSelection)) {
+
+ simpleSelection.removeKey(rowKey);
+
}
- },
- state);
- } catch(IOException e) {
- throw new FacesException(e);
+
+ if (i == clientSelection.getActiveRowIndex()) {
+ grid.setActiveRowKey(rowKey);
+ }
+ state.nextRow();
+
+ }
+ }, state);
+ } catch (IOException e) {
+ throw new FacesException(e);
+ }
+ grid.setSelection(simpleSelection);
+ ValueExpression selectionBinding = grid
+ .getValueExpression("selection");
+ if (selectionBinding != null) {
+ selectionBinding.setValue(context.getELContext(),
+ simpleSelection);
+ }
+ ScrollableDataTableRendererState.restoreState(context);
}
-
- grid.setSelection(simpleSelection);
-
- ValueExpression selectionBinding = grid.getValueExpression("selection");
- if (selectionBinding != null) {
- selectionBinding.setValue(context.getELContext(), simpleSelection);
- }
-
- ScrollableDataTableRendererState.restoreState(context);
}
/*
@@ -183,19 +168,24 @@
public ScriptOptions buildOptions(FacesContext context,
UIComponent component) {
+ UIScrollableDataTable table = (UIScrollableDataTable) component;
ScriptOptions scriptOptions = new ScriptOptions(component);
- scriptOptions.addOption("selectionInput", getSelectionInputName(
- context, (UIScrollableDataTable) component));
- Map<String, Object> attributes = component.getAttributes();
- Object attribut = attributes.get("selectedClass");
- if (attribut == null) {
- attribut = "";
+ if (table.isSelectionEnabled()) {
+ scriptOptions.addOption("selectionInput", getSelectionInputName(
+ context, table));
+ Map<String, Object> attributes = component.getAttributes();
+ Object attribut = attributes.get("selectedClass");
+ if (attribut == null) {
+ attribut = "";
+ }
+ scriptOptions.addOption("selectedClass", attribut);
+ attribut = attributes.get("activeClass");
+ if (attribut == null) {
+ attribut = "";
+ }
+ scriptOptions.addOption("activeClass", attribut);
+ scriptOptions.addOption("selectionMode", table.getSelectionMode());
}
- scriptOptions.addOption("selectedClass", attribut);
- attribut = attributes.get("activeClass");
- if (attribut == null) {
- attribut = "";
- }scriptOptions.addOption("activeClass", attribut);
return scriptOptions;
}
@@ -205,8 +195,10 @@
UIScrollableDataTable grid = (UIScrollableDataTable) component;
- encodeSelection(context, grid);
- writeSelection(context, grid);
+ if (grid.isSelectionEnabled()) {
+ encodeSelection(context, grid);
+ writeSelection(context, grid);
+ }
}
Modified:
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/Selection.js
===================================================================
---
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/Selection.js 2009-04-23
17:02:12 UTC (rev 13803)
+++
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/Selection.js 2009-04-23
17:06:33 UTC (rev 13804)
@@ -206,6 +206,7 @@
this.selection = new ClientUI.controls.grid.Selection();
this.inputElement = grid.options.selectionInput;
+ this.isSingleMode = "single" == grid.options.selectionMode;
this.onselectionchange = grid.options.onselectionchange;
this.selectedClass = grid.options.selectedClass;
this.activeClass = grid.options.activeClass;
@@ -332,7 +333,7 @@
if (this.inFocus && activeRow != null) {
if(this.firstIndex != activeRow) {
rowIndex = (this.rowCount + activeRow - 1) % this.rowCount;
- if (!event.ctrlKey && !event.shiftKey) {
+ if (this.isSingleMode || (!event.ctrlKey && !event.shiftKey)) {
this.selectionFlag = "x";
range = [rowIndex, rowIndex];
this.setSelection(range);
@@ -357,7 +358,7 @@
if (this.inFocus && activeRow != null) {
rowIndex = (activeRow + 1) % this.rowCount;
if(this.firstIndex != rowIndex) {
- if (!event.ctrlKey && !event.shiftKey) {
+ if (this.isSingleMode || (!event.ctrlKey && !event.shiftKey)) {
this.selectionFlag = "x";
range = [rowIndex, rowIndex];
this.setSelection(range);
@@ -379,7 +380,7 @@
}
break;
case 65: case 97: // Ctrl-A
- if (this.inFocus && event.ctrlKey) {
+ if (this.inFocus && event.ctrlKey && !this.isSingleMode) {
this.selectionFlag = "a";
for (var i = 0; i < this.rowCount; i++) {
this.addRowToSelection(i);
@@ -404,7 +405,7 @@
this.shiftRow = null;
}
var range;
- if ( event.shiftKey && !event.ctrlKey && !event.altKey) {
+ if ( event.shiftKey && !event.ctrlKey && !event.altKey &&
!this.isSingleMode) {
this.firstIndex = Number($(this.prefix +
":n").rows[0].id.split(this.prefix)[1].split(":")[2]);;
this.selectionFlag = "x";
if(!this.shiftRow) {
@@ -420,19 +421,19 @@
}
range = [this.startRow, this.endRow];
this.setSelection(range);
- } else if (!event.shiftKey && event.ctrlKey && !event.altKey) {
+ } else if (!event.shiftKey && event.ctrlKey && !event.altKey
&& !this.isSingleMode) {
if (this.selection.isSelectedId(rowIndex)) {
this.removeRowFromSelection(rowIndex);
} else {
this.addRowToSelection(rowIndex);
}
- } else if (!event.shiftKey && !event.ctrlKey && !event.altKey) {
+ } else if (this.isSingleMode || (!event.shiftKey && !event.ctrlKey &&
!event.altKey)) {
this.selectionFlag = "x";
range = [rowIndex, rowIndex];
this.setSelection(range);
}
this.setActiveRow(rowIndex);
- if (event.shiftKey) {
+ if (event.shiftKey && !this.isSingleMode) {
if (window.getSelection) {
window.getSelection().removeAllRanges();
} else if (document.selection) {