Skip to main content
summaryrefslogtreecommitdiffstats
blob: b4028175cca71391624c7cb8ed7169df10d07347 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*******************************************************************************
 * Copyright (c) 2006 Oracle Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Gerry Kessler/Oracle - initial API and implementation
 *    
 ********************************************************************************/
package org.eclipse.jst.jsf.taglibprocessing.attributevalues;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jst.jsf.core.jsfappconfig.JSFAppConfigManager;
import org.eclipse.jst.jsf.facesconfig.emf.ValidatorType;
import org.eclipse.jst.jsf.metadataprocessors.features.PossibleValue;
import org.eclipse.osgi.util.NLS;

/**
 * ValidatorID attribute feature
 * 
 * <p><b>Provisional API - subject to change</b></p>
 *
 */
public class FacesConfigValidatorIDFeatures extends FacesConfigIdentifierFeatures {

	/**
	 * Faces validator classname
	 */
	protected static final String VALIDATOR = "javax.faces.validator.Validator"; //$NON-NLS-1$
	/**
	 * Imagename to use when displaying validator
	 */
	protected static final String IMAGE_NAME = "/icons/full/obj16/FacesConfig_Validator.gif"; //$NON-NLS-1$
	
	/* (non-Javadoc)
	 * @see org.eclipse.jst.jsf.taglibprocessing.attributevalues.FacesConfigIdentifierFeatures#getReturnType()
	 */
	protected String getReturnType(){ return VALIDATOR;}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jst.jsf.taglibprocessing.attributevalues.FacesConfigIdentifierFeatures#getElements(org.eclipse.jst.jsf.core.jsfappconfig.JSFAppConfigManager)
	 */
	protected List getElements(JSFAppConfigManager mgr) {
		if (mgr != null)
			return mgr.getValidators();
		return new ArrayList(0);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jst.jsf.taglibprocessing.attributevalues.FacesConfigIdentifierFeatures#getPossibleValueProposals(java.util.List)
	 */
	protected List getPossibleValueProposals(List elements) {
		List ret = new ArrayList();
		Collections.sort(elements, new ValidatorSorter());
		for (Iterator it = elements.iterator();it.hasNext();){
			ValidatorType obj = (ValidatorType)it.next();
			if (obj.getValidatorId() != null && obj.getValidatorId().getTextContent() != null){
				PossibleValue pv = createProposal(obj.getValidatorId().getTextContent(), obj.getDisplayName(), obj.getDescription());
				if (pv != null){
					pv.setIcon(getImage());
					ret.add(pv);
				}
			}
		}
		return ret;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jst.jsf.taglibprocessing.attributevalues.FacesConfigIdentifierFeatures#getImageName()
	 */
	protected String getImageName() {		
		return IMAGE_NAME;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jst.jsf.taglibprocessing.attributevalues.FacesConfigIdentifierFeatures#getMyValidationMessage(java.lang.String)
	 */
	protected String getMyValidationMessage(String value) {		
		if (value == null || value.trim().equals("")) //$NON-NLS-1$
			return Messages.FacesConfigValidatorIDFeatures_validatorid_empty;
		
		return NLS.bind(Messages.FacesConfigIdentifierType_invalid_validator_id, new String[]{singleQuote(value)});
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jst.jsf.taglibprocessing.attributevalues.FacesConfigIdentifierFeatures#getElementIDs(org.eclipse.jst.jsf.core.jsfappconfig.JSFAppConfigManager)
	 */
	protected List getElementIDs(JSFAppConfigManager mgr) {
		List elements = getElements(mgr);
		List ret = new ArrayList(elements.size());		
		for (Iterator it = elements.iterator();it.hasNext();){
			ValidatorType aType = (ValidatorType)it.next();
			if (aType.getValidatorId() != null && aType.getValidatorId().getTextContent() != null){
				String id = aType.getValidatorId().getTextContent();
				if (id != null)
					ret.add(id.trim());
			}
		}
		return ret;
	}
	
	/**
	 * Validator id sorter - incomplete
	 */
	class ValidatorSorter implements Comparator {

		public int compare(Object o1, Object o2) {		
			//TODO
			return 0;

		}
		
	}
}

Back to the top