001: // WebOnSwing - Web Application Framework
002: //Copyright (C) 2004 Fernando Damian Petrola
003: //
004: //This library is free software; you can redistribute it and/or
005: //modify it under the terms of the GNU Lesser General Public
006: //License as published by the Free Software Foundation; either
007: //version 2.1 of the License, or (at your option) any later version.
008: //
009: //This library is distributed in the hope that it will be useful,
010: //but WITHOUT ANY WARRANTY; without even the implied warranty of
011: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: //Lesser General Public License for more details.
013: //
014: //You should have received a copy of the GNU Lesser General Public
015: //License along with this library; if not, write to the Free Software
016: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:
018: package net.ar.webonswing.swing.components.validators.contributors;
019:
020: import java.util.*;
021:
022: import javax.swing.*;
023:
024: import net.ar.webonswing.*;
025: import net.ar.webonswing.helpers.*;
026: import net.ar.webonswing.managers.script.*;
027: import net.ar.webonswing.remote.*;
028: import net.ar.webonswing.render.markup.*;
029: import net.ar.webonswing.swing.components.validators.*;
030: import net.ar.webonswing.ui.*;
031: import net.ar.webonswing.wrapping.*;
032:
033: public class ValidatorUIContributor extends
034: AbstractSwingComponentUIContributor {
035: public void doRenderingContribution(
036: RenderingContributionContainer theContribManager) {
037: JValidator theValidator = (JValidator) getJComponent();
038:
039: RemoteHelper.removeToolTipListeners(theValidator);
040: Tag theTag = new Tag("span");
041: StringBuffer theScript = new StringBuffer();
042:
043: if (theValidator.isEnabled()) {
044: theTag.addTextToContainer(
045: RemoteHelper.str2web(theValidator.getText()))
046: .addAttribute("id", theComponent.getName());
047:
048: for (int i = 0; i < theComponent.getChildCount(); i++) {
049: VisualComponent child = theComponent.getChildAt(i);
050: theContribManager.getContainerRenderer().render(child);
051: theScript.append(theContribManager
052: .getComponentInitScripts(child)[0]);
053: }
054:
055: if (theValidator.isRemoteValidation())
056: theScript.append(getScript(theValidator));
057: }
058:
059: theContribManager.doContribution(theComponent, theTag, theTag,
060: theScript.toString());
061: }
062:
063: protected String getScript(JValidator aValidator) {
064: JComponent componentToValidate = aValidator
065: .getComponentToValidate();
066: String componentToValidateName = componentToValidate != null ? WosFramework
067: .getInstance().getHierarchyWrapper()
068: .getComponentWrapper(componentToValidate).getName()
069: : "";
070: return getJsCreationScript(new Object[] {
071: theComponent.getName(), componentToValidateName,
072: aValidator.getOwnMessage(),
073: aValidator.getGroupMessage(),
074: aValidator.isGrouped() + "",
075: getShootersNames(aValidator).toArray() });
076: }
077:
078: protected String getJsCreationScript(Object[] parameters) {
079: return RemoteHelper.createJsInstance(theComponent.getName(),
080: getJsValidatorClassName(), parameters);
081: }
082:
083: protected String getJsValidatorClassName() {
084: return WosHelper.getNoPackageClassName(getJComponent());
085: }
086:
087: public void doScriptContribution(
088: ScriptContributionContainer aContributionManager) {
089: aContributionManager.addInclude(WosFramework.getInstance()
090: .getCompleteResourcePath()
091: + "/js/validators/JValidator.js");
092:
093: JValidator theValidator = (JValidator) getJComponent();
094:
095: if (theValidator.isRemoteValidation())
096: aContributionManager.addInclude(WosFramework.getInstance()
097: .getCompleteResourcePath()
098: + "/js/validators/"
099: + getJsValidatorClassName()
100: + ".js");
101: }
102:
103: protected Vector getShootersNames(JValidator aValidator) {
104: Vector result = new Vector();
105: for (Iterator i = aValidator.getValidationShooters().iterator(); i
106: .hasNext();)
107: result.add(WosFramework.getInstance().getHierarchyWrapper()
108: .getComponentWrapper(i.next()).getName());
109: return result;
110: }
111: }
|