/**
* Removes a workspace from the system
*/
public void delete(final WorkspaceImpl workspace) throws Exception {
HibernateTxFragment txFragment = new HibernateTxFragment() {
protected void txFragment(Session session) throws Exception {
//Delete own resources
GraphicElementManager[] managers = UIServices.lookup().getGraphicElementManagers();
for (int i = 0; i < managers.length; i++) {
GraphicElementManager manager = managers[i];
GraphicElement[] elements = manager.getElements(workspace.getId());
for (int j = 0; j < elements.length; j++) {
GraphicElement element = elements[j];
manager.delete(element);
}
}
// Remove attached workspace permissions.
Policy policy = SecurityServices.lookup().getSecurityPolicy();
policy.removePermissions(workspace);
// Notify instances removal before deleting workspace.
Iterator instanceIt = workspace.getPanelInstancesSet().iterator();
while (instanceIt.hasNext()) {
PanelInstance instance = (PanelInstance) instanceIt.next();
instance.instanceRemoved(session);
}
// Notify panels before deleting workspace.
Iterator sectionIt = workspace.getSections().iterator();
while (sectionIt.hasNext()) {
Section section = (Section) sectionIt.next();
Panel[] panels = section.getAllPanels();
for (int i = 0; i < panels.length; i++) {
Panel panel = panels[i];
panel.getProvider().getDriver().fireBeforePanelRemoved(panel);
panel.panelRemoved();
}
}
policy.save();
// Delete workspace.
session.delete(workspace);
session.flush();
// Notify workspace removal
fireWorkspaceRemoved(workspace);
}
};
txFragment.execute();
}