~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to ide/projectimport/bluej/src/org/netbeans/bluej/export/ExportWizardPanel1.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
package org.netbeans.bluej.export;
 
42
 
 
43
import java.awt.Component;
 
44
import java.io.File;
 
45
import java.util.HashSet;
 
46
import java.util.Iterator;
 
47
import java.util.Set;
 
48
import javax.swing.event.ChangeEvent;
 
49
import javax.swing.event.ChangeListener;
 
50
import org.openide.WizardDescriptor;
 
51
import org.openide.filesystems.FileObject;
 
52
import org.openide.util.HelpCtx;
 
53
 
 
54
public class ExportWizardPanel1 implements WizardDescriptor.Panel {
 
55
 
 
56
    private String path;
 
57
    /**
 
58
     * The visual component that displays this panel. If you need to access the
 
59
     * component from this class, just use getComponent().
 
60
     */
 
61
    private Component component;
 
62
 
 
63
    private FileObject dir;
 
64
    private boolean valid = false;
 
65
    private WizardDescriptor settings;
 
66
    
 
67
    ExportWizardPanel1(FileObject fo) {
 
68
        dir = fo;
 
69
    }
 
70
    
 
71
    // Get the visual component for the panel. In this template, the component
 
72
    // is kept separate. This can be more efficient: if the wizard is created
 
73
    // but never displayed, or not all panels are displayed, it is better to
 
74
    // create only those which really need to be visible.
 
75
    public Component getComponent() {
 
76
        if (component == null) {
 
77
            component = new ExportPanel(dir, this);
 
78
        }
 
79
        return component;
 
80
    }
 
81
    
 
82
    public HelpCtx getHelp() {
 
83
        // Show no Help button for this panel:
 
84
        return HelpCtx.DEFAULT_HELP;
 
85
        // If you have context help:
 
86
        // return new HelpCtx(SampleWizardPanel1.class);
 
87
    }
 
88
    
 
89
    public boolean isValid() {
 
90
        return valid;
 
91
    }
 
92
    
 
93
    private final Set listeners = new HashSet(1);
 
94
    public final void addChangeListener(ChangeListener l) {
 
95
        synchronized (listeners) {
 
96
            listeners.add(l);
 
97
        }
 
98
    }
 
99
    public final void removeChangeListener(ChangeListener l) {
 
100
        synchronized (listeners) {
 
101
            listeners.remove(l);
 
102
        }
 
103
    }
 
104
    protected final void fireChangeEvent() {
 
105
        Iterator it;
 
106
        synchronized (listeners) {
 
107
            it = new HashSet(listeners).iterator();
 
108
        }
 
109
        ChangeEvent ev = new ChangeEvent(this);
 
110
        while (it.hasNext()) {
 
111
            ((ChangeListener)it.next()).stateChanged(ev);
 
112
        }
 
113
    }
 
114
    
 
115
    // You can use a settings object to keep track of state. Normally the
 
116
    // settings object will be the WizardDescriptor, so you can use
 
117
    // WizardDescriptor.getProperty & putProperty to store information entered
 
118
    // by the user.
 
119
    public void readSettings(Object sets) {
 
120
        this.settings = (WizardDescriptor)sets;
 
121
        File fil = (File)settings.getProperty("NewProjectLocation");
 
122
        String path = fil != null ? fil.getAbsolutePath() : "";
 
123
        updateValue(path);
 
124
    }
 
125
    public void storeSettings(Object set) {
 
126
        WizardDescriptor wiz = (WizardDescriptor)set;
 
127
        if (path != null) {
 
128
            //#79637 can be null when immediately cancelling the wizard.
 
129
            wiz.putProperty("NewProjectLocation", new File(path.trim())); // NOI18N
 
130
        }
 
131
    }
 
132
 
 
133
    void updateValue(String value) {
 
134
        path = value;
 
135
        if (path == null || path.trim().length() == 0) {
 
136
            settings.putProperty("WizardPanel_errorMessage", org.openide.util.NbBundle.getMessage(ExportWizardPanel1.class, "ERROR_noFolder"));
 
137
            valid = false;
 
138
        } else {
 
139
            File fil = new File(path.trim());
 
140
            if (fil.exists() && (fil.isFile() || (fil.isDirectory() && fil.listFiles().length > 0))) {
 
141
                settings.putProperty("WizardPanel_errorMessage", org.openide.util.NbBundle.getMessage(ExportWizardPanel1.class, "ERROR_WrongFolder"));
 
142
                valid = false;
 
143
            } else {
 
144
                settings.putProperty("WizardPanel_errorMessage", null);
 
145
                valid = true;
 
146
            }
 
147
        }
 
148
        
 
149
        fireChangeEvent();
 
150
    }
 
151
    
 
152
}
 
153