NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Creating a file from a template in the project instantiate() method

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users
View previous topic :: View next topic  
Author Message
remcollier



Joined: 17 Oct 2008
Posts: 7
Location: Dublin, Ireland

PostPosted: Wed Nov 12, 2008 11:46 am    Post subject: Creating a file from a template in the project instantiate() method Reply with quote

Hi,

I am trying to modify the default project type wizard so that I can allow the user to decide whether two specific files are created when a project is created (basically the files are called default.cfg and default.aps).

What is the recommended way for doing this, I have modified the panel and updated the store() and read() methods so that the necessary information is in the wizard properties. I know how to access those properties in the instantiate() method, but how do I create the files.

I have default versions of these files set up as Templates, but cannot find any static methods on the Templates class that allow me to retrieve a reference to these files?
Back to top
hamada ahmed
Posted via mailing list.





PostPosted: Wed Nov 12, 2008 11:50 am    Post subject: Creating a file from a template in the project instantiate() method Reply with quote

hiyou can use
Back to top
remcollier



Joined: 17 Oct 2008
Posts: 7
Location: Dublin, Ireland

PostPosted: Wed Nov 12, 2008 1:21 pm    Post subject: Reply with quote

Okay, so I found a solution myself, I don't know if it is the best, but here it is...

if ((Boolean) wiz.getProperty("createCFGFile")) {
String cfg = (String) wiz.getProperty("cfg");
if ((Boolean) wiz.getProperty("useDefaultCFG")) {
cfg = "default.cfg";
}
FileObject srcDir = dir.getFileObject("src");

// set relDFolder to be the src folder...
DataFolder relDFolder = DataFolder.findFolder(srcDir);

// Check the file name and update relDFolder is the file name
// includes a relative path
int index = cfg.lastIndexOf("/");
if (index > -1) {
FileObject relFolder = dir.createFolder(cfg.substring(0,index));
relDFolder = DataFolder.findFolder(relFolder);
cfg = cfg.substring(index+1);
}

// strip off the extension if it is there...
if (cfg.endsWith(".cfg")) {
cfg = cfg.substring(0, cfg.length()-4);
}

// get the template
FileObject tplate = Repository.getDefault().getDefaultFileSystem().findResource( "Templates/Agent_Factory/CFGTemplate.cfg" );
DataObject dTemplate = DataFolder.find(tplate);
try {
dTemplate.createFromTemplate(relDFolder, cfg);
} catch (StringIndexOutOfBoundsException ex) {
// DO NOTHING - This seems to be a framework problem...
// The template creation method looks for a package???
}
}

The try...catch is placed around the createFromTemplate method due to an exception I have been getting in NB6.1 - this problem arises with objects that are based on the Generic Languages Framework - the creation methods throw an exception when the getPackage(...) method of LangaugesDataObject is called (and i've no idea why).

I've logged the above issue as a bug, but maybe somebody knows why it is not working (it works with some projects and not others).
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo