Home » Eclipse Projects » Eclipse Platform » Creating Project with a Nature
Creating Project with a Nature [message #272996] |
Wed, 29 September 2004 14:48  |
Eclipse User |
|
|
|
Originally posted by: barlock.usx.ibmx.com
I have some code that includes this snippet:
String[] prevNatures = description.getNatureIds();
String[] newNatures = new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length] = TMNature.ID;
description.setNatureIds(newNatures);
// Create the new project operation.
final IProject projectHandle = project;
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
protected void execute(IProgressMonitor monitor) throws
CoreException {
createNewProject(projectHandle, description, monitor);
}
};
// Run the new project creation operation. If either exception
// occurs, we return a null project to indicate the operation was
// cancelled.
try {
context.run(true, true, op);
}
I've discovered that if I move the code that adds TMNature.ID to some place
after the project creation, the project no longer behaves as expected once
it is created. For example, it just doesn't appear at all in certain
perspectives and it may or may not have the corrrect projectNatureImage. I
do know that if I move this code, I have to set the description back in the
project with:
project.setDescription(description, null);
So, if I want the nature-setting code elsewhere (I'm thinking of a common
method to create a basic project, which can be augmented with one or more
natures later), what API call(s) do I need to add to let all interested
parties in the UI know about the new natures?
Chris
|
|
|
Re: Creating Project with a Nature [message #273300 is a reply to message #272996] |
Mon, 04 October 2004 06:24  |
Eclipse User |
|
|
|
Originally posted by: ian.hartney.gmail.com
This is my entrie project creation code... it seem to work fine. Hope it
helps.
Ian Hartney.
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
if (monitor == null) {
monitor= new NullProgressMonitor();
}
try {
monitor.beginTask("Creating Project",2);
IWorkspaceRoot root= ecletexPlugin.getWorkspace().getRoot();
for (int i= 0; i < fPages.length; i++) {
createProject(root, fPages[i], new SubProgressMonitor(monitor, 1));
}
} finally {
monitor.done();
}
}
private void createProject(IWorkspaceRoot root,
ecletexProjectCreationWizardPage page, IProgressMonitor monitor) throws
InvocationTargetException, InterruptedException {
monitor.beginTask("Creating Project Directory", 1);
String name= page.getName();
try {
IProject project = root.getProject(name);
if (!project.exists()) {
project.create(null);
}
if (!project.isOpen()) {
project.open(null);
}
IProjectDescription desc= project.getDescription();
String[] natures = desc.getNatureIds();
String[] newNatures = new String[natures.length+1];
System.arraycopy(natures,0,newNatures,1,natures.length);
newNatures[0] = "ish.ecletex.ecletexNature";
desc.setNatureIds(newNatures);
ICommand[] commands = desc.getBuildSpec();
ICommand command = desc.newCommand();
command.setBuilderName("ish.ecletex.ecletexBuilder");
ICommand[] newCommands = new ICommand[commands.length+1];
System.arraycopy(commands,0,newCommands,1,commands.length);
newCommands[0]= command;
desc.setBuildSpec(newCommands);
project.setDescription(desc, new SubProgressMonitor(monitor, 1));
project.setPersistentProperty(new QualifiedName("ish.ecletex",
ecletexProjectProperties.MAINFILE_PROPERTY),page.getMainFile ());
project.setPersistentProperty(
new QualifiedName("ish.ecletex",
ecletexProjectProperties.BIBTEX_COMPLIER_ACTION_PROPERTY),
ecletexProjectProperties.DEFAULT_BIBTEX_COMPLIER_ACTION);
project.setPersistentProperty(
new QualifiedName("ish.ecletex",
ecletexProjectProperties.PS_ACTION_PROPERTY),
ecletexProjectProperties.DEFAULT_PS_ACTION);
if(ecletexProjectProperties.DEFAULT_PDF_ACTION.equals(eclete xProjectProperties.CHECKED))
project.setPersistentProperty(
new QualifiedName("ish.ecletex",
ecletexProjectProperties.PS_ACTION_PROPERTY),
ecletexProjectProperties.DEFAULT_PDF_ACTION);
project.setPersistentProperty(
new QualifiedName("ish.ecletex",
ecletexProjectProperties.PDF_ACTION_PROPERTY),
ecletexProjectProperties.DEFAULT_PDF_ACTION);
//project.setPersistentProperty(
// new QualifiedName("ish.ecletex",
ecletexProjectProperties.DICTIONARY_PROPERTY),
ecletexProjectProperties.DEFAULT_DICTIONARY);
IPath projectDir = new Path(ProjectUtils.getProjectDir(project));
IPath mainFile = projectDir.append(page.getMainFile());
System.out.println("Creating: "+mainFile.toOSString());
File f= new File(mainFile.toOSString());
try{
f.createNewFile();
}catch(IOException ex){
System.out.println(ex.toString());
}
project.refreshLocal(IProject.DEPTH_INFINITE, null);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
"Chris Barlock" <barlock@usx.ibmx.com> wrote in message
news:cjevo4$7mo$1@eclipse.org...
>I have some code that includes this snippet:
>
> String[] prevNatures = description.getNatureIds();
> String[] newNatures = new String[prevNatures.length + 1];
> System.arraycopy(prevNatures, 0, newNatures, 0,
> prevNatures.length);
> newNatures[prevNatures.length] = TMNature.ID;
> description.setNatureIds(newNatures);
>
> // Create the new project operation.
> final IProject projectHandle = project;
> WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
> protected void execute(IProgressMonitor monitor) throws
> CoreException {
> createNewProject(projectHandle, description, monitor);
> }
> };
>
> // Run the new project creation operation. If either exception
> // occurs, we return a null project to indicate the operation was
> // cancelled.
> try {
> context.run(true, true, op);
> }
>
> I've discovered that if I move the code that adds TMNature.ID to some
> place
> after the project creation, the project no longer behaves as expected once
> it is created. For example, it just doesn't appear at all in certain
> perspectives and it may or may not have the corrrect projectNatureImage.
> I
> do know that if I move this code, I have to set the description back in
> the
> project with:
>
> project.setDescription(description, null);
>
> So, if I want the nature-setting code elsewhere (I'm thinking of a common
> method to create a basic project, which can be augmented with one or more
> natures later), what API call(s) do I need to add to let all interested
> parties in the UI know about the new natures?
>
> Chris
>
>
|
|
|
Goto Forum:
Current Time: Fri May 16 15:52:02 EDT 2025
Powered by FUDForum. Page generated in 0.03203 seconds
|