NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
remcollier
Joined: 17 Oct 2008 Posts: 7 Location: Dublin, Ireland
|
Posted: Wed Nov 12, 2008 11:46 am Post subject: Creating a file from a template in the project instantiate() method |
|
|
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.
|
Posted: Wed Nov 12, 2008 11:50 am Post subject: Creating a file from a template in the project instantiate() method |
|
|
| hiyou can use |
|
| Back to top |
|
 |
remcollier
Joined: 17 Oct 2008 Posts: 7 Location: Dublin, Ireland
|
Posted: Wed Nov 12, 2008 1:21 pm Post subject: |
|
|
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 |
|
 |
|
|
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
|
|