……
<nature>org.eclipse.jdt.core.javanature</nature>
……
|
<extension
point="org.eclipse.core.resources.natures"
id="entityNature"
name="Entity Nature">
<runtime>
<run class="com.company.natures.EntityNature">
</run>
</runtime>
</extension>
|
public
void
setEntityNature(IProject project){
try
{
IProjectDescription description = project.getDescription();
String[] natures = description.getNatureIds();
String[] newNatures =
new
String[natures.
length
+ 1];
System.arraycopy(natures, 0, newNatures, 0, natures.
length
);
newNatures[natures.
length
] =
"com.company.natures.entityNature"
;
description.setNatureIds(newNatures);
project.setDescription(description,
null
);
}
catch
(CoreException e) {
e.printStackTrace();
}
}
|
public
boolean
hasEntityNature(IProject project){
try
{
return
project.hasNature(“
com.company.natures.entityNature
”);
}
catch
(CoreException e) {
e.printStackTrace();
}
return
false
;
}
|
<extension
point="org.eclipse.core.resources.natures"
id="entityNature"
name="Entity Nature">
<runtime>
<run class="com.company.natures.EntityNature">
</run>
</runtime>
<requires-nature id="org.eclipse.jdt.core.javanature"/>
</extension>
|
public
void
setEntityNatureWithValidate(IProject project,Workspace workspace){
try
{
IProjectDescription description = project.getDescription();
String[] natures = description.getNatureIds();
String[] newNatures =
new
String[natures.
length
+ 1];
System.arraycopy(natures, 0, newNatures, 0, natures.
length
);
newNatures[natures.
length
] =
"com.company.natures.entityNature"
;
IStatus status = workspace.validateNatureSet(natures);
if
(status.getCode() == IStatus.
OK
) {
//check
description.setNatureIds(newNatures);
project.setDescription(description,
null
);
}
else
{
//
TODO
提醒用户
}
description.setNatureIds(newNatures);
project.setDescription(description,
null
);
}
catch
(CoreException e) {
e.printStackTrace();
}
}
|
IProjectNatureDescriptor descriptor = workspace.getNatureDescriptor( "com.example.natures.myOtherNature" );
|
IProjectNatureDescriptor[] descriptors = workspace.getNatureDescriptors();
|