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.php.project.wizards;
043:
044: import java.awt.BorderLayout;
045: import javax.swing.JPanel;
046: import org.netbeans.modules.php.rt.spi.providers.Host;
047: import org.netbeans.modules.php.rt.spi.providers.ProjectConfigProvider;
048: import org.netbeans.modules.php.rt.spi.providers.ProjectWizardComponent;
049: import org.netbeans.modules.php.rt.spi.providers.WebServerProvider;
050: import org.openide.WizardDescriptor;
051:
052: /**
053: *
054: * TODO: was quickly updated to show design. Needs refactoring.
055: * should use the same UI panel as customizer dialog
056: * @author ads
057: */
058: class ProviderPanelVisual extends JPanel {
059:
060: private static final long serialVersionUID = 6317907249928135438L;
061:
062: ProviderPanelVisual(ProviderSpecificPanel panel) {
063: myPanel = panel;
064: initComponents();
065: // temporary. while there is no additional options
066: mySeparator.setVisible(false);
067: }
068:
069: boolean dataIsValid(WizardDescriptor descriptor) {
070: descriptor.putProperty(
071: NewPhpProjectWizardIterator.WIZARD_PANEL_ERROR_MESSAGE,
072: "");
073: boolean flag = true;
074: if (myHostsPanel != null) {
075: flag = myHostsPanel.dataIsValid();
076: }
077: if (getProviderComoponent() != null) {
078: flag = flag && getProviderComoponent().isContentValid();
079: }
080: /*
081: * There is no sense to validate Version panel.
082: */
083: return flag;
084: }
085:
086: void read(WizardDescriptor descriptor) {
087: configureProviderPanel(descriptor);
088: validate();
089: }
090:
091: void store(WizardDescriptor descriptor) {
092: //REMOVED
093: //myVersionPanel.store(descriptor);
094: if (myHostsPanel != null) {
095: myHostsPanel.store(descriptor);
096: }
097:
098: storeServerConfig(descriptor);
099: }
100:
101: ProviderSpecificPanel getPanel() {
102: return myPanel;
103: }
104:
105: void useServerConfig(ProjectConfigProvider provider, Host host) {
106: if (getProviderPanel() != null) {
107: myProviderPanel.remove(getProviderPanel());
108: }
109: if (provider != null) {
110: ProjectWizardComponent comp = provider
111: .getWizardComponent(host);
112: myProviderPanel.add(BorderLayout.NORTH, comp.getPanel());
113: myProviderComponent = comp;
114: }
115: myProviderPanel.validate();
116: validate();
117: }
118:
119: void storeServerConfig(WizardDescriptor descriptor) {
120: if (getProviderComoponent() != null) {
121: getProviderComoponent().store(descriptor);
122: }
123: }
124:
125: void readServerConfig(WizardDescriptor descriptor) {
126: if (getProviderComoponent() != null) {
127: getProviderComoponent().read(descriptor);
128: }
129: }
130:
131: private void configureProviderPanel(WizardDescriptor descriptor) {
132: if (myHostsPanel != null) {
133: myChoosePanel.remove(myHostsPanel);
134: }
135: myHostsPanel = new HostPanelVisual(this );
136: myChoosePanel.add(BorderLayout.NORTH, myHostsPanel);
137: myHostsPanel.read(descriptor);
138: myChoosePanel.validate();
139:
140: readServerConfig(descriptor);
141: }
142:
143: private ProjectWizardComponent getProviderComoponent() {
144: return myProviderComponent;
145: }
146:
147: private JPanel getProviderPanel() {
148: if (getProviderComoponent() != null) {
149: return getProviderComoponent().getPanel();
150: }
151: return null;
152: }
153:
154: /** This method is called from within the constructor to
155: * initialize the form.
156: * WARNING: Do NOT modify this code. The content of this method is
157: * always regenerated by the Form Editor.
158: */
159: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
160: private void initComponents() {
161: java.awt.GridBagConstraints gridBagConstraints;
162:
163: myChoosePanel = new javax.swing.JPanel();
164: myProviderPanel = new javax.swing.JPanel();
165: mySeparator = new javax.swing.JSeparator();
166: myAdditionalConfiguration = new javax.swing.JPanel();
167:
168: setLayout(new java.awt.GridBagLayout());
169:
170: myChoosePanel.setLayout(new java.awt.BorderLayout());
171: gridBagConstraints = new java.awt.GridBagConstraints();
172: gridBagConstraints.gridx = 0;
173: gridBagConstraints.gridy = 0;
174: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
175: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
176: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
177: gridBagConstraints.weightx = 1.0;
178: add(myChoosePanel, gridBagConstraints);
179:
180: myProviderPanel.setLayout(new java.awt.BorderLayout());
181: gridBagConstraints = new java.awt.GridBagConstraints();
182: gridBagConstraints.gridx = 0;
183: gridBagConstraints.gridy = 1;
184: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
185: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
186: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
187: gridBagConstraints.weightx = 1.0;
188: add(myProviderPanel, gridBagConstraints);
189: gridBagConstraints = new java.awt.GridBagConstraints();
190: gridBagConstraints.gridx = 0;
191: gridBagConstraints.gridy = 2;
192: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
193: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
194: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
195: gridBagConstraints.weightx = 1.0;
196: gridBagConstraints.insets = new java.awt.Insets(7, 0, 7, 0);
197: add(mySeparator, gridBagConstraints);
198:
199: myAdditionalConfiguration
200: .setLayout(new java.awt.BorderLayout());
201: gridBagConstraints = new java.awt.GridBagConstraints();
202: gridBagConstraints.gridx = 0;
203: gridBagConstraints.gridy = 3;
204: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
205: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
206: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
207: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
208: gridBagConstraints.weightx = 1.0;
209: gridBagConstraints.weighty = 1.0;
210: add(myAdditionalConfiguration, gridBagConstraints);
211: }// </editor-fold>//GEN-END:initComponents
212:
213: // Variables declaration - do not modify//GEN-BEGIN:variables
214: private javax.swing.JPanel myAdditionalConfiguration;
215: private javax.swing.JPanel myChoosePanel;
216: private javax.swing.JPanel myProviderPanel;
217: private javax.swing.JSeparator mySeparator;
218:
219: // End of variables declaration//GEN-END:variables
220:
221: protected class AbsentHost implements Host {
222:
223: public AbsentHost(String name) {
224: myName = name;
225: }
226:
227: public Object getProperty(String key) {
228: return null;
229: }
230:
231: public void setProperty(String key, Object value) {
232: }
233:
234: public WebServerProvider getProvider() {
235: return null;
236: }
237:
238: public String getDisplayName() {
239: return myName;
240: }
241:
242: public String getServerName() {
243: return getDisplayName();
244: }
245:
246: @Override
247: public String toString() {
248: return getDisplayName();
249: }
250:
251: public String getId() {
252: return getDisplayName();
253: }
254:
255: private String myName;
256: }
257:
258: protected class NoHost extends AbsentHost {
259:
260: public NoHost() {
261: super ("No Server");
262: }
263:
264: public String getId() {
265: return "9846573n2cm#$%jsdlc32@$%^35947534mcfoei%^%^8709gfgjhkfghjl";
266: }
267:
268: }
269:
270: protected NoHost getNoHost() {
271: return myNoHost;
272: }
273:
274: private ProviderSpecificPanel myPanel;
275:
276: private HostPanelVisual myHostsPanel;
277:
278: //REMOVED
279: //private PhpVersionPanel myVersionPanel;
280: private ProjectWizardComponent myProviderComponent;
281:
282: private NoHost myNoHost = new NoHost();
283: }
|