001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.visualweb.project.jsf.ui;
043:
044: import org.netbeans.modules.visualweb.project.jsf.api.JsfProjectUtils;
045: import org.netbeans.modules.visualweb.project.jsf.api.JsfProjectConstants;
046:
047: import java.util.ArrayList;
048: import java.util.Iterator;
049: import java.util.List;
050: import javax.swing.event.ChangeEvent;
051: import javax.swing.event.ChangeListener;
052: import javax.swing.event.DocumentListener;
053: import org.netbeans.api.project.Project;
054: import org.openide.util.NbBundle;
055:
056: /**
057: *
058: * @author Po-Ting Wu
059: */
060: public class PagebeanPackagePanelGUI extends javax.swing.JPanel
061: implements DocumentListener {
062:
063: private Project project;
064: private final List/*<ChangeListener>*/listeners = new ArrayList();
065:
066: /** Creates new form SimpleTargetChooserGUI */
067: public PagebeanPackagePanelGUI(Project project) {
068: this .project = project;
069:
070: initComponents();
071: initValues(project);
072:
073: packageTextField.getDocument().addDocumentListener(this );
074: }
075:
076: public void initValues(Project project) {
077: String packageName = JsfProjectUtils.getProjectProperty(
078: project, JsfProjectConstants.PROP_JSF_PAGEBEAN_PACKAGE);
079: if (packageName == null || packageName.length() == 0) {
080: packageName = JsfProjectUtils.deriveSafeName(project
081: .getProjectDirectory().getName());
082: }
083: packageTextField.setText(packageName);
084:
085: packageTextField.setEditable(!JsfProjectUtils
086: .isJsfProject(project));
087: }
088:
089: public String getPackageName() {
090: String text = packageTextField.getText().trim();
091:
092: if (text.length() == 0) {
093: return null;
094: } else {
095: return text;
096: }
097: }
098:
099: public synchronized void addChangeListener(ChangeListener l) {
100: listeners.add(l);
101: }
102:
103: public synchronized void removeChangeListener(ChangeListener l) {
104: listeners.remove(l);
105: }
106:
107: private void fireChange() {
108: ChangeEvent e = new ChangeEvent(this );
109: List templist;
110: synchronized (this ) {
111: templist = new ArrayList(listeners);
112: }
113: Iterator it = templist.iterator();
114: while (it.hasNext()) {
115: ((ChangeListener) it.next()).stateChanged(e);
116: }
117: }
118:
119: /** This method is called from within the constructor to
120: * initialize the form.
121: * WARNING: Do NOT modify this code. The content of this method is
122: * always regenerated by the Form Editor.
123: */
124: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
125: private void initComponents() {
126: java.awt.GridBagConstraints gridBagConstraints;
127:
128: packageLabel = new javax.swing.JLabel();
129: packageTextField = new javax.swing.JTextField();
130:
131: setLayout(new java.awt.GridBagLayout());
132:
133: getAccessibleContext().setAccessibleDescription(
134: org.openide.util.NbBundle.getBundle(
135: PagebeanPackagePanelGUI.class).getString(
136: "AD_PagebeanPackagePanelGUI"));
137: packageLabel.setDisplayedMnemonic(org.openide.util.NbBundle
138: .getMessage(PagebeanPackagePanelGUI.class,
139: "MNE_PagebeanPackage_Label").charAt(0));
140: packageLabel.setLabelFor(packageTextField);
141: packageLabel.setText(org.openide.util.NbBundle.getMessage(
142: PagebeanPackagePanelGUI.class,
143: "LBL_PagebeanPackage_Label"));
144: gridBagConstraints = new java.awt.GridBagConstraints();
145: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
146: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
147: add(packageLabel, gridBagConstraints);
148:
149: gridBagConstraints = new java.awt.GridBagConstraints();
150: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
151: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
152: gridBagConstraints.weightx = 1.0;
153: gridBagConstraints.weighty = 1.0;
154: gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 0);
155: add(packageTextField, gridBagConstraints);
156: packageTextField.getAccessibleContext()
157: .setAccessibleDescription(
158: org.openide.util.NbBundle.getBundle(
159: PagebeanPackagePanelGUI.class)
160: .getString("AD_packageTextField"));
161:
162: }// </editor-fold>//GEN-END:initComponents
163:
164: // Variables declaration - do not modify//GEN-BEGIN:variables
165: private javax.swing.JLabel packageLabel;
166: private javax.swing.JTextField packageTextField;
167:
168: // End of variables declaration//GEN-END:variables
169:
170: // DocumentListener implementation -----------------------------------------
171:
172: public void changedUpdate(javax.swing.event.DocumentEvent e) {
173: fireChange();
174: }
175:
176: public void insertUpdate(javax.swing.event.DocumentEvent e) {
177: fireChange();
178: }
179:
180: public void removeUpdate(javax.swing.event.DocumentEvent e) {
181: fireChange();
182: }
183: }
|