From: <die...@us...> - 2010-02-04 15:05:32
|
Revision: 1797 http://openutils.svn.sourceforge.net/openutils/?rev=1797&view=rev Author: diego_schivo Date: 2010-02-04 15:04:56 +0000 (Thu, 04 Feb 2010) Log Message: ----------- CONTROLS-18 Default savehandler for grid control Modified Paths: -------------- trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGrid.java Modified: trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGrid.java =================================================================== --- trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGrid.java 2010-02-04 14:29:26 UTC (rev 1796) +++ trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGrid.java 2010-02-04 15:04:56 UTC (rev 1797) @@ -53,6 +53,10 @@ throws RepositoryException { super.init(request, response, websiteNode, configNode); + if (StringUtils.isEmpty(getConfigValue("saveHandler"))) + { + setConfig("saveHandler", "net.sourceforge.openutils.mgnlcontrols.dialog.DialogGridSaveHandler"); + } if (configNode != null && configNode.hasContent("columns")) { colConfigs.addAll(configNode.getChildByName("columns").getChildren(ItemType.CONTENTNODE)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2012-01-16 11:04:11
|
Revision: 3733 http://openutils.svn.sourceforge.net/openutils/?rev=3733&view=rev Author: diego_schivo Date: 2012-01-16 11:04:00 +0000 (Mon, 16 Jan 2012) Log Message: ----------- CONTROLS-42 Grid: extra empty lines are not removed on dialog save after row count has been decreased Modified Paths: -------------- trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGrid.java Modified: trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGrid.java =================================================================== --- trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGrid.java 2011-12-28 07:41:17 UTC (rev 3732) +++ trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGrid.java 2012-01-16 11:04:00 UTC (rev 3733) @@ -35,6 +35,7 @@ import net.sourceforge.openutils.mgnlcontrols.configuration.GridColumnTypeManager; import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.math.NumberUtils; /** @@ -103,6 +104,32 @@ } colIndex++; } + int rows = NumberUtils.toInt(String.valueOf(parameters.get("rows")), -1); + if (rows > 0) + { + while (columns.size() < rows) + { + columns.add(new String[0]); + } + while (columns.size() > rows) + { + boolean empty = true; + for (String token : columns.get(columns.size() - 1)) + { + if (!StringUtils.isEmpty(token)) + { + empty = false; + break; + } + } + if (!empty) + { + // non-empty line: do not remove it + break; + } + columns.remove(columns.size() - 1); + } + } value = DialogGridSaveHandler.columnsToValue(columns); } parameters.put("gridValue", value); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2012-01-17 12:05:25
|
Revision: 3734 http://openutils.svn.sourceforge.net/openutils/?rev=3734&view=rev Author: diego_schivo Date: 2012-01-17 12:05:14 +0000 (Tue, 17 Jan 2012) Log Message: ----------- CONTROLS-42 adjustRowCount Modified Paths: -------------- trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGrid.java Modified: trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGrid.java =================================================================== --- trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGrid.java 2012-01-16 11:04:00 UTC (rev 3733) +++ trunk/openutils-mgnlcontrols/src/main/java/net/sourceforge/openutils/mgnlcontrols/dialog/DialogGrid.java 2012-01-17 12:05:14 UTC (rev 3734) @@ -24,6 +24,7 @@ import info.magnolia.cms.util.NodeDataUtil; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -88,6 +89,11 @@ String value = getValue(); if (value != null) { + int rows = NumberUtils.toInt(String.valueOf(getConfigValue("rows")), -1); + if (rows > 0) + { + value = adjustRowCount(value, rows); + } List<String[]> columns = DialogGridSaveHandler.valueToColumns(value); int colIndex = 0; for (String[] column : columns) @@ -104,35 +110,28 @@ } colIndex++; } - int rows = NumberUtils.toInt(String.valueOf(parameters.get("rows")), -1); - if (rows > 0) - { - while (columns.size() < rows) - { - columns.add(new String[0]); - } - while (columns.size() > rows) - { - boolean empty = true; - for (String token : columns.get(columns.size() - 1)) - { - if (!StringUtils.isEmpty(token)) - { - empty = false; - break; - } - } - if (!empty) - { - // non-empty line: do not remove it - break; - } - columns.remove(columns.size() - 1); - } - } value = DialogGridSaveHandler.columnsToValue(columns); } parameters.put("gridValue", value); } + protected String adjustRowCount(String value, int count) + { + List<String> rows = new ArrayList<String>(Arrays.asList(StringUtils.splitPreserveAllTokens(value, '\n'))); + while (rows.size() < count) + { + rows.add(StringUtils.EMPTY); + } + while (rows.size() > count) + { + String row = StringUtils.removeEnd(rows.get(rows.size() - 1), "\r"); + if (!StringUtils.isEmpty(StringUtils.remove(row, '\t'))) + { + // non-empty line: do not remove it + break; + } + rows.remove(rows.size() - 1); + } + return StringUtils.join(rows, '\n'); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |