alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.ant.freeform.ui;

import java.awt.Component;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.MessageFormat;
import java.util.ArrayList;

import java.util.HashSet;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.swing.JComponent;
import javax.swing.event.ChangeListener;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.modules.ant.freeform.FreeformProjectGenerator;
import org.netbeans.spi.project.support.ant.AntProjectHelper;
import org.netbeans.spi.project.support.ant.PropertyUtils;
import org.openide.ErrorManager;
import org.openide.WizardDescriptor;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.NbBundle;

/**
 * @author  David Konecny, Radko Najman
 */
public class NewWebFreeformProjectWizardIterator implements WizardDescriptor.InstantiatingIterator {

    // See NewJ2SEFreeformProjectWizardIterator for list of contants 
    // defined and used by standard J2SE panels.
    
    // web sources
    public static final String PROP_WEB_WEBMODULES = "webModules"; //  NOI18N
    public static final String PROP_WEB_SOURCE_FOLDERS = "webSourceFolders"; //  NOI18N
    
    private static final long serialVersionUID = 1L;
    
    private transient int index;
    private transient WizardDescriptor.Panel[] panels;
    private transient WizardDescriptor wiz;
    
    public NewWebFreeformProjectWizardIterator() {
    }
    
    private WizardDescriptor.Panel[] createPanels () {
        return new WizardDescriptor.Panel[] {
                new BasicProjectInfoWizardPanel(),
                new TargetMappingWizardPanel("webapps"), // NOI18N
                new WebLocationsWizardPanel(),
                new SourceFoldersWizardPanel(),
                new ClasspathWizardPanel(),
            };
    }
    
    private String[] createSteps() {
            return new String[] {
                NbBundle.getMessage (NewWebFreeformProjectWizardIterator.class, "TXT_NewJ2SEFreeformProjectWizardIterator_NameAndLocation"), // NOI18N
                NbBundle.getMessage (NewWebFreeformProjectWizardIterator.class, "TXT_NewJ2SEFreeformProjectWizardIterator_BuildAndRunActions"), // NOI18N
                NbBundle.getMessage (NewWebFreeformProjectWizardIterator.class, "TXT_NewWebFreeformProjectWizardIterator_WebSources"), // NOI18N
                NbBundle.getMessage (NewWebFreeformProjectWizardIterator.class, "TXT_NewJ2SEFreeformProjectWizardIterator_SourcePackageFolders"), // NOI18N
                NbBundle.getMessage (NewWebFreeformProjectWizardIterator.class, "TXT_NewJ2SEFreeformProjectWizardIterator_Classpath") // NOI18N
            };
    }
    
    public Set/**/ instantiate () throws IOException {
        ProjectModel pm = (ProjectModel)wiz.getProperty(NewJ2SEFreeformProjectWizardIterator.PROP_PROJECT_MODEL);
        File nbProjectFolder = pm.getNBProjectFolder();
        String projName = (String)wiz.getProperty(NewJ2SEFreeformProjectWizardIterator.PROP_PROJECT_NAME);
        File antScript = (File)wiz.getProperty(NewJ2SEFreeformProjectWizardIterator.PROP_ANT_SCRIPT);
        if (antScript.getParentFile().equals(nbProjectFolder) && antScript.getName().equals("build.xml")) { // NOI18N
            // default location of build file
            antScript = null;
        }
        List mappings = (List)wiz.getProperty(NewJ2SEFreeformProjectWizardIterator.PROP_TARGET_MAPPINGS);
        
        List webSources = (List)wiz.getProperty(PROP_WEB_SOURCE_FOLDERS);
        // at the moment always only one web-root
        assert webSources.size() == 1;
        pm.addSourceFolder((FreeformProjectGenerator.SourceFolder)webSources.get(0));
        
        List webModules = (List) wiz.getProperty(PROP_WEB_WEBMODULES);
        
        ProjectModel.instantiateWebProject(pm, projName, antScript, mappings, webModules);
        
        Set resultSet = new HashSet();
        resultSet.add(FileUtil.toFileObject(nbProjectFolder));
        return resultSet;
    }
    
        
    public void initialize(WizardDescriptor wiz) {
        this.wiz = wiz;
        index = 0;
        panels = createPanels();
        // Make sure list of steps is accurate.
        String[] steps = createSteps();
        for (int i = 0; i < panels.length; i++) {
            Component c = panels[i].getComponent();
//            if (steps[i] == null) {
//                // Default step name to component name of panel.
//                // Mainly useful for getting the name of the target
//                // chooser to appear in the list of steps.
//                steps[i] = c.getName();
//            }
            assert c instanceof JComponent;
            JComponent jc = (JComponent)c;
            // Step #.
            jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); // NOI18N
            // Step name (actually the whole list for reference).
            jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
            // Name of panel
            jc.setName(steps[i]);
            // set title
            jc.putClientProperty ("NewProjectWizard_Title", NbBundle.getMessage (NewWebFreeformProjectWizardIterator.class, "TXT_NewWebFreeformProjectWizardIterator_NewProjectWizardTitle")); // NOI18N
        }
    }
    
    public void uninitialize(WizardDescriptor wiz) {
        wiz.putProperty(NewJ2SEFreeformProjectWizardIterator.PROP_ANT_SCRIPT, null);
        wiz.putProperty(NewJ2SEFreeformProjectWizardIterator.PROP_PROJECT_NAME, null);
        wiz.putProperty(NewJ2SEFreeformProjectWizardIterator.PROP_TARGET_MAPPINGS, null);
        wiz.putProperty(NewJ2SEFreeformProjectWizardIterator.PROP_PROJECT_MODEL, null);
        wiz.putProperty(PROP_WEB_SOURCE_FOLDERS, null);
        wiz.putProperty(PROP_WEB_WEBMODULES, null);
        this.wiz = null;
        panels = null;
    }
    
    public String name() {
        return MessageFormat.format (NbBundle.getMessage(NewWebFreeformProjectWizardIterator.class, "TXT_NewJ2SEFreeformProjectWizardIterator_TitleFormat"), // NOI18N
            new Object[] {new Integer (index + 1), new Integer (panels.length) });
    }
    
    public boolean hasNext() {
        if (current() instanceof SourceFoldersWizardPanel) {
            assert current().getComponent() instanceof SourceFoldersPanel;
            SourceFoldersPanel sfp = (SourceFoldersPanel)current().getComponent();
            if (!sfp.hasSomeSourceFolder()) {
                return false;
            }
        }
        return index < panels.length - 1;
    }
    public boolean hasPrevious() {
        return index > 0;
    }
    public void nextPanel() {
        if (!hasNext()) throw new NoSuchElementException();
        index++;
    }
    public void previousPanel() {
        if (!hasPrevious()) throw new NoSuchElementException();
        index--;
    }
    public WizardDescriptor.Panel current () {
        return panels[index];
    }
    
    // If nothing unusual changes in the middle of the wizard, simply:
    public final void addChangeListener(ChangeListener l) {}
    public final void removeChangeListener(ChangeListener l) {}
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.