Nature [message #514238] |
Fri, 12 February 2010 23:16 |
NH Messages: 14 Registered: December 2009 |
Junior Member |
|
|
Can anybody tell me why my nature setproject() for
configure methods() programs wont get called. The .project is being created without any errors and the natures are enabled in the workspace. I out a bit of a loss here but just can see what is going wrong.
I've attach the following bits of code
#1 plugin xml
#2 Nature defined
#3 wizard code
#4 ,project created
Or does anybody have a complete set of code
which creates a . project file where the only thing that needs to be created is the .project file( I can created the folders etc) that call the configure() method. I will need this for a builder later!!!!
#1 plugin code
____________________
<extension
id="com.eclipse.poitin.nature.YoNature"
name="YoNature"
point="org.eclipse.core.resources.natures">
<runtime>
<run
class="com.eclipse.poitin.nature.YoNature">
</run>
</runtime>
</extension>
#2 Nature Defined
__________________________________
package com.eclipse.poitin.nature;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;
public class YoNature implements IProjectNature {
private IProject project;
public static final String NATURE_ID = "com.eclipse.poitin.nature.YoNature";
public void configure() throws CoreException {
System.out.println("configure added");
}
public void deconfigure() throws CoreException {
System.out.println("nature deconfigure");
}
public IProject getProject() {
// TODO Auto-generated method stub
System.out.println("in yo nature getProject");
return project;
}
public void setProject(IProject project) {
System.out.println("in yo nature setproject");
this.project = project;
}
}
#3 Wizard Code
package com.eclipse.poitin.wizards;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
import com.eclipse.poitin.nature.YoNature;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProjectNatureDescriptor;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
public class YoWizard extends Wizard implements INewWizard {
private WizardNewProjectCreationPage MyPageOne;
public YoWizard() {
// TODO Auto-generated constructor stub
}
public void addPages(){
super.addPages();
setWindowTitle("Wizard to add Poitin Project");
MyPageOne = new WizardNewProjectCreationPage("Project Page");
addPage(MyPageOne);
System.out.println("IS PAGE COMPLETE1 - " + MyPageOne.isPageComplete());
}
@Override
public boolean performFinish() {
try {
getContainer()
.run(false, true, new WorkspaceModifyOperation() {
protected void execute(IProgressMonitor monitor) {
createProject(monitor != null
? monitor
: new NullProgressMonitor());
}
});
} catch(Exception x) {
// EIALogger.printToLog(x);
return false;
}
return true;
}
protected void createProject(IProgressMonitor monitor) {
monitor.beginTask("Creates new project.", 50 );
try{
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = ResourcesPlugin
.getWorkspace()
.getRoot();
IProject project = root.getProject(MyPageOne
.getProjectName());
IProjectDescription description = ResourcesPlugin
.getWorkspace()
.newProjectDescription(
project.getName());
if( !Platform.getLocation().equals(MyPageOne.getLocationPath()) )
description.setLocation(MyPageOne.getLocationPath());
String[] natures = description.getNatureIds();
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
newNatures[natures.length] = YoNature.NATURE_ID;
IStatus status = workspace.validateNatureSet(natures);
IProjectNatureDescriptor descriptor = workspace.getNatureDescriptor(YoNature.NATURE_ID);
if (status.getCode() == IStatus.OK) {
System.out.println("nature is cool]");
description.setNatureIds(newNatures);
description.setComment("Setting Comment Works");
//description.setName("Setting the name works");
System.out.println("Description setting was fine");
System.out.println("Descriptor :" + descriptor);
}
project.create(description, null);
project.open(null);
project.setDescription(description,monitor);
project.close(null);
}
catch(Exception x) {
System.out.println(x);
} finally {
monitor.done();
}
}
private void createFolderHelper (IFolder folder, IProgressMonitor monitor)
{
try {
if(!folder.exists()) {
IContainer parent = folder.getParent();
if(parent instanceof IFolder
&& (!((IFolder)parent).exists())) {
createFolderHelper((IFolder)parent, monitor);
}
folder.create(false,true,monitor);
}
// here in at the end..
} catch (Exception e) {
// EIALogger.printToLog(e);
}
}
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
// TODO Auto-generated method stub
}
}
#4 .project file created, but System.out.println arent being called!!!!!!!!!!!!!!!!!!!!
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>zzzzzzzzzz</name>
<comment>Setting Comment Works</comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
<nature>com.eclipse.poitin.nature.PoitinNature</nature>
</natures>
</projectDescription>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03874 seconds