details: /erp/devel/pi/rev/71ae37dedcfa changeset: 9308:71ae37dedcfa user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Wed Dec 22 16:49:52 2010 +0100 summary: fixed bug 13687: Sort tabs are less intrusive when updating
Previously sort tabs tried to reorder all the items with an interval between positions of 10. The only exception to this was in case the item was in a module not in development. Now it tries to do as less changes as possible, keeping the elements in the same position as they were in case they were already sorted even if their interval is not 10. When positioning a new element between 2 existent ones, it is tried its possition not to affect the other elements but to look for a sequenece in between, only in case no free sequences are available sequences for other elements are recalculated. diffstat: src-db/database/model/triggers/AD_FIELD_TRG2.xml | 34 ++++ src-wad/src/org/openbravo/wad/javasourceSortTab.javaxml | 110 +++++++++++++-- 2 files changed, 124 insertions(+), 20 deletions(-) diffs (193 lines): diff -r 95c0f9711201 -r 71ae37dedcfa src-db/database/model/triggers/AD_FIELD_TRG2.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-db/database/model/triggers/AD_FIELD_TRG2.xml Wed Dec 22 16:49:52 2010 +0100 @@ -0,0 +1,34 @@ +<?xml version="1.0"?> + <database name="TRIGGER AD_FIELD_TRG2"> + <trigger name="AD_FIELD_TRG2" table="AD_FIELD" fires="before" insert="false" update="true" delete="false" foreach="row"> + <body><![CDATA[ + /************************************************************************* + * The contents of this file are subject to the Openbravo Public License + * Version 1.1 (the "License"), being the Mozilla Public License + * Version 1.1 with a permitted attribution clause; you may not use this + * file except in compliance with the License. You may obtain a copy of + * the License at http://www.openbravo.com/legal/license.html + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * The Original Code is Openbravo ERP. + * The Initial Developer of the Original Code is Openbravo SLU + * All portions are Copyright (C) 2010 Openbravo SLU + * All Rights Reserved. + * Contributor(s): ______________________________________. + ************************************************************************/ + +BEGIN + + IF AD_isTriggerEnabled()='N' THEN RETURN; + END IF; + + IF (:old.IsDisplayed='Y' and :new.IsDisplayed='N') THEN + :new.seqNo := null; + END IF; + +END AD_FIELD_TRG2 +]]></body> + </trigger> + </database> diff -r 95c0f9711201 -r 71ae37dedcfa src-wad/src/org/openbravo/wad/javasourceSortTab.javaxml --- a/src-wad/src/org/openbravo/wad/javasourceSortTab.javaxml Wed Dec 22 16:31:14 2010 +0100 +++ b/src-wad/src/org/openbravo/wad/javasourceSortTab.javaxml Wed Dec 22 16:49:52 2010 +0100 @@ -130,33 +130,100 @@ i++; } - //modify only in case the field's module is in development + //modify only in case the field's module is in development int start=0; int end=0; int seqno=0; int maxSeqno=0; boolean templateInDev = <PARAMETER_TMP id="class">Almacen</PARAMETER_TMP>Data.isTemplateInDev(this); - while(end < size) { + while (end < size) { + // start-end define the first and last element to sort start = end; - while (start < size && !templateInDev && dataShown[start].isindevelopment.equals("N")) start++; - end = start; - while (end < size && (templateInDev || dataShown[end].isindevelopment.equals("Y"))) end++; - - if (start > 0) seqno = new Integer(dataShown[start-1].seqnoParam).intValue(); - if (end < size) maxSeqno = new Integer(dataShown[end].seqnoParam).intValue(); - if ((start > 0) && (end < size-1) && (seqno > maxSeqno)){ + + // look for the first non-sorted item, and set it as start + boolean sorted = true; + while (start < size && sorted) { + if (start < size - 1) { + sorted = !(dataShown[start].seqnoParam.isEmpty() && !dataShown[start + 1].seqnoParam + .isEmpty()); + sorted = sorted + && !(dataShown[start].seqnoParam.isEmpty() && dataShown[start + 1].seqnoParam + .isEmpty()); + if (sorted && !dataShown[start].seqnoParam.isEmpty() + && !dataShown[start + 1].seqnoParam.isEmpty()) { + sorted = Integer.parseInt(dataShown[start].seqnoParam) < Integer + .parseInt(dataShown[start + 1].seqnoParam); + } + } else if (start == size - 1) { + // In case a single element, treat it as not sorted + sorted = false; + } + + if (sorted) { + start++; + } + } + + // Start now contains the first unsorted element, if it is not in dev, move start forward + while (start < size && !templateInDev && dataShown[start].isindevelopment.equals("N")) { + start++; + } + + // Looking for end. It will be the last unsorted element + end = start + 1; + if (end > size) { + end = size; + } + if (start > 0 && !dataShown[start - 1].seqnoParam.isEmpty()) { + seqno = new Integer(dataShown[start - 1].seqnoParam).intValue(); + } + while (end < size && !sorted + && (templateInDev || dataShown[end].isindevelopment.equals("Y"))) { + + sorted = dataShown[end].seqnoParam.isEmpty() && !dataShown[end].seqnoParam.isEmpty(); + sorted = sorted + || end + 1 < size + && !(dataShown[end].seqnoParam.isEmpty() || dataShown[end + 1].seqnoParam.isEmpty()) + && Integer.parseInt(dataShown[end].seqnoParam) < Integer + .parseInt(dataShown[end + 1].seqnoParam); + + if (end + 1 < size && !dataShown[end].seqnoParam.isEmpty()) { + maxSeqno = new Integer(dataShown[end].seqnoParam).intValue(); + + if (sorted && maxSeqno - seqno <= end - start) { + // It is sorted, it should be the end point, but there's no place for sorting, set + // it as unsorted to look for more place if possible. + sorted = false; + } + } + if (!sorted) { + end++; + } + } + + if (maxSeqno == 0 && end < size) { + maxSeqno = new Integer(dataShown[end].seqnoParam).intValue(); + } + + log4j.debug("Sorting from position:" + start + " to:" + end + ". Size:" + size); + + if ((start > 0) && (end < size) && (seqno >= maxSeqno) && !(start == end && end == size)) { myError.setType("Error"); myError.setTitle(Utility.messageBD(this, "Error", vars.getLanguage())); - myError.setMessage(Utility.messageBD(this, "CannotReorderNotDevModules", vars.getLanguage())); + myError.setMessage(Utility.messageBD(this, "CannotReorderNotDevModules", vars + .getLanguage())); releaseRollbackConnection(conn); error = true; break; } - if (end==size) maxSeqno = -1; //no limit - int add = (maxSeqno == -1 )?10:new Float(((maxSeqno-seqno)/(end-start+1))).intValue(); - for (int j=start; j < end; j++) { - if (maxSeqno == -1 || seqno < maxSeqno) seqno+=add; + if (end == size) + maxSeqno = -1; // no limit + int add = (maxSeqno == -1) ? 10 : new Float(((maxSeqno - seqno) / (end - start + 1))) + .intValue(); + for (int j = start; j < end; j++) { + if (maxSeqno == -1 || seqno < maxSeqno) + seqno += add; else { myError.setType("Warning"); myError.setTitle(Utility.messageBD(this, "Warning", vars.getLanguage())); @@ -165,19 +232,22 @@ dataShown[j].seqnoParam = Integer.toString(seqno); } } - - for (int j=0; !error && j < dataShown.length; j++) { - if (j < dataShown.length-1 && (new Integer(dataShown[j].seqnoParam).intValue() > new Integer(dataShown[j+1].seqnoParam).intValue())) { + + for (int j = 0; !error && j < dataShown.length; j++) { + if (j < dataShown.length - 1 + && (dataShown[j].seqnoParam.isEmpty() || dataShown[j + 1].seqnoParam.isEmpty() || Integer + .parseInt(dataShown[j].seqnoParam) > Integer + .parseInt(dataShown[j + 1].seqnoParam))) { myError.setType("Error"); myError.setTitle(Utility.messageBD(this, "Error", vars.getLanguage())); - myError.setMessage(Utility.messageBD(this, "CannotReorderNotDevModules", vars.getLanguage())); + myError.setMessage(Utility.messageBD(this, "CannotReorderNotDevModules", vars + .getLanguage())); releaseRollbackConnection(conn); error = true; break; } dataShown[j].updateY(conn, this); } - } if (!error) { releaseCommitConnection(conn); @@ -207,7 +277,7 @@ try { releaseRollbackConnection(conn); } catch (Exception ignored) {} - throw new ServletException("@CODE=@" + exc.getMessage()); + throw new ServletException("@CODE=@" + exc.getMessage(), exc); } } ------------------------------------------------------------------------------ Forrester recently released a report on the Return on Investment (ROI) of Google Apps. They found a 300% ROI, 38%-56% cost savings, and break-even within 7 months. Over 3 million businesses have gone Google with Google Apps: an online email calendar, and document program that's accessible from your browser. Read the Forrester report: http://p.sf.net/sfu/googleapps-sfnew _______________________________________________ Openbravo-commits mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbravo-commits
