You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by kn...@apache.org on 2007/03/25 01:31:45 UTC

svn commit: r522132 - in /incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket: ajax/markup/html/ ajax/markup/html/form/ markup/html/form/ markup/html/link/

Author: knopp
Date: Sat Mar 24 17:31:44 2007
New Revision: 522132

URL: http://svn.apache.org/viewvc?view=rev&rev=522132
Log:
WICKET-415 -  Backport link hierarchy from trunk

Added:
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/AbstractSubmitLink.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/link/AbstractLink.java
Modified:
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/AjaxFallbackLink.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/AjaxLink.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitLink.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/SubmitLink.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/link/Link.java

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/AjaxFallbackLink.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/AjaxFallbackLink.java?view=diff&rev=522132&r1=522131&r2=522132
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/AjaxFallbackLink.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/AjaxFallbackLink.java Sat Mar 24 17:31:44 2007
@@ -20,6 +20,7 @@
 import wicket.ajax.AjaxRequestTarget;
 import wicket.ajax.IAjaxCallDecorator;
 import wicket.ajax.calldecorator.CancelEventIfNoAjaxDecorator;
+import wicket.markup.ComponentTag;
 import wicket.markup.html.link.Link;
 import wicket.model.IModel;
 
@@ -71,7 +72,15 @@
 				return new CancelEventIfNoAjaxDecorator(AjaxFallbackLink.this
 						.getAjaxCallDecorator());
 			}
-
+			
+			protected void onComponentTag(ComponentTag tag)
+			{
+				// only render handler if link is enabled
+				if (isLinkEnabled())
+				{
+					super.onComponentTag(tag);
+				}
+			}
 		});
 	}
 

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/AjaxLink.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/AjaxLink.java?view=diff&rev=522132&r1=522131&r2=522132
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/AjaxLink.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/AjaxLink.java Sat Mar 24 17:31:44 2007
@@ -21,7 +21,7 @@
 import wicket.ajax.IAjaxCallDecorator;
 import wicket.ajax.calldecorator.CancelEventIfNoAjaxDecorator;
 import wicket.markup.ComponentTag;
-import wicket.markup.html.WebMarkupContainer;
+import wicket.markup.html.link.AbstractLink;
 import wicket.model.IModel;
 
 /**
@@ -32,7 +32,7 @@
  * @author Igor Vaynberg (ivaynberg)
  * 
  */
-public abstract class AjaxLink extends WebMarkupContainer implements IAjaxLink
+public abstract class AjaxLink extends AbstractLink implements IAjaxLink
 {
 	private static final long serialVersionUID = 1L;
 
@@ -70,18 +70,35 @@
 				return new CancelEventIfNoAjaxDecorator(AjaxLink.this.getAjaxCallDecorator());
 			}
 
+			protected void onComponentTag(ComponentTag tag)
+			{
+				// add the onclick handler only if link is enabled 
+				if (isLinkEnabled())
+				{
+					super.onComponentTag(tag);
+				}
+			}
 		});
 	}
 
 	protected void onComponentTag(ComponentTag tag)
 	{
 		super.onComponentTag(tag);
-		// disable any href attr in markup
-		if (tag.getName().equalsIgnoreCase("a") || tag.getName().equalsIgnoreCase("link")
-				|| tag.getName().equalsIgnoreCase("area"))
+		
+		if (isLinkEnabled()) 
+		{
+			// disable any href attr in markup
+			if (tag.getName().equalsIgnoreCase("a") || tag.getName().equalsIgnoreCase("link")
+					|| tag.getName().equalsIgnoreCase("area"))
+			{
+				tag.put("href", "#");
+			}
+		} 
+		else 
 		{
-			tag.put("href", "#");
+			disableLink(tag);
 		}
+		
 	}
 
 	/**

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitLink.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitLink.java?view=diff&rev=522132&r1=522131&r2=522132
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitLink.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitLink.java Sat Mar 24 17:31:44 2007
@@ -20,7 +20,7 @@
 import wicket.ajax.IAjaxCallDecorator;
 import wicket.ajax.form.AjaxFormSubmitBehavior;
 import wicket.markup.ComponentTag;
-import wicket.markup.html.WebMarkupContainer;
+import wicket.markup.html.form.AbstractSubmitLink;
 import wicket.markup.html.form.Form;
 import wicket.util.string.AppendingStringBuffer;
 
@@ -33,7 +33,7 @@
  * 
  * @author Igor Vaynberg (ivaynberg)
  */
-public abstract class AjaxSubmitLink extends WebMarkupContainer
+public abstract class AjaxSubmitLink extends AbstractSubmitLink
 {
 	private static final long serialVersionUID = 1L;
 
@@ -81,6 +81,15 @@
 			{
 				return AjaxSubmitLink.this.getAjaxCallDecorator();
 			}
+			
+			protected void onComponentTag(ComponentTag tag)
+			{
+				// write the onclick handler only if link is enabled
+				if (isLinkEnabled())
+				{					
+					super.onComponentTag(tag);
+				}
+			}
 		});
 
 	}
@@ -101,8 +110,26 @@
 	protected void onComponentTag(ComponentTag tag)
 	{
 		super.onComponentTag(tag);
-		checkComponentTag(tag, "a");
-		tag.put("href", "#");
+		
+		if (isLinkEnabled()) 
+		{
+			checkComponentTag(tag, "a");
+			tag.put("href", "#");
+		}
+		else
+		{
+			disableLink(tag);
+		}
+	}
+	
+	/**
+	 * Final implementation of the Button's onSubmit. AjaxSubmitLinks have
+	 * there own onSubmit which is called.
+	 * 
+	 * @see wicket.markup.html.form.Button#onSubmit()
+	 */
+	public final void onSubmit()
+	{
 	}
 
 	/**

Added: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/AbstractSubmitLink.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/AbstractSubmitLink.java?view=auto&rev=522132
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/AbstractSubmitLink.java (added)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/AbstractSubmitLink.java Sat Mar 24 17:31:44 2007
@@ -0,0 +1,177 @@
+/*
+ * 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.
+ */
+package wicket.markup.html.form;
+
+import wicket.Component;
+import wicket.Page;
+import wicket.markup.html.link.AbstractLink;
+import wicket.model.IModel;
+import wicket.util.string.PrependingStringBuffer;
+import wicket.version.undo.Change;
+
+/**
+ * Abstract class for links that are capable of submitting a form.
+ * 
+ * @author Matej Knopp
+ */
+public abstract class AbstractSubmitLink extends AbstractLink
+		implements
+			IFormSubmittingComponent
+{
+	/**
+	 * Target form or null if the form is parent of the link.
+	 */
+	private Form form;
+
+	/**
+	 * If false, all standard processing like validating and model updating is
+	 * skipped.
+	 */
+	private boolean defaultFormProcessing = true;
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 * @param model
+	 */
+	public AbstractSubmitLink(String id, IModel model)
+	{
+		super(id, model);
+	}
+
+	/**
+	 * 
+	 * Construct.
+	 * 
+	 * @param id
+	 */
+	public AbstractSubmitLink(String id)
+	{
+		super(id);
+	}
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 * @param model
+	 * @param form
+	 */
+	public AbstractSubmitLink(String id, IModel model, Form form)
+	{
+		super(id, model);
+		this.form = form;
+	}
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 * @param form
+	 */
+	public AbstractSubmitLink(String id, Form form)
+	{
+		super(id);
+		this.form = form;
+	}
+
+	/**
+	 * Sets the defaultFormProcessing property. When false (default is true),
+	 * all validation and formupdating is bypassed and the onSubmit method of
+	 * that button is called directly, and the onSubmit method of the parent
+	 * form is not called. A common use for this is to create a cancel button.
+	 * 
+	 * TODO: This is a copy & paste from Button
+	 * 
+	 * @param defaultFormProcessing
+	 *            defaultFormProcessing
+	 * @return This
+	 */
+	public final AbstractSubmitLink setDefaultFormProcessing(boolean defaultFormProcessing)
+	{
+		if (this.defaultFormProcessing != defaultFormProcessing)
+		{
+			addStateChange(new Change()
+			{
+				private static final long serialVersionUID = 1L;
+
+				boolean formerValue = AbstractSubmitLink.this.defaultFormProcessing;
+
+				public void undo()
+				{
+					AbstractSubmitLink.this.defaultFormProcessing = formerValue;
+				}
+
+				public String toString()
+				{
+					return "DefaultFormProcessingChange[component: " + getPath()
+							+ ", default processing: " + formerValue + "]";
+				}
+			});
+		}
+
+		this.defaultFormProcessing = defaultFormProcessing;
+		return this;
+	}
+
+	/**
+	 * @see wicket.markup.html.form.IFormSubmittingComponent#getDefaultFormProcessing()
+	 */
+	public boolean getDefaultFormProcessing()
+	{
+		return defaultFormProcessing;
+	}
+
+	/**
+	 * @see wicket.markup.html.form.IFormSubmittingComponent#getForm()
+	 */
+	public Form getForm()
+	{
+		if (this.form != null)
+		{
+			return this.form;
+		}
+		else
+		{
+			return (Form)findParent(Form.class);
+		}
+	}
+
+	/**
+	 * @see wicket.markup.html.form.IFormSubmittingComponent#getInputName()
+	 */
+	public String getInputName()
+	{
+		// TODO: This is a copy & paste from the FormComponent class. 
+		String id = getId();
+		final PrependingStringBuffer inputName = new PrependingStringBuffer(id.length());
+		Component c = this;
+		while (true)
+		{
+			inputName.prepend(id);
+			c = c.getParent();
+			if (c == null || (c instanceof Form && ((Form)c).isRootForm()) || c instanceof Page)
+			{
+				break;
+			}
+			inputName.prepend(Component.PATH_SEPARATOR);
+			id = c.getId();
+		}
+		return inputName.toString();
+	}
+}

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/SubmitLink.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/SubmitLink.java?view=diff&rev=522132&r1=522131&r2=522132
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/SubmitLink.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/SubmitLink.java Sat Mar 24 17:31:44 2007
@@ -17,7 +17,6 @@
 package wicket.markup.html.form;
 
 import wicket.markup.ComponentTag;
-import wicket.markup.html.link.ILinkListener;
 import wicket.model.IModel;
 
 /**
@@ -66,12 +65,10 @@
  * @author Igor Vaynberg (ivaynberg)
  * @author Eelco Hillenius
  */
-public class SubmitLink extends Button
+public abstract class SubmitLink extends AbstractSubmitLink
 {
 	private static final long serialVersionUID = 1L;
 
-	private Form form;
-
 	/**
 	 * With this constructor the SubmitLink must be inside a Form.
 	 * 
@@ -100,8 +97,7 @@
 	 */
 	public SubmitLink(String id, Form form)
 	{
-		super(id);
-		this.form = form;
+		super(id, form);
 	}
 
 
@@ -139,22 +135,7 @@
 	 */
 	public SubmitLink(String id, IModel model, Form form)
 	{
-		super(id, model);
-		this.form = form;
-	}
-
-	/**
-	 * @return the Form for which this submit link submits. Null if there is no
-	 *         form.
-	 */
-	public final Form getForm()
-	{
-		if (form == null)
-		{
-			// Look for parent form
-			form = (Form)findParent(Form.class);
-		}
-		return form;
+		super(id, model, form);
 	}
 
 	/**
@@ -175,22 +156,9 @@
 	protected void onComponentTag(ComponentTag tag)
 	{
 		// If we're disabled
-		if (!isEnabled())
+		if (!isLinkEnabled())
 		{
-			// if the tag is an anchor proper
-			if (tag.getName().equalsIgnoreCase("a"))
-			{
-				// Change anchor link to span tag
-				tag.setName("span");
-
-				// Remove any href from the old link
-				tag.remove("href");
-			}
-			else
-			{
-				// Remove any onclick design time code
-				tag.remove("onclick");
-			}
+			disableLink(tag);
 		}
 		else
 		{
@@ -215,36 +183,44 @@
 	}
 
 	/**
-	 * The javascript which trigges this link
+	 * The javascript which trigges this link.
+	 * 
+	 * TODO: This is a copy & paste from Button
 	 * 
 	 * @return The javascript
 	 */
-	private String getTriggerJavaScript()
+	protected final String getTriggerJavaScript()
 	{
-		Form form = getForm();
-		if (form != null)
-		{
+		if (getForm() != null) {
+			// find the root form - the one we are really going to submit
+			Form root = getForm().getRootForm();
 			StringBuffer sb = new StringBuffer(100);
 			sb.append("var e=document.getElementById('");
-			sb.append(form.getHiddenFieldId());
+			sb.append(root.getHiddenFieldId());
 			sb.append("'); e.name=\'");
 			sb.append(getInputName());
-			sb.append("'; e.value='x';");
+			sb.append("'; e.value='x';");			
 			sb.append("var f=document.getElementById('");
-			sb.append(form.getJavascriptId());
+			sb.append(root.getMarkupId());
 			sb.append("');");
 			if (shouldInvokeJavascriptFormOnsubmit())
 			{
-				sb.append("if (f.onsubmit != undefined) { if (f.onsubmit()==false) return false; }");
+				if (getForm() != root)
+				{
+					sb.append("var ff=document.getElementById('");
+					sb.append(getForm().getMarkupId());
+					sb.append("');");
+				}
+				else
+				{
+					sb.append("var ff=f;");
+				}
+				sb.append("if (ff.onsubmit != undefined) { if (ff.onsubmit()==false) return false; }");
 			}
 			sb.append("f.submit();e.value='';e.name='';return false;");
 			return sb.toString();
+		} else {
+			return null;
 		}
-		else
-		{
-			// if we didn't find a parent form, fall back on normal link
-			// behavior
-			return "window.location.href='" + urlFor(ILinkListener.INTERFACE).toString() + "';";
-		}
-	}
+	}	
 }

Added: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/link/AbstractLink.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/link/AbstractLink.java?view=auto&rev=522132
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/link/AbstractLink.java (added)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/link/AbstractLink.java Sat Mar 24 17:31:44 2007
@@ -0,0 +1,198 @@
+/*
+ * 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.
+ */
+package wicket.markup.html.link;
+
+import wicket.Application;
+import wicket.markup.ComponentTag;
+import wicket.markup.MarkupStream;
+import wicket.markup.html.WebMarkupContainer;
+import wicket.model.IModel;
+
+/**
+ * Base class that that contains functionality for rendering disabled links.
+ * 
+ * @author Matej Knopp
+ */
+public abstract class AbstractLink extends WebMarkupContainer
+{
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 * @param model
+	 */
+	public AbstractLink(String id, IModel model)
+	{
+		super(id, model);
+	}
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 */
+	public AbstractLink(String id)
+	{
+		super(id);
+	}
+
+	/**
+	 * Simple insertion string to allow disabled links to look like <i>Disabled
+	 * link </i>.
+	 */
+	private String beforeDisabledLink;
+
+	/**
+	 * Simple insertion string to allow disabled links to look like <i>Disabled
+	 * link </i>.
+	 */
+	private String afterDisabledLink;
+
+
+	/**
+	 * Sets the insertion string to allow disabled links to look like
+	 * <i>Disabled link </i>.
+	 * 
+	 * @param afterDisabledLink
+	 *            The insertion string
+	 */
+	public void setAfterDisabledLink(final String afterDisabledLink)
+	{
+		if (afterDisabledLink == null)
+		{
+			throw new IllegalArgumentException(
+					"Value cannot be null.  For no text, specify an empty String instead.");
+		}
+		this.afterDisabledLink = afterDisabledLink;
+	}
+
+	/**
+	 * Gets the insertion string to allow disabled links to look like
+	 * <i>Disabled link </i>.
+	 * 
+	 * @return The insertion string
+	 */
+	public String getAfterDisabledLink()
+	{
+		return afterDisabledLink;
+	}
+
+	/**
+	 * Sets the insertion string to allow disabled links to look like
+	 * <i>Disabled link </i>.
+	 * 
+	 * @param beforeDisabledLink
+	 *            The insertion string
+	 */
+	public void setBeforeDisabledLink(final String beforeDisabledLink)
+	{
+		if (beforeDisabledLink == null)
+		{
+			throw new IllegalArgumentException(
+					"Value cannot be null.  For no text, specify an empty String instead.");
+		}
+		this.beforeDisabledLink = beforeDisabledLink;
+	}
+
+	protected void onAttach()
+	{
+		super.onAttach();
+
+		// Set default for before/after link text
+		if (beforeDisabledLink == null)
+		{
+			final Application app = getApplication();
+			beforeDisabledLink = app.getMarkupSettings().getDefaultBeforeDisabledLink();
+			afterDisabledLink = app.getMarkupSettings().getDefaultAfterDisabledLink();
+		}
+	}
+
+	/**
+	 * Gets the insertion string to allow disabled links to look like
+	 * <i>Disabled link </i>.
+	 * 
+	 * @return The insertion string
+	 */
+	public String getBeforeDisabledLink()
+	{
+		return beforeDisabledLink;
+	}
+
+	/**
+	 * Helper methods that both checks whether the link is enabled and whether
+	 * the action ENABLE is allowed.
+	 * 
+	 * @return whether the link should be rendered as enabled
+	 */
+	protected final boolean isLinkEnabled()
+	{
+		return isEnabled() && isEnableAllowed();
+	}
+
+	/**
+	 * Renders this link's body.
+	 * 
+	 * @param markupStream
+	 *            the markup stream
+	 * @param openTag
+	 *            the open part of this tag
+	 * @see wicket.Component#onComponentTagBody(MarkupStream, ComponentTag)
+	 */
+	protected final void onComponentTagBody(final MarkupStream markupStream,
+			final ComponentTag openTag)
+	{
+		// Draw anything before the body?
+		if (!isLinkEnabled() && getBeforeDisabledLink() != null)
+		{
+			getResponse().write(getBeforeDisabledLink());
+		}
+
+		// Render the body of the link
+		renderComponentTagBody(markupStream, openTag);
+
+		// Draw anything after the body?
+		if (!isLinkEnabled() && getAfterDisabledLink() != null)
+		{
+			getResponse().write(getAfterDisabledLink());
+		}
+	}
+
+	/**
+	 * Alters the tag so that the link renders as disabled.
+	 * 
+	 * This method is meant to be called from
+	 * {@link #onComponentTag(ComponentTag)} method of the derived class.
+	 * 
+	 * @param tag
+	 */
+	protected void disableLink(final ComponentTag tag)
+	{
+		// if the tag is an anchor proper
+		if (tag.getName().equalsIgnoreCase("a") || tag.getName().equalsIgnoreCase("link")
+				|| tag.getName().equalsIgnoreCase("area"))
+		{
+			// Change anchor link to span tag
+			tag.setName("span");
+
+			// Remove any href from the old link
+			tag.remove("href");
+
+			tag.remove("onclick");
+		}
+	}
+}

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/link/Link.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/link/Link.java?view=diff&rev=522132&r1=522131&r2=522132
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/link/Link.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/link/Link.java Sat Mar 24 17:31:44 2007
@@ -16,15 +16,12 @@
  */
 package wicket.markup.html.link;
 
-import wicket.Application;
 import wicket.Component;
 import wicket.IPageMap;
 import wicket.Page;
 import wicket.RequestCycle;
 import wicket.WicketRuntimeException;
 import wicket.markup.ComponentTag;
-import wicket.markup.MarkupStream;
-import wicket.markup.html.WebMarkupContainer;
 import wicket.model.IModel;
 import wicket.util.string.Strings;
 import wicket.version.undo.Change;
@@ -77,7 +74,7 @@
  * @author Jonathan Locke
  * @author Eelco Hillenius
  */
-public abstract class Link extends WebMarkupContainer implements ILinkListener
+public abstract class Link extends AbstractLink implements ILinkListener
 {
 	/** Change record for when an anchor is changed. */
 	private final class AnchorChange extends Change
@@ -106,12 +103,6 @@
 	private static final long serialVersionUID = 1L;
 
 	/**
-	 * Simple insertion string to allow disabled links to look like <i>Disabled
-	 * link </i>.
-	 */
-	private String afterDisabledLink;
-
-	/**
 	 * An anchor (form 'http://server/app/etc#someAnchor') will be appended to
 	 * the link so that after this link executes, it will jump to the provided
 	 * anchor component's position. The provided anchor must either have the
@@ -128,12 +119,6 @@
 	private boolean autoEnable = false;
 
 	/**
-	 * Simple insertion string to allow disabled links to look like <i>Disabled
-	 * link </i>.
-	 */
-	private String beforeDisabledLink;
-
-	/**
 	 * The popup specification. If not-null, a javascript on-click event handler
 	 * will be generated that opens a new window using the popup properties.
 	 */
@@ -156,17 +141,6 @@
 	}
 
 	/**
-	 * Gets the insertion string to allow disabled links to look like
-	 * <i>Disabled link </i>.
-	 * 
-	 * @return The insertion string
-	 */
-	public String getAfterDisabledLink()
-	{
-		return afterDisabledLink;
-	}
-
-	/**
 	 * Gets any anchor component.
 	 * 
 	 * @return Any anchor component to jump to, might be null
@@ -189,17 +163,6 @@
 	}
 
 	/**
-	 * Gets the insertion string to allow disabled links to look like
-	 * <i>Disabled link </i>.
-	 * 
-	 * @return The insertion string
-	 */
-	public String getBeforeDisabledLink()
-	{
-		return beforeDisabledLink;
-	}
-
-	/**
 	 * Gets the popup specification. If not-null, a javascript on-click event
 	 * handler will be generated that opens a new window using the popup
 	 * properties.
@@ -259,22 +222,6 @@
 		onClick();
 	}
 
-	/**
-	 * Sets the insertion string to allow disabled links to look like
-	 * <i>Disabled link </i>.
-	 * 
-	 * @param afterDisabledLink
-	 *            The insertion string
-	 */
-	public void setAfterDisabledLink(final String afterDisabledLink)
-	{
-		if (afterDisabledLink == null)
-		{
-			throw new IllegalArgumentException(
-					"Value cannot be null.  For no text, specify an empty String instead.");
-		}
-		this.afterDisabledLink = afterDisabledLink;
-	}
 
 	/**
 	 * Sets an anchor component. An anchor (form
@@ -310,23 +257,6 @@
 	}
 
 	/**
-	 * Sets the insertion string to allow disabled links to look like
-	 * <i>Disabled link </i>.
-	 * 
-	 * @param beforeDisabledLink
-	 *            The insertion string
-	 */
-	public void setBeforeDisabledLink(final String beforeDisabledLink)
-	{
-		if (beforeDisabledLink == null)
-		{
-			throw new IllegalArgumentException(
-					"Value cannot be null.  For no text, specify an empty String instead.");
-		}
-		this.beforeDisabledLink = beforeDisabledLink;
-	}
-
-	/**
 	 * Sets the popup specification. If not-null, a javascript on-click event
 	 * handler will be generated that opens a new window using the popup
 	 * properties.
@@ -448,22 +378,6 @@
 	}
 
 	/**
-	 * @see wicket.Component#onAttach()
-	 */
-	protected void onAttach()
-	{
-		super.onAttach();
-
-		// Set default for before/after link text
-		if (beforeDisabledLink == null)
-		{
-			final Application app = getApplication();
-			beforeDisabledLink = app.getMarkupSettings().getDefaultBeforeDisabledLink();
-			afterDisabledLink = app.getMarkupSettings().getDefaultAfterDisabledLink();
-		}
-	}
-
-	/**
 	 * Whether this link refers to the given page.
 	 * 
 	 * @param page
@@ -496,28 +410,7 @@
 		// If we're disabled
 		if (!isEnabled())
 		{
-			// if the tag is an anchor proper
-			if (tag.getName().equalsIgnoreCase("a") || tag.getName().equalsIgnoreCase("link")
-					|| tag.getName().equalsIgnoreCase("area"))
-			{
-				// Change anchor link to span tag
-				tag.setName("span");
-
-				// Remove any href from the old link
-				tag.remove("href");
-
-				// if it generates a popupscript, remove the design time JS
-				// handler
-				if (popupSettings != null)
-				{
-					tag.remove("onclick");
-				}
-			}
-			else
-			{
-				// Remove any onclick design time code
-				tag.remove("onclick");
-			}
+			disableLink(tag);
 		}
 		else
 		{
@@ -556,50 +449,24 @@
 					tag.put("onclick", "window.location.href='" + url + "';return false;");
 				}
 			}
-		}
-
-		// If the subclass specified javascript, use that
-		final CharSequence onClickJavaScript = getOnClickScript(url);
-		if (onClickJavaScript != null)
-		{
-			tag.put("onclick", onClickJavaScript);
-		}
-
-		if (popupSettings != null)
-		{
-			IPageMap popupPageMap = popupSettings.getPageMap(this);
-			if (popupPageMap != null)
+			
+			// If the subclass specified javascript, use that
+			final CharSequence onClickJavaScript = getOnClickScript(url);
+			if (onClickJavaScript != null)
 			{
-				tag.put("target", popupPageMap.getName());
+				tag.put("onclick", onClickJavaScript);
 			}
-		}
-	}
 
-	/**
-	 * Renders this link's body.
-	 * 
-	 * @param markupStream
-	 *            the markup stream
-	 * @param openTag
-	 *            the open part of this tag
-	 * @see wicket.Component#onComponentTagBody(MarkupStream, ComponentTag)
-	 */
-	protected final void onComponentTagBody(final MarkupStream markupStream,
-			final ComponentTag openTag)
-	{
-		// Draw anything before the body?
-		if (!isEnabled() && getBeforeDisabledLink() != null)
-		{
-			getResponse().write(getBeforeDisabledLink());
+			if (popupSettings != null)
+			{
+				IPageMap popupPageMap = popupSettings.getPageMap(this);
+				if (popupPageMap != null)
+				{
+					tag.put("target", popupPageMap.getName());
+				}
+			}
 		}
 
-		// Render the body of the link
-		renderComponentTagBody(markupStream, openTag);
-
-		// Draw anything after the body?
-		if (!isEnabled() && getAfterDisabledLink() != null)
-		{
-			getResponse().write(getAfterDisabledLink());
-		}
 	}
+
 }