KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > customizer > OC4JCustomizerDataSupport


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.oc4j.customizer;
21
22 import java.awt.event.ItemEvent JavaDoc;
23 import java.awt.event.ItemListener JavaDoc;
24 import javax.swing.event.ChangeListener JavaDoc;
25 import javax.swing.event.DocumentEvent JavaDoc;
26 import javax.swing.event.DocumentListener JavaDoc;
27 import javax.swing.event.ListDataEvent JavaDoc;
28 import javax.swing.event.ListDataListener JavaDoc;
29 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
30 import org.netbeans.modules.j2ee.oc4j.OC4JDeploymentManager;
31 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginProperties;
32
33 /**
34  * Customizer data support keeps models for all the customizer components,
35  * initializes them, tracks model changes and performs save.
36  *
37  * @author Michal Mocnak
38  */

39 public class OC4JCustomizerDataSupport {
40     
41     private OC4JCustomizerSupport.PathModel classModel;
42     private OC4JCustomizerSupport.PathModel javadocModel;
43     
44     private boolean javadocModelFlag;
45     
46     private OC4JPluginProperties properties;
47     private OC4JDeploymentManager dm;
48     
49     /**
50      * Creates a new instance of CustomizerDataSupport
51      */

52     public OC4JCustomizerDataSupport(OC4JDeploymentManager dm) {
53         this.dm = dm;
54         this.properties = dm.getProperties();
55         init();
56     }
57     
58     /**
59      * Initialize the customizer models
60      */

61     private void init() {
62         // classModel
63
classModel = new OC4JCustomizerSupport.PathModel(properties.getClasses());
64         
65         // javadocModel
66
javadocModel = new OC4JCustomizerSupport.PathModel(properties.getJavadocs());
67         javadocModel.addListDataListener(new ModelChangeAdapter() {
68             public void modelChanged() {
69                 javadocModelFlag = true;
70                 store(); // This is just temporary until the server manager has OK and Cancel buttons
71
}
72         });
73     }
74     
75     public InstanceProperties getInstanceProperties() {
76         return dm.getInstanceProperties();
77     }
78     
79     public OC4JCustomizerSupport.PathModel getClassModel() {
80         return classModel;
81     }
82     
83     public OC4JCustomizerSupport.PathModel getJavadocsModel() {
84         return javadocModel;
85     }
86     
87     /**
88      * Save all changes
89      */

90     private void store() {
91         if (javadocModelFlag) {
92             properties.setJavadocs(javadocModel.getData());
93             javadocModelFlag = false;
94         }
95     }
96     
97     /**
98      * Adapter that implements several listeners, which is useful for dirty model
99      * monitoring.
100      */

101     private abstract class ModelChangeAdapter implements ListDataListener JavaDoc,
102             DocumentListener JavaDoc, ItemListener JavaDoc, ChangeListener JavaDoc {
103         
104         public abstract void modelChanged();
105         
106         public void contentsChanged(ListDataEvent JavaDoc e) {
107             modelChanged();
108         }
109         
110         public void intervalAdded(ListDataEvent JavaDoc e) {
111             modelChanged();
112         }
113         
114         public void intervalRemoved(ListDataEvent JavaDoc e) {
115             modelChanged();
116         }
117         
118         public void changedUpdate(DocumentEvent JavaDoc e) {
119             modelChanged();
120         }
121         
122         public void removeUpdate(DocumentEvent JavaDoc e) {
123             modelChanged();
124         }
125         
126         public void insertUpdate(DocumentEvent JavaDoc e) {
127             modelChanged();
128         }
129         
130         public void itemStateChanged(ItemEvent JavaDoc e) {
131             modelChanged();
132         }
133         
134         public void stateChanged(javax.swing.event.ChangeEvent JavaDoc e) {
135             modelChanged();
136         }
137     }
138 }
Popular Tags