|
……
<nature>org.eclipse.jdt.core.javanature</nature>
……
|
-
Workspace下有多个工程,如何知道哪个工程是需要缓存实体信息的?
-
何时执行缓存动作?何时销毁缓存?
|
<extension
point="org.eclipse.core.resources.natures"
id="entityNature"
name="Entity Nature">
<runtime>
<run class="com.company.natures.EntityNature">
</run>
</runtime>
</extension>
|

|
publicvoid 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();
}
}
|
|
publicboolean hasEntityNature(IProject project){
try {
return project.hasNature(“com.company.natures.entityNature”);
} catch (CoreException e) {
e.printStackTrace();
}
returnfalse;
}
|
|
<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>
|
|
publicvoid 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();
}
}
|
- natureIds中所有的nature已经被注册
- natureIds中所有nature依赖的nature已经包含在natureIds中
- natureIds中所有nature之间没有循环依赖关系
- natureIds中没有重复的nature
|
IProjectNatureDescriptor descriptor = workspace.getNatureDescriptor( "com.example.natures.myOtherNature" );
|
|
IProjectNatureDescriptor[] descriptors = workspace.getNatureDescriptors();
|
315




被折叠的 条评论
为什么被折叠?



