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.awt.Component;
048: import java.util.ArrayList;
049: import java.util.Iterator;
050: import java.util.List;
051: import javax.swing.event.ChangeEvent;
052: import javax.swing.event.ChangeListener;
053: import org.netbeans.api.project.Project;
054: import org.openide.WizardDescriptor;
055: import org.openide.util.HelpCtx;
056: import org.openide.util.NbBundle;
057:
058: /**
059: *
060: * @author Po-Ting Wu
061: */
062: final class PagebeanPackagePanel implements WizardDescriptor.Panel,
063: ChangeListener {
064:
065: private final List/*<ChangeListener>*/listeners = new ArrayList();
066: private PagebeanPackagePanelGUI gui;
067:
068: private Project project;
069: private WizardDescriptor wizard;
070:
071: PagebeanPackagePanel(Project project) {
072: this .project = project;
073: this .gui = null;
074: }
075:
076: public Component getComponent() {
077: if (gui == null) {
078: gui = new PagebeanPackagePanelGUI(project);
079: gui.addChangeListener(this );
080: }
081: return gui;
082: }
083:
084: public HelpCtx getHelp() {
085: return null;
086: }
087:
088: public boolean isValid() {
089: if (gui == null) {
090: return false;
091: }
092:
093: // Check to make sure that the package name is valid
094: String packageName = gui.getPackageName();
095: if (!JsfProjectUtils.isValidJavaPackageName(packageName)) {
096: wizard.putProperty("WizardPanel_errorMessage", NbBundle
097: .getMessage(PagebeanPackagePanel.class,
098: "MSG_InvalidPackageName", packageName)); // NOI18N
099: return false;
100: }
101:
102: return true;
103: }
104:
105: public synchronized void addChangeListener(ChangeListener l) {
106: listeners.add(l);
107: }
108:
109: public synchronized void removeChangeListener(ChangeListener l) {
110: listeners.remove(l);
111: }
112:
113: private void fireChange() {
114: ChangeEvent e = new ChangeEvent(this );
115: List templist;
116: synchronized (this ) {
117: templist = new ArrayList(listeners);
118: }
119: Iterator it = templist.iterator();
120: while (it.hasNext()) {
121: ((ChangeListener) it.next()).stateChanged(e);
122: }
123: }
124:
125: public void readSettings(Object settings) {
126: wizard = (WizardDescriptor) settings;
127:
128: if (gui == null) {
129: getComponent();
130: }
131:
132: gui.initValues(project);
133: }
134:
135: public void storeSettings(Object settings) {
136: if (WizardDescriptor.PREVIOUS_OPTION
137: .equals(((WizardDescriptor) settings).getValue())) {
138: return;
139: }
140:
141: if (isValid()) {
142: ((WizardDescriptor) settings).putProperty(
143: JsfProjectConstants.PROP_JSF_PAGEBEAN_PACKAGE, gui
144: .getPackageName());
145: }
146: }
147:
148: public void stateChanged(ChangeEvent e) {
149: if (wizard != null && isValid()) {
150: wizard.putProperty(
151: JsfProjectConstants.PROP_JSF_PAGEBEAN_PACKAGE, gui
152: .getPackageName());
153: }
154:
155: fireChange();
156: }
157: }
|