netbeans.org is behind firewall, using runsocks wrapper... Index: projectui/src/org/netbeans/modules/project/ui/actions/Actions.java =================================================================== RCS file: /cvs/projects/projectui/src/org/netbeans/modules/project/ui/actions/Actions.java,v retrieving revision 1.20 diff -u -b -r1.20 Actions.java --- projectui/src/org/netbeans/modules/project/ui/actions/Actions.java 5 Apr 2005 18:31:35 -0000 1.20 +++ projectui/src/org/netbeans/modules/project/ui/actions/Actions.java 16 May 2005 15:35:47 -0000 @@ -84,6 +84,11 @@ return NEW_FILE; } + public synchronized Action newProjectAction() { + return new NewProject(); + } + + public Action projectCommandAction(String command, String namePattern, Icon icon ) { return new ProjectAction( command, namePattern, icon, null ); } Index: projectui/src/org/netbeans/modules/project/ui/actions/NewProject.java =================================================================== RCS file: /cvs/projects/projectui/src/org/netbeans/modules/project/ui/actions/NewProject.java,v retrieving revision 1.19 diff -u -b -r1.19 NewProject.java --- projectui/src/org/netbeans/modules/project/ui/actions/NewProject.java 2 May 2005 14:31:58 -0000 1.19 +++ projectui/src/org/netbeans/modules/project/ui/actions/NewProject.java 16 May 2005 15:35:47 -0000 @@ -14,6 +14,7 @@ package org.netbeans.modules.project.ui.actions; import java.awt.event.ActionEvent; +import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.LinkedList; @@ -26,6 +27,7 @@ import org.netbeans.modules.project.ui.NewProjectWizard; import org.netbeans.modules.project.ui.OpenProjectList; import org.netbeans.modules.project.ui.ProjectUtilities; +import org.netbeans.spi.project.ui.support.CommonProjectActions; import org.openide.ErrorManager; import org.openide.filesystems.FileObject; import org.openide.filesystems.Repository; @@ -68,9 +70,7 @@ } } - private void doPerform () { - - FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource( "Templates/Project" ); //NOI18N + /*T9Y*/ NewProjectWizard prepareWizardDescriptor(FileObject fo) { NewProjectWizard wizard = new NewProjectWizard(fo); if ( isPreselect ) { @@ -83,6 +83,17 @@ wizard.putProperty( "PRESELECT_TEMPLATE", null ); } + FileObject folder = (FileObject) getValue(CommonProjectActions.EXISTING_SOURCES_FOLDER); + if (folder != null) { + wizard.putProperty(CommonProjectActions.EXISTING_SOURCES_FOLDER, folder); + } + return wizard; + } + + private void doPerform () { + + FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource( "Templates/Project" ); //NOI18N + NewProjectWizard wizard = prepareWizardDescriptor(fo); try { Index: projectuiapi/nbproject/project.properties =================================================================== RCS file: /cvs/projects/projectuiapi/nbproject/project.properties,v retrieving revision 1.8 diff -u -b -r1.8 project.properties --- projectuiapi/nbproject/project.properties 25 Apr 2005 12:44:42 -0000 1.8 +++ projectuiapi/nbproject/project.properties 16 May 2005 15:35:47 -0000 @@ -14,3 +14,7 @@ javadoc.title=Project UI API javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml +# copy paste magic to enable unit tests +test.unit.src.dir=${basedir}/test/unit/src +test-unit-sys-prop.test.junit.jar=${junit.dir}/modules/ext/junit-3.8.1.jar + Index: projectuiapi/src/org/netbeans/modules/project/uiapi/ActionsFactory.java =================================================================== RCS file: /cvs/projects/projectuiapi/src/org/netbeans/modules/project/uiapi/ActionsFactory.java,v retrieving revision 1.6 diff -u -b -r1.6 ActionsFactory.java --- projectuiapi/src/org/netbeans/modules/project/uiapi/ActionsFactory.java 16 Jun 2004 12:31:07 -0000 1.6 +++ projectuiapi/src/org/netbeans/modules/project/uiapi/ActionsFactory.java 16 May 2005 15:35:47 -0000 @@ -34,6 +34,8 @@ public Action closeProjectAction(); public Action newFileAction(); + + public Action newProjectAction(); // Actions sensitive to project selection Index: projectuiapi/src/org/netbeans/spi/project/ui/support/CommonProjectActions.java =================================================================== RCS file: /cvs/projects/projectuiapi/src/org/netbeans/spi/project/ui/support/CommonProjectActions.java,v retrieving revision 1.6 diff -u -b -r1.6 CommonProjectActions.java --- projectuiapi/src/org/netbeans/spi/project/ui/support/CommonProjectActions.java 9 May 2005 09:54:02 -0000 1.6 +++ projectuiapi/src/org/netbeans/spi/project/ui/support/CommonProjectActions.java 16 May 2005 15:35:47 -0000 @@ -22,6 +22,12 @@ */ public class CommonProjectActions { + /** + * {@link FileObject} value honored by newProjectAction that defines + * existing sources directory (compare to project directory). + */ + public static final String EXISTING_SOURCES_FOLDER = "existingSourcesFolder"; + private CommonProjectActions() {} /** @@ -90,4 +96,15 @@ return Utilities.getActionsFactory().newFileAction(); } + /** + * Creates action that invokes new project wizard. + * It honors {@link #EXISTING_SOURCES_DIRECTORY}. + * + * @return an action + * @see org.netbeans.spi.project.ui.PrivilegedTemplates + * @see org.netbeans.spi.project.ui.RecommendedTemplates + */ + public static Action newProjectAction() { + return Utilities.getActionsFactory().newProjectAction(); + } } Index: projectuiapi/src/org/netbeans/spi/project/ui/templates/support/Templates.java =================================================================== RCS file: /cvs/projects/projectuiapi/src/org/netbeans/spi/project/ui/templates/support/Templates.java,v retrieving revision 1.12 diff -u -b -r1.12 Templates.java --- projectuiapi/src/org/netbeans/spi/project/ui/templates/support/Templates.java 16 Apr 2005 19:06:16 -0000 1.12 +++ projectuiapi/src/org/netbeans/spi/project/ui/templates/support/Templates.java 16 May 2005 15:35:47 -0000 @@ -99,6 +99,31 @@ } } + /** + * Find the existing sources folder selected for a custom template wizard iterator. + *

+ * This may not be set, unless you have CommonProjectActions.newProjectAction + * with CommonProjectActions.EXISTING_SOURCES_FOLDER value. + *

+ * + * @param wizardDescriptor the wizard as passed to {@link WizardDescriptor.InstantiatingIterator#initialize} + * or {@link TemplateWizard.Iterator#initialize} + * @return the folder into which the user has requested this iterator create a file (or null if not set) + */ + public static FileObject getExitingSourcesFolder( WizardDescriptor wizardDescriptor ) { + + if ( wizardDescriptor instanceof TemplateWizard ) { + try { + return ((TemplateWizard)wizardDescriptor).getTargetFolder().getPrimaryFile(); + } + catch ( IOException e ) { + return null; + } + } + else { + return (FileObject) wizardDescriptor.getProperty( ProjectChooserFactory.WIZARD_KEY_TARGET_FOLDER ); + } + } /** * Stores a target folder so that it can be remembered later using {@link #getTargetFolder}. * @param wizardDescriptor a template wizard Index: projectuiapi/test/unit/src/org/netbeans/spi/project/ui/support/CommonProjectActionsTest.java =================================================================== RCS file: projectuiapi/test/unit/src/org/netbeans/spi/project/ui/support/CommonProjectActionsTest.java diff -N projectuiapi/test/unit/src/org/netbeans/spi/project/ui/support/CommonProjectActionsTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ projectuiapi/test/unit/src/org/netbeans/spi/project/ui/support/CommonProjectActionsTest.java 16 May 2005 15:35:47 -0000 @@ -0,0 +1,62 @@ +/* + * 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-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.spi.project.ui.support; +import junit.framework.*; +import javax.swing.Action; +import org.netbeans.modules.project.uiapi.Utilities; + +/** + * + * @author Petr Kuzel + */ +public class CommonProjectActionsTest extends TestCase { + + public CommonProjectActionsTest(String testName) { + super(testName); + } + + public static Test suite() { + TestSuite suite = new TestSuite(CommonProjectActionsTest.class); + + return suite; + } + + public void testSetAsMainProjectAction() { + } + + public void testCustomizeProjectAction() { + } + + public void testOpenSubprojectsAction() { + } + + public void testCloseProjectAction() { + } + + public void testNewFileAction() { + } + + /** + * Assure that two clients do not interact. + */ + public void testNewProjectAction() { + Action client1 = CommonProjectActions.newProjectAction(); + File exitingSources = new Object(); + client1.setValue(CommonProjectActions.EXISTING_SOURCES_FOLDER, exitingSources); + Action client2 = CommonProjectActions.newProjectAction(); + Object o = client2.getValue(CommonProjectActions.EXISTING_SOURCES_FOLDER); + assertTrue(o != exitingSources); + } + +}