01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * 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-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19: package org.netbeans.modules.soa.ui.form;
20:
21: import java.beans.PropertyEditor;
22: import javax.swing.JPanel;
23: import org.netbeans.modules.soa.ui.form.valid.DefaultValidStateManager;
24: import org.netbeans.modules.soa.ui.form.valid.ValidStateManager;
25: import org.netbeans.modules.soa.ui.form.valid.ValidStateManager.ValidStateListener;
26: import org.netbeans.modules.soa.ui.form.valid.Validator;
27: import org.netbeans.modules.soa.ui.form.valid.Validator.Severity;
28: import org.openide.explorer.propertysheet.PropertyEnv;
29:
30: /**
31: * This class is intended to be used as a base class for different
32: * property customizer dialogs, which want to provide a validation facility.
33: *
34: * @author nk160297
35: */
36: public abstract class ValidablePropertyCustomizer extends JPanel
37: implements Validator.Provider, ValidStateManager.Provider,
38: ReusablePropertyCustomizer {
39:
40: private DefaultValidStateManager validationManager;
41: protected Validator myValidator;
42: protected PropertyEnv myPropertyEnv;
43:
44: public ValidablePropertyCustomizer() {
45: validationManager = new DefaultValidStateManager();
46: validationManager
47: .addValidStateListener(new ValidStateListener() {
48: public void stateChanged(ValidStateManager source,
49: boolean isValid) {
50: if (myPropertyEnv != null) {
51: if (isValid) {
52: myPropertyEnv
53: .setState(PropertyEnv.STATE_NEEDS_VALIDATION);
54: } else {
55: myPropertyEnv
56: .setState(PropertyEnv.STATE_INVALID);
57: }
58: }
59: }
60: });
61: }
62:
63: public synchronized void init(PropertyEnv propertyEnv,
64: PropertyEditor propertyEditor) {
65: myPropertyEnv = propertyEnv;
66: }
67:
68: public void revalidate(boolean isFast) {
69: ValidStateManager vsm = getValidStateManager(isFast);
70: Validator validator = getValidator();
71: // vsm.clearReasons();
72: validator.clearReasons();
73: validator.doValidation(isFast);
74: vsm.processValidationResults(validator);
75: }
76:
77: public ValidStateManager getValidStateManager(boolean isFast) {
78: return validationManager;
79: }
80:
81: public synchronized Validator getValidator() {
82: if (myValidator == null) {
83: myValidator = createValidator();
84: }
85: return myValidator;
86: }
87:
88: public abstract Validator createValidator();
89:
90: }
|