HibernateTxFragment txFragment = new HibernateTxFragment() {
protected void txFragment(Session session) throws Exception {
newPanel.setInstance(instance);
newPanel.setSection(section);
Layout layout = section.getLayout();
if (layout != null)
newPanel.getProvider().getDriver().fireBeforePanelPlacedInRegion(newPanel, layout.getRegion(region));
newPanel.setLayoutRegionId(region);
UIServices.lookup().getPanelsManager().store(newPanel);
// Assign panel & save changes
section.assignPanel(newPanel, region);
if (position != -1) {
SectionRegion sr = newPanel.getSection().getSectionRegion(region);
int maxLoops = 30;
while (newPanel.getPosition() != position && (maxLoops--) > 0) {
if (newPanel.getPosition() > position)
sr.moveBackInRegion(newPanel);
else
sr.moveForwardInRegion(newPanel);
}
}
UIServices.lookup().getSectionsManager().store(section);
newPanel.getProvider().getDriver().fireAfterPanelPlacedInRegion(newPanel, null);
hideModalDialog();
}
};
txFragment.execute();
} else {
log.error("Instance with id <" + id + "> not found in current workspace. Cannot put panel to region " + region);
log.error("Also, provider with id <" + id + "> is not found in current installation.");
}
} else {//Create new instance and new panel, provider is given in id.
final PanelInstance newInstance = new PanelInstance();
HibernateTxFragment txFragment = new HibernateTxFragment() {
protected void txFragment(Session session) throws Exception {
newInstance.setProvider(provider);
newInstance.setWorkspace(workspace);
Locale[] locales = (LocaleManager.lookup()).getPlatformAvailableLocales();
for (int i = 0; i < locales.length; i++) {
Locale locale = locales[i];
String panelTitle = provider.getResource(provider.getDescription(), locale);
if (panelTitle != null)
newInstance.setTitle(StringEscapeUtils.unescapeHtml(panelTitle), locale.toString());
}
// Add instance to workspace
workspace.addPanelInstance(newInstance);
UIServices.lookup().getPanelsManager().store(newInstance);
// Initialize panel (after creation)
newInstance.init();
// Save changes
UIServices.lookup().getWorkspacesManager().store(workspace);
final Panel newPanel = new Panel();
newPanel.setInstance(newInstance);
newPanel.setSection(section);
Layout layout = section.getLayout();
if (layout != null)
newPanel.getProvider().getDriver().fireBeforePanelPlacedInRegion(newPanel, layout.getRegion(region));
newPanel.setLayoutRegionId(region);
UIServices.lookup().getPanelsManager().store(newPanel);
// Assign panel & save changes
section.assignPanel(newPanel, region);