* Updates all the designs stored in the given workspace to reflect the renaming.
* @param workspaceManager The workspace manager containing all the design the user wishes to update
* @return True if any designs were updated
*/
public boolean updateDesigns(WorkspaceManager workspaceManager) {
CALWorkspace workspace = workspaceManager.getWorkspace();
List<Pair<GemDesign, Document>> undoList = new ArrayList<Pair<GemDesign, Document>>(); // A list of designs that have been updated and should be undone if an error is encountered.
try {
ModuleName[] workspaceModuleNames = workspaceManager.getModuleNamesInProgram();
// loop through each module in the workspace
for (final ModuleName moduleName : workspaceModuleNames) {
if (workspace.getMetaModule(moduleName) == null) {
// the program contains the module but the workspace doesn't, so we cannot process it
continue;
}
ModuleNameResolver moduleNameResolver = workspaceManager.getModuleTypeInfo(moduleName).getModuleNameResolver();
GemDesignManager designManager = (GemDesignManager)workspace.getResourceManager(moduleName, WorkspaceResource.GEM_DESIGN_RESOURCE_TYPE);
// loop through the resources for this module
for (Iterator<WorkspaceResource> it = ((GemDesignStore)designManager.getResourceStore()).getResourceIterator(moduleName); it.hasNext(); ) {
WorkspaceResource designResource = it.next();
GemDesign gemDesign = GemDesign.loadGemDesign(designResource, new Status("Load Design Status"));
Document designDoc = gemDesign.getDesignDocument();
Document oldDesignDoc = (Document)designDoc.cloneNode(true);
boolean changesMade = updateDesignDocument(designDoc, gemDesign.getDesignName(), moduleNameResolver);
if (changesMade) {
if (!designManager.getResourceStore().isWriteable(new ResourceName(CALFeatureName.getFunctionFeatureName(gemDesign.getDesignName())))) {
throw new RenamingException("Can not update the design for " + gemDesign.getDesignName().getQualifiedName() + " because it is not writeable.");
}
Status saveGemStatus = new Status("Save gem design status");
workspace.saveDesign(gemDesign, saveGemStatus);
if (saveGemStatus.getSeverity().equals(Status.Severity.ERROR)) {
throw new RenamingException("Error saving the updated design for " + gemDesign.getDesignName().getQualifiedName() + ".");
}
undoList.add(new Pair<GemDesign, Document>(gemDesign, oldDesignDoc));
}
}
}
// Return true if the undoList has contents (ie. changes have been made)
return !undoList.isEmpty();
} catch (RenamingException e) {
status.add(new Status(Status.Severity.ERROR, e.getErrorMessage()));
for (int i = undoList.size() - 1; i >= 0; i--) {
Pair<GemDesign, Document> designDocPair = undoList.get(i);
GemDesign gemDesign = designDocPair.fst();
Document oldDesignDoc = designDocPair.snd();
replaceDocumentChildren(gemDesign.getDesignDocument(), oldDesignDoc);
Status undoStatus = new Status("Undo design update status");
workspace.saveDesign(gemDesign, undoStatus);
if (undoStatus.getSeverity().equals(Status.Severity.ERROR)) {
String msg = "FATAL: Error undoing the design update for " + gemDesign.getDesignName().getQualifiedName();
status.add(new Status(Status.Severity.ERROR, msg));
}