Extending : Multi-project support in Extension : Project prefix : APIs to handle project prefix
  
APIs to handle project prefix
For an extended widget, if its attribute refers resource in another project, the widget implementation needs to handle project prefix to locate the resource. UNICOM® Digital Transformation Toolkit (UDTT™) provides two APIs for technical developers to handle project prefix.
IProject FilePathUtil.getProjecByResourceID(String resourceID, IProject activeProject)
The API returns project which resource locates according to resourceID, if resourceID does not contain project prefix, the activeProject will be returned. If the project map key is not defined in the UDTT configuration file, “IllegalArgumentException” exception is thrown.
String FilePathUtil.getValueByResourceID(String resourceID)
The API returns resource without project prefix.
Example
The following sample code demonstrates how to retrieve icon file from global project.
try{
IProject imageProject = FilePathUtil.getProjecByResourceID(imageLocation,EditorUtils.getActiveProject())
String imageRelativeLocation = FilePathUtil.getValueByResourceID(imageLocation);
IFile imageFile = imageProject.getFile(imageRelativeLocation);
}
catch(IllegalArgumentException ie){
// handle map key is not defined exception
}
The following sample code demonstrates how to retrieve NLS definition from global project.
try{
IProject selectedProject = FilePathUtil.getProjecByResourceID(nlsLocation,EditorUtils.getActiveProject())
String nlsTextField = getValueByResourceID(nlsLocation);
String nlsValue = NLSUtils.getPropertiesValue(nlsTextField,selectedProject);
}
catch(IllegalArgumentException ie){
// handle map key is not defined exception
}
Go up to
Project prefix