1 19 20 package org.netbeans.spi.project.ui.templates.support; 21 22 import java.io.IOException ; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.api.project.SourceGroup; 25 import org.netbeans.modules.project.uiapi.ProjectChooserFactory; 26 import org.netbeans.modules.project.uiapi.Utilities; 27 import org.netbeans.spi.project.ui.support.CommonProjectActions; 28 import org.openide.WizardDescriptor; 29 import org.openide.filesystems.FileObject; 30 import org.openide.loaders.DataFolder; 31 import org.openide.loaders.DataObject; 32 import org.openide.loaders.TemplateWizard; 33 34 38 public class Templates { 39 40 private Templates() {} 41 42 53 public static Project getProject( WizardDescriptor wizardDescriptor ) { 54 return (Project) wizardDescriptor.getProperty( ProjectChooserFactory.WIZARD_KEY_PROJECT ); 55 } 56 57 68 public static FileObject getTemplate( WizardDescriptor wizardDescriptor ) { 69 if (wizardDescriptor == null) { 70 throw new IllegalArgumentException ("Cannot pass a null wizardDescriptor"); } 72 if ( wizardDescriptor instanceof TemplateWizard ) { 73 DataObject template = ((TemplateWizard)wizardDescriptor).getTemplate(); 74 if (template != null) { 75 return template.getPrimaryFile(); 76 } 77 } 78 return (FileObject) wizardDescriptor.getProperty( ProjectChooserFactory.WIZARD_KEY_TEMPLATE ); 79 } 80 81 94 public static FileObject getTargetFolder( WizardDescriptor wizardDescriptor ) { 95 96 if ( wizardDescriptor instanceof TemplateWizard ) { 97 try { 98 return ((TemplateWizard)wizardDescriptor).getTargetFolder().getPrimaryFile(); 99 } 100 catch ( IOException e ) { 101 return null; 102 } 103 } 104 else { 105 return (FileObject) wizardDescriptor.getProperty( ProjectChooserFactory.WIZARD_KEY_TARGET_FOLDER ); 106 } 107 } 108 109 122 public static FileObject getExistingSourcesFolder( WizardDescriptor wizardDescriptor ) { 123 return (FileObject) wizardDescriptor.getProperty( CommonProjectActions.EXISTING_SOURCES_FOLDER ); 124 } 125 130 public static void setTargetFolder( WizardDescriptor wizardDescriptor, FileObject folder ) { 131 132 if ( wizardDescriptor instanceof TemplateWizard ) { 133 DataFolder dataFolder = DataFolder.findFolder( folder ); 134 ((TemplateWizard)wizardDescriptor).setTargetFolder( dataFolder ); 135 } 136 else { 137 wizardDescriptor.putProperty( ProjectChooserFactory.WIZARD_KEY_TARGET_FOLDER, folder ); 138 } 139 } 140 141 149 public static String getTargetName( WizardDescriptor wizardDescriptor ) { 150 if ( wizardDescriptor instanceof TemplateWizard ) { 151 return ((TemplateWizard)wizardDescriptor).getTargetName(); 152 } 153 else { 154 return (String ) wizardDescriptor.getProperty( ProjectChooserFactory.WIZARD_KEY_TARGET_NAME ); 155 } 156 } 157 158 166 public static void setTargetName( WizardDescriptor wizardDescriptor, String targetName ) { 167 if ( wizardDescriptor instanceof TemplateWizard ) { 168 ((TemplateWizard)wizardDescriptor).setTargetName( targetName ); 169 } 170 else { 171 wizardDescriptor.putProperty( ProjectChooserFactory.WIZARD_KEY_TARGET_NAME, targetName ); 172 } 173 } 174 175 183 public static WizardDescriptor.Panel createSimpleTargetChooser( Project project, SourceGroup[] folders ) { 184 return createSimpleTargetChooser( project, folders, null ); 185 } 186 187 198 public static WizardDescriptor.Panel createSimpleTargetChooser( Project project, SourceGroup[] folders, WizardDescriptor.Panel bottomPanel ) { 199 return Utilities.getProjectChooserFactory().createSimpleTargetChooser( project, folders, bottomPanel ); 200 } 201 202 } 203 | Popular Tags |