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

« back to all changes in this revision

Viewing changes to j2ee/earproject/src/org/netbeans/modules/j2ee/earproject/ui/wizards/ImportBlueprintEarWizardIterator.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
 
 
42
package org.netbeans.modules.j2ee.earproject.ui.wizards;
 
43
 
 
44
import java.awt.Component;
 
45
import java.io.File;
 
46
import java.io.IOException;
 
47
import java.text.MessageFormat;
 
48
import java.util.HashSet;
 
49
import java.util.Map;
 
50
import java.util.NoSuchElementException;
 
51
import java.util.Set;
 
52
import javax.swing.JComponent;
 
53
import javax.swing.event.ChangeListener;
 
54
import org.netbeans.api.progress.ProgressHandle;
 
55
import org.netbeans.modules.j2ee.earproject.EarProjectGenerator;
 
56
import org.netbeans.modules.j2ee.earproject.ModuleType;
 
57
import org.netbeans.modules.j2ee.earproject.ui.FoldersListSettings;
 
58
import org.openide.WizardDescriptor;
 
59
import org.openide.filesystems.FileObject;
 
60
import org.openide.filesystems.FileUtil;
 
61
import org.openide.util.HelpCtx;
 
62
import org.openide.util.NbBundle;
 
63
 
 
64
/**
 
65
 * Wizard for importing a new Enterprise Application project.
 
66
 * @author Jesse Glick
 
67
 */
 
68
public class ImportBlueprintEarWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator {
 
69
    
 
70
    private static final long serialVersionUID = 1L;
 
71
    
 
72
    static final String PROP_NAME_INDEX = "nameIndex"; //NOI18N
 
73
    
 
74
    private transient int index;
 
75
    private transient WizardDescriptor.Panel[] panels;
 
76
    transient WizardDescriptor wiz;
 
77
    
 
78
    private WizardDescriptor.Panel[] createPanels() {
 
79
        return new WizardDescriptor.Panel[] {
 
80
            new PanelConfigureProject(PROP_NAME_INDEX,
 
81
                    NbBundle.getBundle(ImportBlueprintEarWizardIterator.class),
 
82
                    new HelpCtx(this.getClass()), true),
 
83
            new PanelModuleDetection()
 
84
        };
 
85
    }
 
86
    
 
87
    private String[] createSteps() {
 
88
        return new String[] {
 
89
            NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_NWP1_ProjectTitleName"),
 
90
            NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_IW_ApplicationModulesStep")
 
91
        };
 
92
    }
 
93
    
 
94
    public Set<FileObject> instantiate() throws IOException {
 
95
        assert false : "This method cannot be called if the class implements WizardDescriptor.ProgressInstantiatingIterator.";
 
96
        return null;
 
97
    }
 
98
        
 
99
    public Set<FileObject> instantiate(ProgressHandle handle) throws IOException {
 
100
        handle.start(3);
 
101
        handle.progress(NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_NewEarProjectWizardIterator_WizardProgress_CreatingProject"), 1);
 
102
        
 
103
        File dirF = (File) wiz.getProperty(WizardProperties.PROJECT_DIR);
 
104
        if (dirF != null) {
 
105
            dirF = FileUtil.normalizeFile(dirF);
 
106
        }
 
107
        File srcF = (File) wiz.getProperty(WizardProperties.SOURCE_ROOT);
 
108
        if (srcF != null) {
 
109
            srcF = FileUtil.normalizeFile(srcF);
 
110
        }
 
111
        String name = (String) wiz.getProperty(WizardProperties.NAME);
 
112
        String j2eeLevel = (String) wiz.getProperty(WizardProperties.J2EE_LEVEL);
 
113
        //        String contextPath = (String) wiz.getProperty(WizardProperties.CONTEXT_PATH);
 
114
        String serverInstanceID = (String) wiz.getProperty(WizardProperties.SERVER_INSTANCE_ID);
 
115
        String platformName = (String)wiz.getProperty(WizardProperties.JAVA_PLATFORM);
 
116
        String sourceLevel = (String)wiz.getProperty(WizardProperties.SOURCE_LEVEL);
 
117
        @SuppressWarnings("unchecked")
 
118
        Map<FileObject, ModuleType> userModules = (Map<FileObject, ModuleType>)
 
119
                wiz.getProperty(WizardProperties.USER_MODULES);
 
120
        return testableInstantiate(platformName, sourceLevel, j2eeLevel, dirF,
 
121
                srcF, serverInstanceID, name, userModules, handle);
 
122
    }
 
123
    
 
124
    /** <strong>Package private for unit test only</strong>. */
 
125
    static Set<FileObject> testableInstantiate(final String platformName,
 
126
            final String sourceLevel, final String j2eeLevel, final File dirF,
 
127
            final File srcF, final String serverInstanceID, final String name,
 
128
            final Map<FileObject, ModuleType> userModules, ProgressHandle handle) throws IOException {
 
129
        
 
130
        EarProjectGenerator.importProject(dirF, srcF, name, j2eeLevel,
 
131
                serverInstanceID, platformName, sourceLevel, userModules);
 
132
        if (handle != null) {
 
133
            handle.progress(2);
 
134
        }
 
135
 
 
136
        FileObject dir = FileUtil.toFileObject(dirF);
 
137
        
 
138
        // remember last used server
 
139
        FoldersListSettings.getDefault().setLastUsedServer(serverInstanceID);
 
140
        Set<FileObject> resultSet = new HashSet<FileObject>();
 
141
        resultSet.add(dir);
 
142
        
 
143
        NewEarProjectWizardIterator.setProjectChooserFolder(dirF);
 
144
        
 
145
        if (handle != null) {
 
146
            handle.progress(NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_NewEarProjectWizardIterator_WizardProgress_PreparingToOpen"), 3);
 
147
        }
 
148
 
 
149
        // Returning set of FileObject of project diretory.
 
150
        // Project will be open and set as main
 
151
        return resultSet;
 
152
    }
 
153
    
 
154
    public void initialize(WizardDescriptor wiz) {
 
155
        this.wiz = wiz;
 
156
        index = 0;
 
157
        panels = createPanels();
 
158
        // Make sure list of steps is accurate.
 
159
        String[] steps = createSteps();
 
160
        for (int i = 0; i < panels.length; i++) {
 
161
            Component c = panels[i].getComponent();
 
162
            if (steps[i] == null) {
 
163
                // Default step name to component name of panel.
 
164
                // Mainly useful for getting the name of the target
 
165
                // chooser to appear in the list of steps.
 
166
                steps[i] = c.getName();
 
167
            }
 
168
            if (c instanceof JComponent) { // assume Swing components
 
169
                JComponent jc = (JComponent)c;
 
170
                // Step #.
 
171
                jc.putClientProperty("WizardPanel_contentSelectedIndex", i); // NOI18N
 
172
                // Step name (actually the whole list for reference).
 
173
                jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
 
174
            }
 
175
        }
 
176
    }
 
177
 
 
178
    public void uninitialize(WizardDescriptor wiz) {
 
179
        if (this.wiz != null) {
 
180
            this.wiz.putProperty(WizardProperties.PROJECT_DIR,null);
 
181
            this.wiz.putProperty(WizardProperties.NAME,null);
 
182
        }
 
183
        this.wiz = null;
 
184
        panels = null;
 
185
    }
 
186
    
 
187
    public String name() {
 
188
        return MessageFormat.format(
 
189
                NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_WizardStepsCount"),
 
190
                index + 1, panels.length);
 
191
    }
 
192
    
 
193
    public boolean hasNext() {
 
194
        return index < panels.length - 1;
 
195
    }
 
196
    
 
197
    public boolean hasPrevious() {
 
198
        return index > 0;
 
199
    }
 
200
    
 
201
    public void nextPanel() {
 
202
        if (!hasNext()) {
 
203
            throw new NoSuchElementException();
 
204
        }
 
205
        index++;
 
206
    }
 
207
    
 
208
    public void previousPanel() {
 
209
        if (!hasPrevious()) {
 
210
            throw new NoSuchElementException();
 
211
        }
 
212
        index--;
 
213
    }
 
214
    
 
215
    public WizardDescriptor.Panel current() {
 
216
        return panels[index];
 
217
    }
 
218
    
 
219
    // If nothing unusual changes in the middle of the wizard, simply:
 
220
    public final void addChangeListener(ChangeListener l) {}
 
221
    public final void removeChangeListener(ChangeListener l) {}
 
222
    
 
223
    // helper methods, finds indexJSP's FileObject
 
224
    FileObject getIndexJSPFO(FileObject webRoot, String indexJSP) {
 
225
        // XXX: ignore unvalid mainClass?
 
226
        return webRoot.getFileObject(indexJSP.replace('.', '/'), "jsp"); // NOI18N
 
227
    }
 
228
    
 
229
}