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: package org.netbeans.modules.visualweb.samples.bundled.wizard;
042:
043: import java.awt.Component;
044: import java.io.File;
045: import java.util.HashSet;
046: import java.util.Iterator;
047: import java.util.Set;
048: import javax.swing.event.ChangeEvent;
049: import javax.swing.event.ChangeListener;
050:
051: import org.netbeans.spi.project.ui.templates.support.Templates;
052: import org.openide.WizardDescriptor;
053: import org.openide.filesystems.FileObject;
054: import org.openide.util.HelpCtx;
055: import org.openide.util.NbBundle;
056:
057: public class SamplesWebWizardPanel implements WizardDescriptor.Panel {
058: private WizardDescriptor wizard;
059:
060: /*
061: * The visual component that displays this panel. If you need to access the
062: * component from this class, just use getComponent().
063: */
064: private SamplesWebVisualPanel component;
065:
066: // Get the visual component for the panel. In this template, the component
067: // is kept separate. This can be more efficient: if the wizard is created
068: // but never displayed, or not all panels are displayed, it is better to
069: // create only those which really need to be visible.
070: public Component getComponent() {
071: if (component == null) {
072: component = new SamplesWebVisualPanel(this );
073: }
074: return component;
075: }
076:
077: public HelpCtx getHelp() {
078: // Show no Help button for this panel:
079: return HelpCtx.DEFAULT_HELP;
080: // If you have context help:
081: // return new HelpCtx(SampleWizardPanel1.class);
082: }
083:
084: public boolean isValid() {
085: FileObject template = Templates.getTemplate(this .wizard);
086: String projectLocation = (String) this .component
087: .getProjectLocation();
088: File projectLocationFile = new File(projectLocation);
089: String projectName = (String) this .component.getProjectName();
090: File projectNameFile = new File(projectLocation
091: + File.separator + projectName);
092: boolean result = !projectNameFile.exists()
093: && projectLocationFile.exists();
094: if (!result) {
095: String errorMessage = NbBundle.getMessage(
096: SamplesWebWizardPanel.class,
097: "MSG_not_valid_project_name", projectName);
098: this .wizard.putProperty("WizardPanel_errorMessage",
099: errorMessage); // NOI18N
100: } else {
101: this .wizard.putProperty("WizardPanel_errorMessage", null); // NOI18N
102: }
103: // If it is always OK to press Next or Finish, then:
104: return result;
105: // If it depends on some condition (form filled out...), then:
106: // return someCondition();
107: // and when this condition changes (last form field filled in...) then:
108: // fireChangeEvent();
109: // and uncomment the complicated stuff below.
110: }
111:
112: //public final void addChangeListener(ChangeListener l) {}
113: //public final void removeChangeListener(ChangeListener l) {}
114:
115: private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(
116: 1);
117:
118: public final void addChangeListener(ChangeListener l) {
119: synchronized (listeners) {
120: listeners.add(l);
121: }
122: }
123:
124: public final void removeChangeListener(ChangeListener l) {
125: synchronized (listeners) {
126: listeners.remove(l);
127: }
128: }
129:
130: protected final void fireChangeEvent() {
131: Iterator<ChangeListener> it;
132: synchronized (listeners) {
133: it = new HashSet<ChangeListener>(listeners).iterator();
134: }
135: ChangeEvent ev = new ChangeEvent(this );
136: while (it.hasNext()) {
137: it.next().stateChanged(ev);
138: }
139: }
140:
141: // You can use a settings object to keep track of state. Normally the
142: // settings object will be the WizardDescriptor, so you can use
143: // WizardDescriptor.getProperty & putProperty to store information entered
144: // by the user.
145: public void readSettings(Object settings) {
146: this .wizard = (WizardDescriptor) settings;
147: this .component.read(wizard);
148: }
149:
150: public void storeSettings(Object settings) {
151: WizardDescriptor wd = (WizardDescriptor) settings;
152: this.component.store(wd);
153: }
154:
155: }
|