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.apisupport.project.ui.wizard;
043:
044: import java.beans.PropertyChangeEvent;
045: import java.beans.PropertyChangeListener;
046: import javax.swing.event.ChangeListener;
047: import org.openide.WizardDescriptor;
048: import org.openide.util.ChangeSupport;
049: import org.openide.util.HelpCtx;
050: import org.openide.util.NbBundle;
051:
052: /**
053: * Basic wizard panel for APISupport projects.
054: *
055: * @author Martin Krauskopf
056: */
057: public abstract class BasicWizardPanel implements
058: WizardDescriptor.Panel<WizardDescriptor>,
059: PropertyChangeListener {
060:
061: private boolean valid = true;
062: private WizardDescriptor settings;
063:
064: private final ChangeSupport changeSupport = new ChangeSupport(this );
065:
066: protected BasicWizardPanel(WizardDescriptor settings) {
067: this .settings = settings;
068: }
069:
070: public void setSettings(WizardDescriptor settings) {
071: this .settings = settings;
072: }
073:
074: protected WizardDescriptor getSettings() {
075: return settings;
076: }
077:
078: public void addChangeListener(ChangeListener l) {
079: changeSupport.addChangeListener(l);
080: }
081:
082: public void removeChangeListener(ChangeListener l) {
083: changeSupport.removeChangeListener(l);
084: }
085:
086: protected void fireChange() {
087: changeSupport.fireChange();
088: }
089:
090: /**
091: * Convenience method for accessing Bundle resources from this package.
092: */
093: protected final String getMessage(String key) {
094: return NbBundle.getMessage(getClass(), key);
095: }
096:
097: public HelpCtx getHelp() {
098: return null;
099: }
100:
101: public void storeSettings(WizardDescriptor settings) {
102: }
103:
104: public void readSettings(WizardDescriptor settings) {
105: }
106:
107: public boolean isValid() {
108: return valid;
109: }
110:
111: /**
112: * Mainly for receiving events from wrapped component about its validity.
113: * Firing events further to Wizard descriptor so it will reread this panel's
114: * state and reenable/redisable its next/prev/finish/... buttons.
115: */
116: public void propertyChange(PropertyChangeEvent evt) {
117: if ("valid".equals(evt.getPropertyName())) { // NOI18N
118: boolean nueValid = ((Boolean) evt.getNewValue())
119: .booleanValue();
120: if (nueValid != valid) {
121: valid = nueValid;
122: fireChange();
123: }
124: }
125: }
126:
127: abstract static class NewTemplatePanel extends BasicWizardPanel {
128:
129: private final NewModuleProjectData data;
130:
131: NewTemplatePanel(final NewModuleProjectData data) {
132: super (data.getSettings());
133: this .data = data;
134: }
135:
136: abstract void reloadData();
137:
138: abstract void storeData();
139:
140: public NewModuleProjectData getData() {
141: return data;
142: }
143:
144: public @Override
145: void readSettings(WizardDescriptor settings) {
146: reloadData();
147: }
148:
149: public @Override
150: void storeSettings(WizardDescriptor settings) {
151: storeData();
152: }
153:
154: protected String getWizardTypeString() {
155: String helpId = null;
156: switch (data.getWizardType()) {
157: case NewNbModuleWizardIterator.TYPE_SUITE:
158: helpId = "suite"; // NOI18N
159: break;
160: case NewNbModuleWizardIterator.TYPE_MODULE:
161: case NewNbModuleWizardIterator.TYPE_SUITE_COMPONENT:
162: helpId = "module"; // NOI18N
163: break;
164: case NewNbModuleWizardIterator.TYPE_LIBRARY_MODULE:
165: helpId = "library"; // NOI18N
166: break;
167: default:
168: assert false : "Unknown wizard type = "
169: + data.getWizardType();
170: }
171: return helpId;
172: }
173:
174: }
175:
176: }
|