You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2007/06/25 15:54:18 UTC

svn commit: r550502 - in /incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette: Palette.java component/AbstractOptions.java palette.js

Author: ivaynberg
Date: Mon Jun 25 06:54:18 2007
New Revision: 550502

URL: http://svn.apache.org/viewvc?view=rev&rev=550502
Log:
WICKET-636: Get the ability to add some properties to the html "<option>" tag for the palette component

Modified:
    incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/Palette.java
    incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/AbstractOptions.java
    incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/palette.js

Modified: incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/Palette.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/Palette.java?view=diff&rev=550502&r1=550501&r2=550502
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/Palette.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/Palette.java Mon Jun 25 06:54:18 2007
@@ -17,6 +17,7 @@
 package org.apache.wicket.extensions.markup.html.form.palette;
 
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Iterator;
 
 import org.apache.wicket.Component;
@@ -366,9 +367,22 @@
 	 */
 	protected Component newSelectionComponent()
 	{
-		return new Selection("selection", this);
+		return new Selection("selection", this) {
+			private static final long serialVersionUID = 1L;
+
+			protected HashMap getAdditionalAttributes(Object choice) {
+                return Palette.this.getAdditionalAttributesForSelection(choice);
+            }
+        };
 	}
 
+    /**
+     * @see wicket.extensions.markup.html.form.palette.component#getAdditionalAttributes()
+     */
+    protected HashMap getAdditionalAttributesForSelection(Object choice) {
+        return null;
+    }
+	
 	/**
 	 * factory method for the available items component
 	 * 
@@ -376,9 +390,22 @@
 	 */
 	protected Component newChoicesComponent()
 	{
-		return new Choices("choices", this);
+		return new Choices("choices", this) {
+			private static final long serialVersionUID = 1L;
+
+			protected HashMap getAdditionalAttributes(Object choice) {
+                return Palette.this.getAdditionalAttributesForChoices(choice);
+            }
+        };
 	}
 
+    /**
+     * @see wicket.extensions.markup.html.form.palette.component#getAdditionalAttributes()
+     */
+    protected HashMap getAdditionalAttributesForChoices(Object choice) {
+        return null;
+    }
+	
 	private Component getChoicesComponent()
 	{
 		return choicesComponent;

Modified: incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/AbstractOptions.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/AbstractOptions.java?view=diff&rev=550502&r1=550501&r2=550502
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/AbstractOptions.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/AbstractOptions.java Mon Jun 25 06:54:18 2007
@@ -16,6 +16,7 @@
  */
 package org.apache.wicket.extensions.markup.html.form.palette.component;
 
+import java.util.HashMap;
 import java.util.Iterator;
 
 import org.apache.wicket.extensions.markup.html.form.palette.Palette;
@@ -81,8 +82,18 @@
 			  			  "    Wicket.Form.excludeFromAjaxSerialization." + this.getMarkupId() + "='true';" +
 						  JavascriptUtils.SCRIPT_CLOSE_TAG);
 			
-			buffer.append("\n<option value=\"").append(id).append("\">").append(value).append(
-					"</option>");
+            buffer.append("\n<option value=\"").append(id).append("\"");
+            
+            HashMap additionalAttributesMap = getAdditionalAttributes(choice);
+            if(additionalAttributesMap != null) {
+                Iterator iter = additionalAttributesMap.keySet().iterator();
+                while(iter.hasNext()) {
+                    String next = (String)iter.next();
+                    buffer.append(" " + next.toString() + "=\"" + additionalAttributesMap.get(next).toString() + "\"");
+                }
+            }
+            
+			buffer.append(">").append(value).append("</option>");
 
 		}
 
@@ -90,6 +101,13 @@
 		replaceComponentTagBody(markupStream, openTag, buffer);
 	}
 
+    /**
+     * @return map of attribute/value pairs (String/String)
+     */
+    protected HashMap getAdditionalAttributes(Object choice) {
+        return null;
+    }
+	
 	/**
 	 * 
 	 * @param tag

Modified: incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/palette.js
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/palette.js?view=diff&rev=550502&r1=550501&r2=550502
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/palette.js (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/palette.js Mon Jun 25 06:54:18 2007
@@ -50,12 +50,8 @@
 	function paletteMoveHelper(source, dest) {
 		var dirty=false;
 		for (var i=0;i<source.options.length;i++) {
-			if (source.options[i].selected) {
-				var option=new Option(source.options[i].text, source.options[i].value);
-				var destIndex=dest.options.length;
-				dest.options[destIndex]=option;
-				dest.options[destIndex].selected=true;
-				source.options[i]=null;
+			if (source.options[i].selected) {	
+				dest.appendChild(source.options[i]);
 				i--;
 				dirty=true;
 			}
@@ -73,21 +69,13 @@
 	}
 	
 	function paletteMoveUpHelper(box) {
-		var start=0;
 		var dirty=false;
-
-		for (start=0;start<box.options.length;start++) {
-			if (box.options[start].selected==false) {
-				break;
-			}
-		}
-		start++;
-
-		for (var i=start;i<box.options.length;i++) {
-			if (box.options[i].selected) {
-				paletteSwapHelper(box, i, i-1);
-				box.options[i-1].selected=true;
-				dirty=true;
+		for (var i=0;i<box.options.length;i++) {
+			if (box.options[i].selected && i>0) {
+				if(!box.options[i-1].selected) {
+					box.insertBefore(box.options[i],box.options[i-1]);
+					dirty=true;
+				}
 			}
 		}
 		return dirty;
@@ -95,7 +83,6 @@
 	
 	function paletteMoveDown(choicesId, selectionId, recorderId) {
 		var selection=paletteResolve(selectionId);
-		
 
 		if (paletteMoveDownHelper(selection)) {
 			var recorder=paletteResolve(recorderId);
@@ -104,36 +91,17 @@
 	}
 
 	function paletteMoveDownHelper(box) {
-		var start=0;
 		var dirty=false;
-
-		for (start=box.options.length-1;start>=0;start--) {
-			if (box.options[start].selected==false) {
-				break;
-			}
-		}
-		start--;
-
-		for (var i=start;i>=0;i--) {
-			if (box.options[i].selected) {
-				paletteSwapHelper(box, i, i+1);
-				box.options[i+1].selected=true;
-				dirty=true;
+		for (var i=box.options.length-1;i>=0;i--) {
+			if (box.options[i].selected && i<box.options.length-1) {
+				if(!box.options[i+1].selected) {
+					box.insertBefore(box.options[i+1],box.options[i]);
+					dirty=true;
+				}
 			}
 		}
 		return dirty;
-	}
-	
-		
-	function paletteSwapHelper(box, idx1, idx2) {
-		var value1=box.options[idx1].value;
-		var text1=box.options[idx1].text;
-		var value2=box.options[idx2].value;
-		var text2=box.options[idx2].text;
-		box.options[idx1]=new Option(text2, value2);
-		box.options[idx2]=new Option(text1, value1);
-	}
-	
+	}	
 	
 	function paletteUpdateRecorder(selection, recorder) {
 		recorder.value="";
@@ -152,4 +120,3 @@
 			box.options[i].selected=false;
 		}	
 	}
-	
\ No newline at end of file