}
}
public static void insertLinkBefore(IProject project, IPath newSource, IPath referenceSource, IPath runtimePath, IProgressMonitor monitor) throws CoreException {
//Looks like WTP'APIS doesn't have such feature, hence this implementation.
StructureEdit moduleCore = null;
try {
moduleCore = StructureEdit.getStructureEditForWrite(project);
if (moduleCore == null) {
return;
}
WorkbenchComponent component = moduleCore.getComponent();
if (component == null) {
return;
}
int i = 0;
int refPosition = -1;
int newSourcePosition = -1;
List<ComponentResource> resources = component.getResources();
for (ComponentResource resource : resources) {
IPath sourcePath = resource.getSourcePath();
if (referenceSource.equals(sourcePath)) {
refPosition = i;
} else if (newSource.equals(sourcePath)) {
newSourcePosition = i;
}
if (refPosition > -1 && newSourcePosition > -1) {
break;
}
i++;
}
if (refPosition < 0) {
refPosition = i;
}
IResource folder = project.getFolder(newSource);
if (newSourcePosition > refPosition) {
component.getResources().move(newSourcePosition, refPosition);
} else if (newSourcePosition < 0) {
ComponentResource componentResource = moduleCore.createWorkbenchModuleResource(folder);
componentResource.setRuntimePath(runtimePath);
component.getResources().add(refPosition,componentResource);
}
}
finally {
if (moduleCore != null) {
moduleCore.saveIfNecessary(monitor);
moduleCore.dispose();
}
}
}