KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > util > gui > propedit > UniqueFilter


1 package net.suberic.util.gui.propedit;
2 import net.suberic.util.VariableBundle;
3
4 import java.util.List JavaDoc;
5
6 /**
7  * A PropertyEditorListener which disallows entries which already exist
8  * for a particular property.
9  *
10  */

11 public class UniqueFilter extends PropertyEditorAdapter implements ConfigurablePropertyEditorListener {
12   String JavaDoc parentProperty;
13   PropertyEditorManager manager;
14
15   /**
16    * Configures this filter from the given key.
17    */

18   public void configureListener(String JavaDoc key, String JavaDoc property, String JavaDoc propertyBase, String JavaDoc editorTemplate, PropertyEditorManager pManager) {
19
20     String JavaDoc parentProp = pManager.getProperty(key + ".listProperty", "");
21     if (parentProp.length() > 0) {
22       if (parentProp.startsWith(".")) {
23         parentProperty=propertyBase + parentProp;
24       } else {
25         parentProperty=parentProp;
26       }
27     }
28
29     manager = pManager;
30
31   }
32
33   /**
34    * Called when a property is about to change. If the value is not ok
35    * with the listener, a PropertyValueVetoException should be thrown.
36    *
37    * In this case, if the entry already exists in the parentProperty we
38    * throw an Exception.
39    */

40   public void propertyChanging(PropertyEditorUI source, String JavaDoc property, String JavaDoc newValue) throws PropertyValueVetoException {
41     String JavaDoc parentValue = manager.getCurrentProperty(parentProperty, "");
42     List JavaDoc<String JavaDoc> parentValueList = VariableBundle.convertToList(parentValue);
43     if (parentValueList.contains(newValue)) {
44       throw new PropertyValueVetoException(property, newValue, manager.formatMessage("Message.uniquFilter.notUnique", newValue, parentProperty), this);
45     }
46   }
47
48 }
49
Popular Tags