本文整理汇总了Java中org.netbeans.spi.project.ui.templates.support.Templates.getTemplate方法的典型用法代码示例。如果您正苦于以下问题:Java Templates.getTemplate方法的具体用法?Java Templates.getTemplate怎么用?Java Templates.getTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.spi.project.ui.templates.support.Templates
的用法示例。
在下文中一共展示了Templates.getTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readSettings
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
@Override
public void readSettings(WizardDescriptor settings) {
this.wizard = settings;
TemplateChooserPanelGUI panel = (TemplateChooserPanelGUI) this.getComponent();
final FileObject currentTemplate = Templates.getTemplate(settings);
FileObject templates = FileUtil.getConfigFile("Templates"); //NOI18N
String currentCategoryName = null;
String currentTemplateName = null;
if (templates != null && currentTemplate != null && currentTemplate.getParent() != null && templates.equals(currentTemplate.getParent().getParent())) {
try {
final DataObject dobj = DataObject.find(currentTemplate);
final DataObject owner = DataObject.find(currentTemplate.getParent());
currentTemplateName = dobj.getName();
currentCategoryName = owner.getName();
} catch (DataObjectNotFoundException e) {
//Ignore and use default
}
}
panel.readValues( project, currentCategoryName, currentTemplateName );
settings.putProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, 0);
settings.putProperty(WizardDescriptor.PROP_CONTENT_DATA, new String[] {
NbBundle.getBundle (TemplateChooserPanel.class).getString ("LBL_TemplatesPanel_Name"), // NOI18N
NbBundle.getBundle (TemplateChooserPanel.class).getString ("LBL_TemplatesPanel_Dots")}); // NOI18N
// bugfix #44400: wizard title always changes
settings.putProperty("NewFileWizard_Title", null); // NOI18N
}
示例2: instantiate
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
/**
* This is where, the schema gets instantiated from the template.
*/
public Set instantiate (TemplateWizard wizard) throws IOException {
FileObject dir = Templates.getTargetFolder( wizard );
DataFolder df = DataFolder.findFolder( dir );
FileObject template = Templates.getTemplate( wizard );
DataObject dTemplate = DataObject.find( template );
DataObject dobj = dTemplate.createFromTemplate(df, Templates.getTargetName(wizard));
if (dobj == null)
return Collections.emptySet();
encoding = EncodingUtil.getProjectEncoding(df.getPrimaryFile());
if(!EncodingUtil.isValidEncoding(encoding))
encoding = "UTF-8"; //NOI18N
EditCookie edit = dobj.getCookie(EditCookie.class);
if (edit != null) {
EditorCookie editorCookie = dobj.getCookie(EditorCookie.class);
Document doc = (Document)editorCookie.openDocument();
fixEncoding(doc, encoding);
SaveCookie save = dobj.getCookie(SaveCookie.class);
if (save!=null) save.save();
}
return Collections.singleton(dobj.getPrimaryFile());
}
示例3: instantiate
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
public Set<DataObject> instantiate() throws IOException {
FileObject targetFolder = Templates.getTargetFolder(wiz);
TestNGSupport.findTestNGSupport(FileOwnerQuery.getOwner(targetFolder)).configureProject(targetFolder);
String targetName = Templates.getTargetName(wiz);
DataFolder df = DataFolder.findFolder(targetFolder);
FileObject template = Templates.getTemplate(wiz);
DataObject dTemplate = DataObject.find(template);
String pkgName = getSelectedPackageName(targetFolder);
String suiteName = pkgName + " suite";
String projectName = ProjectUtils.getInformation(FileOwnerQuery.getOwner(targetFolder)).getName();
if (pkgName == null || pkgName.trim().length() < 1) {
pkgName = ".*"; //NOI18N
suiteName = "All tests for " + projectName;
}
Map<String, String> props = new HashMap<String, String>();
props.put("suiteName", projectName);
props.put("testName", suiteName);
props.put("pkg", pkgName);
DataObject dobj = dTemplate.createFromTemplate(df, targetName, props);
return Collections.singleton(dobj);
}
示例4: instantiate
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
@Override
public Set<?> instantiate() throws IOException {
// TODO: Use RequestProcessor for instantiation, this takes too much time.
String className = Templates.getTargetName(wizard);
FileObject pkg = Templates.getTargetFolder(wizard);
DataFolder targetFolder = DataFolder.findFolder(pkg);
FileObject templateFile = Templates.getTemplate(wizard);
DataObject templateDataObject = DataObject.find(templateFile);
DataObject createdDataObject = templateDataObject.createFromTemplate(targetFolder, className);
OpenCookie open = (OpenCookie) createdDataObject.getCookie(OpenCookie.class);
if (open != null) {
open.open();
}
return Collections.singleton(createdDataObject);
}
示例5: instantiate
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
@Override
public Set<?> instantiate() throws IOException {
// Create file from template
String targetName = Templates.getTargetName(wizard);
FileObject foDir = Templates.getTargetFolder(wizard);
FileObject foTemplate = Templates.getTemplate(wizard);
DataObject doTemplate = DataObject.find(foTemplate);
DataFolder df = DataFolder.findFolder(foDir);
Map<String, Object> props = new HashMap<>();
props.put(WIZ_BASE_INTERF, wizard.getProperty(WIZ_BASE_INTERF));
props.put(WIZ_ENTITY_CLASS, wizard.getProperty(WIZ_ENTITY_CLASS));
props.put(WIZ_ID_CLASS, wizard.getProperty(WIZ_ID_CLASS));
DataObject doCreated = doTemplate.createFromTemplate(df, targetName, props);
FileObject foCreated = doCreated.getPrimaryFile();
return Collections.singleton(foCreated);
}
示例6: createNbActions
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
private void createNbActions(String bootVersion, String pkg, String mvnName, FileObject dir) throws IOException {
// build main class string
StringBuilder mainClass = new StringBuilder(pkg);
mainClass.append('.')
.append(Character.toUpperCase(mvnName.charAt(0)))
.append(mvnName.substring(1))
.append("Application");
// retrieve default options from prefs
final Preferences prefs = NbPreferences.forModule(PrefConstants.class);
final boolean bForceColor = prefs.getBoolean(PREF_FORCE_COLOR_OUTPUT, true);
final boolean bManualRestart = prefs.getBoolean(PREF_MANUAL_RESTART, false);
final String strVmOpts = Utils.vmOptsFromPrefs();
// create nbactions.xml from template
FileObject foTmpl = Templates.getTemplate(wiz);
new FileBuilder(foTmpl, dir)
.name("nbactions")
.param("mainClass", mainClass.toString())
.param("forceColor", bForceColor)
.param("manualRestart", bManualRestart)
.param("isBoot2", bootVersion.startsWith("2"))
.param("vmOpts", strVmOpts)
.build();
}
示例7: createNbActions
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
private void createNbActions(FileObject dir) throws IOException {
// retrieve default options from prefs
final Preferences prefs = NbPreferences.forModule(PrefConstants.class);
final boolean bForceColor = prefs.getBoolean(PREF_FORCE_COLOR_OUTPUT, true);
final boolean bManualRestart = prefs.getBoolean(PREF_MANUAL_RESTART, false);
final String strVmOpts = Utils.vmOptsFromPrefs();
// compute name of devtools restart trigger file
String triggerFileEnv = BOOTVERSION.startsWith("2") ? SpringBootService.ENV_RESTART_20 : SpringBootService.ENV_RESTART_15;
// create nbactions.xml from template
FileObject foTmpl = Templates.getTemplate(wiz);
new FileBuilder(foTmpl, dir)
.name("nbactions")
.param("forceColor", bForceColor)
.param("manualRestart", bManualRestart)
.param("restartTriggerFileEnv", triggerFileEnv)
.param("vmOpts", strVmOpts)
.build();
}
示例8: instantiate
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
public Set<FileObject> instantiate() throws IOException {
Set<FileObject> mySet = new LinkedHashSet<FileObject>();
//create folders
File dirF = FileUtil.normalizeFile(new File((String) wiz.getProperty("folder")));
dirF.mkdirs();
//unzip file
FileObject template = Templates.getTemplate(wiz);
FileObject dir = FileUtil.toFileObject(dirF);
unZipFile(template.getInputStream(), dir);
// Always open top dir as a project:
mySet.add(dir);
File parent = dirF.getParentFile();
if (parent != null && parent.exists()) {
ProjectChooser.setProjectsFolder(parent);
}
return mySet;
}
示例9: instantiate
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
@Override
public Set<FileObject> instantiate() throws IOException {
if(!isUsedName()) {
FileObject pathDestinationFolder = ProjectUtils.getCurrentProject().getProjectDirectory();
File destinationFolder = new File(pathDestinationFolder.getPath() + "/" + getDestinationFolder());
if (!destinationFolder.isDirectory()) {
destinationFolder.mkdir();
}
FileObject template = Templates.getTemplate(wizard);
DataObject templateDataObject = DataObject.find(template);
FileObject targetFolder = ProjectUtils.getCurrentProject().getProjectDirectory().getFileObject(getDestinationFolder());
DataFolder targetFolderDataObject = DataFolder.findFolder(targetFolder);
DataObject createdDataFile = templateDataObject.createFromTemplate(targetFolderDataObject, getNewFileName(), getTemplateParameters());
FileObject createdFile = createdDataFile.getPrimaryFile();
if (getWithMetadataFile()) {
createMetadataFile(targetFolder);
}
return Collections.singleton(createdFile);
} else {
return Collections.EMPTY_SET;
}
}
示例10: instantiate
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
/**
* Returns set of instantiated objects. If instantiation fails then wizard
* remains open to enable correct values.
*
* @return A set of objects created (the exact type is at the discretion
* of the caller)
* @throws IOException In case of a failing I/O-operation.
*/
@Override
public Set<?> instantiate() throws IOException
{
FileObject template = Templates.getTemplate(wizard);
DataObject templateDO = DataObject.find(template);
FileObject targetFolder = Templates.getTargetFolder(wizard);
DataFolder targetFolderDF = DataFolder.findFolder(targetFolder);
String targetName = WizardUtils.toIdentifier(Templates.getTargetName(wizard));
Map<String, Object> args = getTemplateParameters();
DataObject createdTemplate = templateDO.createFromTemplate(targetFolderDF, targetName, args);
FileObject createdFile = createdTemplate.getPrimaryFile();
Boolean configureCustomProject = (Boolean) wizard.getProperty(AbstractWizardPanel.PROP_CONFIGURE_CUSTOM_PROJECT);
if( configureCustomProject == true )
{
WizardUtils.createTestsRootFolder(Templates.getProject(wizard));
}
return Collections.singleton(createdFile);
}
示例11: mapDataObjectsForPrimaryFiles
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
private Map<String, DataObject> mapDataObjectsForPrimaryFiles() throws IOException {
final FileObject firstTemplate = Templates.getTemplate(wizard);
final FileObject[] fileObjects = firstTemplate.getParent().getChildren();
final Map<String, String> mapTemplatesAndExtentions = new HashMap<>();
mapTemplatesAndExtentions.put(TEMPLATE_FILE__FXML, TEMPLATE_PARAMETER__FXML);
mapTemplatesAndExtentions.put(TEMPLATE_FILE__PRESENTER_JAVA, TEMPLATE_PARAMETER__PRESENTER);
mapTemplatesAndExtentions.put(TEMPLATE_FILE__VIEW_JAVA, TEMPLATE_PARAMETER__VIEW);
final Map<String, DataObject> mapDataObjects = new HashMap<>();
for (FileObject fileObject : fileObjects) {
if (mapTemplatesAndExtentions.containsKey(fileObject.getNameExt())) {
mapDataObjects.put(mapTemplatesAndExtentions.get(fileObject.getNameExt()), DataObject.find(fileObject));
}
}
return mapDataObjects;
}
示例12: instantiate
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
@Override
public Set/*<FileObject>*/ instantiate () throws IOException {
FileObject dir = Templates.getTargetFolder( wiz );
DataFolder df = DataFolder.findFolder( dir );
FileObject template = isFolder ? FileUtil.createMemoryFileSystem().getRoot() : Templates.getTemplate( wiz );
DataObject dTemplate = DataObject.find( template );
DataObject dobj = dTemplate.createFromTemplate( df, Templates.getTargetName( wiz ) );
return Collections.singleton (dobj.getPrimaryFile ());
}
示例13: instantiate
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
@Override
public Set<FileObject> instantiate() throws IOException {
getBottomPanel().save();
FileObject dir = Templates.getTargetFolder(wizard);
FileObject template = Templates.getTemplate(wizard);
DataFolder dataFolder = DataFolder.findFolder(dir);
DataObject dataTemplate = DataObject.find(template);
DataObject createdFile = dataTemplate.createFromTemplate(dataFolder, Templates.getTargetName(wizard));
return Collections.singleton(createdFile.getPrimaryFile());
}
示例14: instantiate
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
@Override public Set instantiate() throws java.io.IOException {
File projectLocation = (File) wiz.getProperty(WizardProperties.PROJECT_DIR);
String name = (String) wiz.getProperty(WizardProperties.NAME);
FileObject templateFO = Templates.getTemplate(wiz);
FileObject prjLoc = J2SESampleProjectGenerator.createProjectFromTemplate(
templateFO, projectLocation, name);
java.util.Set set = new java.util.HashSet();
set.add(DataObject.find(prjLoc));
// open file from the project specified in the "defaultFileToOpen" attribute
Object openFile = templateFO.getAttribute("defaultFileToOpen"); // NOI18N
if (openFile instanceof String) {
FileObject openFO = prjLoc.getFileObject((String)openFile);
set.add(DataObject.find(openFO));
}
// also open a documentation file registered for this project
// and copy the .url file for it to the project (#71985)
FileObject docToOpen = FileUtil.getConfigFile(
"org-netbeans-modules-java-examples/OpenAfterCreated/" + templateFO.getName() + ".url"); // NOI18N
if (docToOpen != null) {
docToOpen = FileUtil.copyFile(docToOpen, prjLoc, "readme"); // NOI18N
set.add(DataObject.find(docToOpen));
}
return set;
}
示例15: instantiate
import org.netbeans.spi.project.ui.templates.support.Templates; //导入方法依赖的package包/类
@Override
public Set<DataObject> instantiate () throws IOException/*, IllegalStateException*/ {
// Here is the default plain behavior. Simply takes the selected
// template (you need to have included the standard second panel
// in createPanels(), or at least set the properties targetName and
// targetFolder correctly), instantiates it in the provided
// position, and returns the result.
// More advanced wizards can create multiple objects from template
// (return them all in the result of this method), populate file
// contents on the fly, etc.
org.openide.filesystems.FileObject dir = Templates.getTargetFolder( wiz );
DataFolder df = DataFolder.findFolder( dir );
FileObject template = Templates.getTemplate( wiz );
DataObject dTemplate = DataObject.find( template );
final DataObject dobj = dTemplate.createFromTemplate( df, Templates.getTargetName( wiz ) );
//this part might be turned pluggable once we have also ant based osgi projects. if..
Project project = Templates.getProject( wiz );
ClassPath cp = ClassPath.getClassPath(dobj.getPrimaryFile(), ClassPath.SOURCE);
final String path = cp.getResourceName(dobj.getPrimaryFile(), '.', false);
final NbMavenProject prj = project.getLookup().lookup(NbMavenProject.class);
if (prj != null) {
Utilities.performPOMModelOperations(project.getProjectDirectory().getFileObject("pom.xml"),
Collections.<ModelOperation<POMModel>>singletonList(
new ModelOperation<POMModel>() {
@Override
public void performOperation(POMModel model) {
addActivator(prj, model, path);
}
}
));
}
return Collections.singleton(dobj);
}