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-2006 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 javax.swing.JPanel;
045: import org.openide.WizardDescriptor;
046: import org.openide.util.NbBundle;
047:
048: /**
049: * Basic visual panel for APISupport wizard panels.
050: *
051: * @author Martin Krauskopf
052: */
053: public abstract class BasicVisualPanel extends JPanel {
054:
055: private WizardDescriptor settings;
056:
057: protected BasicVisualPanel(final WizardDescriptor setting) {
058: this .settings = setting;
059: }
060:
061: public final WizardDescriptor getSettings() {
062: return settings;
063: }
064:
065: /**
066: * Set an error message and mark the panel as invalid.
067: */
068: protected final void setError(String message) {
069: if (message == null) {
070: throw new NullPointerException();
071: }
072: setMessage(message);
073: setValid(false);
074: }
075:
076: /**
077: * Set an warning message but mark the panel as valid.
078: */
079: protected final void setWarning(String message) {
080: if (message == null) {
081: throw new NullPointerException();
082: }
083: setMessage(message);
084: setValid(true);
085: }
086:
087: /**
088: * Mark the panel as invalid without any message.
089: * Use with restraint; generally {@link #setError} is better.
090: */
091: protected final void markInvalid() {
092: setMessage(null);
093: setValid(false);
094: }
095:
096: /**
097: * Mark the panel as valid and clear any error or warning message.
098: */
099: protected final void markValid() {
100: setMessage(null);
101: setValid(true);
102: }
103:
104: private final void setMessage(String message) {
105: settings.putProperty("WizardPanel_errorMessage", message); // NOI18N
106: }
107:
108: /**
109: * Sets this panel's validity and fires event to it's wrapper wizard panel.
110: * See {@link BasicWizardPanel#propertyChange} for what happens further.
111: */
112: private final void setValid(boolean valid) {
113: firePropertyChange("valid", null, Boolean.valueOf(valid)); // NOI18N
114: }
115:
116: protected abstract static class NewTemplatePanel extends
117: BasicVisualPanel {
118:
119: private final NewModuleProjectData data;
120:
121: NewTemplatePanel(final NewModuleProjectData data) {
122: super (data.getSettings());
123: this .data = data;
124: String resource;
125: int wizardType = data.getWizardType();
126: switch (data.getWizardType()) {
127: case NewNbModuleWizardIterator.TYPE_SUITE:
128: resource = "emptySuite"; // NOI18N
129: break;
130: case NewNbModuleWizardIterator.TYPE_MODULE:
131: case NewNbModuleWizardIterator.TYPE_SUITE_COMPONENT:
132: resource = "emptyModule"; // NOI18N
133: break;
134: case NewNbModuleWizardIterator.TYPE_LIBRARY_MODULE:
135: resource = "libraryModule"; // NOI18N
136: break;
137: default:
138: assert false : "Unknown wizard type = " + wizardType;
139: resource = "";
140: }
141: data.getSettings()
142: .putProperty(
143: "NewProjectWizard_Title", // NOI18N
144: NbBundle.getMessage(BasicVisualPanel.class,
145: "Templates/Project/APISupport/"
146: + resource));
147: }
148:
149: protected NewModuleProjectData getData() {
150: return data;
151: }
152:
153: protected boolean isSuiteWizard() {
154: return getData().getWizardType() == NewNbModuleWizardIterator.TYPE_SUITE;
155: }
156:
157: protected boolean isSuiteComponentWizard() {
158: return getData().getWizardType() == NewNbModuleWizardIterator.TYPE_SUITE_COMPONENT;
159: }
160:
161: protected boolean isLibraryWizard() {
162: return getData().getWizardType() == NewNbModuleWizardIterator.TYPE_LIBRARY_MODULE;
163: }
164:
165: }
166:
167: }
|