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.customizer;
043:
044: import java.beans.PropertyChangeEvent;
045: import java.beans.PropertyChangeListener;
046: import javax.swing.JPanel;
047: import org.netbeans.spi.project.ui.support.ProjectCustomizer;
048: import org.openide.util.HelpCtx;
049:
050: /**
051: * Provides common support for a <em>standard</em> panels in the NetBeans module
052: * and suite customizers.
053: *
054: * @author Martin Krauskopf
055: */
056: abstract class NbPropertyPanel extends JPanel implements
057: ModuleProperties.LazyStorage, PropertyChangeListener,
058: HelpCtx.Provider {
059:
060: private Class helpCtxClass;
061:
062: /** Property whether <code>this</code> panel is valid. */
063: static final String VALID_PROPERTY = "isPanelValid"; // NOI18N
064:
065: /** Property for error message of this panel. */
066: static final String ERROR_MESSAGE_PROPERTY = "errorMessage"; // NOI18N
067:
068: protected ModuleProperties props;
069: protected final ProjectCustomizer.Category category;
070:
071: /** Creates new NbPropertyPanel */
072: NbPropertyPanel(final ModuleProperties props,
073: final Class helpCtxClass, ProjectCustomizer.Category cat) {
074: this .props = props;
075: category = cat;
076: props.addLazyStorage(this );
077: initComponents();
078: props.addPropertyChangeListener(this );
079: this .helpCtxClass = helpCtxClass;
080: }
081:
082: /**
083: * This method is called whenever {@link ModuleProperties} are refreshed.
084: */
085: abstract void refresh();
086:
087: String getProperty(String key) {
088: return props.getProperty(key);
089: }
090:
091: void setProperty(String key, String property) {
092: props.setProperty(key, property);
093: }
094:
095: boolean getBooleanProperty(String key) {
096: return props.getBooleanProperty(key);
097: }
098:
099: void setBooleanProperty(String key, boolean property) {
100: props.setBooleanProperty(key, property);
101: }
102:
103: /**
104: * Gives subclasses a chance to set a warning or an error message after a
105: * customizer is loaded/displayed. Just use this method for checking a
106: * validity of a panel's data and eventually call {@link
107: * #setWarning(String)} or {@link #setErrorMessage(String)}. Default
108: * implementation does nothing.
109: */
110:
111: //TODO remove!!
112: protected final void checkForm() {
113: }
114:
115: public void store() { /* empty implementation */
116: }
117:
118: public void propertyChange(PropertyChangeEvent evt) {
119: if (ModuleProperties.PROPERTIES_REFRESHED.equals(evt
120: .getPropertyName())) {
121: refresh();
122: }
123: }
124:
125: @Override
126: public void addNotify() {
127: super .addNotify();
128: //TODO replace with something else..
129: getRootPane()
130: .putClientProperty(BasicCustomizer.LAST_SELECTED_PANEL,
131: category.getName());
132: }
133:
134: public HelpCtx getHelpCtx() {
135: return new HelpCtx(helpCtxClass);
136: }
137:
138: /** This method is called from within the constructor to
139: * initialize the form.
140: * WARNING: Do NOT modify this code. The content of this method is
141: * always regenerated by the Form Editor.
142: */
143: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
144: private void initComponents() {
145:
146: setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER,
147: 0, 0));
148:
149: }
150:
151: // </editor-fold>//GEN-END:initComponents
152:
153: // Variables declaration - do not modify//GEN-BEGIN:variables
154: // End of variables declaration//GEN-END:variables
155:
156: abstract static class Single extends NbPropertyPanel {
157: Single(final SingleModuleProperties props,
158: final Class helpCtxClass, ProjectCustomizer.Category cat) {
159: super (props, helpCtxClass, cat);
160: }
161:
162: SingleModuleProperties getProperties() {
163: return (SingleModuleProperties) props;
164: }
165: }
166:
167: abstract static class Suite extends NbPropertyPanel {
168: Suite(final SuiteProperties props, final Class helpCtxClass,
169: ProjectCustomizer.Category cat) {
170: super (props, helpCtxClass, cat);
171: }
172:
173: SuiteProperties getProperties() {
174: return (SuiteProperties) props;
175: }
176: }
177:
178: }
|