1 19 20 package org.netbeans.modules.j2ee.common.method.impl; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import org.openide.NotifyDescriptor; 25 import org.openide.util.NbBundle; 26 import org.openide.util.Utilities; 27 28 32 public final class ValidatingPropertyChangeListener implements PropertyChangeListener { 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 event) { 45 validate(); 46 } 47 48 protected boolean validate() { 50 String name = panel.getMethodName(); 52 if (!Utilities.isJavaIdentifier(name)) { 53 setError(NbBundle.getMessage(ValidatingPropertyChangeListener.class, "ERROR_nameNonJavaIdentifier")); 54 return false; 55 } 56 String returnType = panel.getReturnType(); 58 if ("".equals(returnType)) { 59 setError(NbBundle.getMessage(ValidatingPropertyChangeListener.class, "ERROR_returnTypeInvalid")); 60 return false; 61 } 62 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 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 |