KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > common > method > impl > ValidatingPropertyChangeListener


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.common.method.impl;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import org.openide.NotifyDescriptor;
25 import org.openide.util.NbBundle;
26 import org.openide.util.Utilities;
27
28 /**
29  *
30  * @author Martin Adamek
31  */

32 public final class ValidatingPropertyChangeListener implements PropertyChangeListener JavaDoc {
33     
34     private final MethodCustomizerPanel panel;
35     private final NotifyDescriptor notifyDescriptor;
36     private final boolean checkInterfaces;
37     
38     public ValidatingPropertyChangeListener(MethodCustomizerPanel panel, NotifyDescriptor notifyDescriptor) {
39         this.panel = panel;
40         this.notifyDescriptor = notifyDescriptor;
41         this.checkInterfaces = panel.supportsInterfacesChecking();
42     }
43     
44     public void propertyChange(PropertyChangeEvent JavaDoc event) {
45         validate();
46     }
47     
48     // protected for testing
49
protected boolean validate() {
50         // method name
51
String JavaDoc name = panel.getMethodName();
52         if (!Utilities.isJavaIdentifier(name)) {
53             setError(NbBundle.getMessage(ValidatingPropertyChangeListener.class, "ERROR_nameNonJavaIdentifier"));
54             return false;
55         }
56         // return type
57
String JavaDoc returnType = panel.getReturnType();
58         if ("".equals(returnType)) {
59             setError(NbBundle.getMessage(ValidatingPropertyChangeListener.class, "ERROR_returnTypeInvalid"));
60             return false;
61         }
62         // interfaces
63
if (checkInterfaces) {
64             boolean local = panel.hasLocal();
65             boolean remote = panel.hasRemote();
66             if (!local && !remote) {
67                 setError(NbBundle.getMessage(ValidatingPropertyChangeListener.class, "ERROR_selectSomeInterface"));
68                 return false;
69             }
70         }
71         unsetError();
72         return true;
73     }
74     
75     private void setError(String JavaDoc message) {
76         notifyDescriptor.setValid(false);
77         panel.setError(message);
78     }
79     
80     private void unsetError() {
81         notifyDescriptor.setValid(true);
82         panel.setError("");
83     }
84     
85 }
86
Popular Tags