KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > j2ee > ui > CustomizerDataSupport


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  * CustomizerDataSupport.java
21  *
22  * Created on March 23, 2006, 10:16 PM
23  *
24  */

25
26 package org.netbeans.modules.j2ee.sun.ide.j2ee.ui;
27
28 import java.awt.event.ItemEvent JavaDoc;
29 import java.awt.event.ItemListener JavaDoc;
30 import javax.swing.event.ChangeListener JavaDoc;
31 import javax.swing.event.DocumentEvent JavaDoc;
32 import javax.swing.event.DocumentListener JavaDoc;
33 import javax.swing.event.ListDataEvent JavaDoc;
34 import javax.swing.event.ListDataListener JavaDoc;
35 import org.netbeans.modules.j2ee.sun.ide.j2ee.DeploymentManagerProperties;
36
37 /**
38  *
39  * @author sherold
40  */

41 public class CustomizerDataSupport {
42     
43     private final DeploymentManagerProperties dmp;
44     
45     // models
46
private CustomizerSupport.PathModel sourceModel;
47     private CustomizerSupport.PathModel classModel;
48     private CustomizerSupport.PathModel javadocModel;
49     
50     // model dirty flags
51
private boolean sourceModelFlag;
52     private boolean javadocModelFlag;
53     private boolean serverPortModelFlag;
54     
55     /**
56      * Creates a new instance of CustomizerDataSupport
57      */

58     public CustomizerDataSupport(DeploymentManagerProperties dmp) {
59         this.dmp = dmp;
60         init();
61     }
62     
63     /** Initialize the customizer models. */
64     private void init() {
65         // classModel
66
classModel = new CustomizerSupport.PathModel(dmp.getClasses());
67         
68         // sourceModel
69
sourceModel = new CustomizerSupport.PathModel(dmp.getSources());
70         sourceModel.addListDataListener(new ModelChangeAdapter() {
71             public void modelChanged() {
72                 sourceModelFlag = true;
73                 store(); // This is just temporary until the server manager has OK and Cancel buttons
74
}
75         });
76         
77         // javadocModel
78
javadocModel = new CustomizerSupport.PathModel(dmp.getJavadocs());
79         javadocModel.addListDataListener(new ModelChangeAdapter() {
80             public void modelChanged() {
81                 javadocModelFlag = true;
82                 store(); // This is just temporary until the server manager has OK and Cancel buttons
83
}
84         });
85     }
86     
87     public CustomizerSupport.PathModel getClassModel() {
88         return classModel;
89     }
90     
91     public CustomizerSupport.PathModel getSourceModel() {
92         return sourceModel;
93     }
94     
95     public CustomizerSupport.PathModel getJavadocsModel() {
96         return javadocModel;
97     }
98     
99     // private helper methods -------------------------------------------------
100

101     /** Save all changes */
102     private void store() {
103         if (sourceModelFlag) {
104             dmp.setSources(sourceModel.getData());
105             sourceModelFlag = false;
106         }
107         
108         if (javadocModelFlag) {
109             dmp.setJavadocs(javadocModel.getData());
110             javadocModelFlag = false;
111         }
112     }
113     
114     // private helper class ---------------------------------------------------
115

116     /**
117      * Adapter that implements several listeners, which is useful for dirty model
118      * monitoring.
119      */

120     private abstract class ModelChangeAdapter implements ListDataListener JavaDoc,
121             DocumentListener JavaDoc, ItemListener JavaDoc, ChangeListener JavaDoc {
122         
123         public abstract void modelChanged();
124         
125         public void contentsChanged(ListDataEvent JavaDoc e) {
126             modelChanged();
127         }
128
129         public void intervalAdded(ListDataEvent JavaDoc e) {
130             modelChanged();
131         }
132
133         public void intervalRemoved(ListDataEvent JavaDoc e) {
134             modelChanged();
135         }
136
137         public void changedUpdate(DocumentEvent JavaDoc e) {
138             modelChanged();
139         }
140
141         public void removeUpdate(DocumentEvent JavaDoc e) {
142             modelChanged();
143         }
144
145         public void insertUpdate(DocumentEvent JavaDoc e) {
146             modelChanged();
147         }
148
149         public void itemStateChanged(ItemEvent JavaDoc e) {
150             modelChanged();
151         }
152
153         public void stateChanged(javax.swing.event.ChangeEvent JavaDoc e) {
154             modelChanged();
155         }
156     }
157 }
158
Popular Tags