use of org.pentaho.mantle.client.events.SolutionBrowserCloseEvent in project pentaho-platform by pentaho.
the class MantleTabPanel method closeTab.
public void closeTab(final PentahoTab closeTab, final boolean invokePreTabCloseHook) {
if (closeTab.getContent() instanceof IFrameTabPanel) {
final Element frameElement = ((IFrameTabPanel) closeTab.getContent()).getFrame().getElement();
String frameId = frameElement.getAttribute("id").replaceAll("\"", "\\\"");
// #a"b1494409287116 need to be escaped to #a\"b1494409287116.
if (frameId.indexOf("\"") != -1) {
frameId = frameId.replaceAll("\"", "");
frameElement.setAttribute("id", frameId);
}
final String finalFrameId = frameId;
if (invokePreTabCloseHook && hasUnsavedChanges(frameElement)) {
// prompt user
VerticalPanel vp = new VerticalPanel();
// $NON-NLS-1$
vp.add(new Label(Messages.getString("confirmTabClose")));
final PromptDialogBox confirmDialog = new PromptDialogBox(Messages.getString("confirm"), Messages.getString("yes"), Messages.getString("no"), false, true, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
vp);
confirmDialog.setCallback(new IDialogCallback() {
public void cancelPressed() {
}
public void okPressed() {
fireCloseTab(finalFrameId);
((CustomFrame) ((IFrameTabPanel) closeTab.getContent()).getFrame()).removeEventListeners(frameElement);
clearClosingFrame(frameElement);
MantleTabPanel.super.closeTab(closeTab, invokePreTabCloseHook);
if (getTabCount() == 0) {
allTabsClosed();
Widget selectTabContent = null;
if (getTab(getSelectedTabIndex()) != null) {
selectTabContent = getTab(getSelectedTabIndex()).getContent();
}
List<FileItem> selectedItems = SolutionBrowserPanel.getInstance().getFilesListPanel().getSelectedFileItems();
EventBusUtil.EVENT_BUS.fireEvent(new SolutionBrowserCloseEvent(selectTabContent, selectedItems));
}
}
});
confirmDialog.center();
return;
}
fireCloseTab(finalFrameId);
((CustomFrame) ((IFrameTabPanel) closeTab.getContent()).getFrame()).removeEventListeners(frameElement);
clearClosingFrame(frameElement);
}
super.closeTab(closeTab, invokePreTabCloseHook);
// since we can't entirely reclaim the frame resources held, keep some around
// so we can minimize the extra leakage caused by constantly created more
// let's only keep 5 of these guys around so at least some of the resources
// can be cleaned up (maybe just wishful thinking)
Widget w = closeTab.getContent();
if (w instanceof IFrameTabPanel && freeFrames.size() < 5) {
// wipe out any file info so it doesn't impact future usages of this frame
SolutionFileInfo sfi = null;
IFrameTabPanel iFrameTabPanel = (IFrameTabPanel) w;
iFrameTabPanel.setFileInfo(sfi);
freeFrames.add(iFrameTabPanel);
}
if (getTabCount() == 0) {
allTabsClosed();
Widget selectTabContent = null;
if (getTab(getSelectedTabIndex()) != null) {
selectTabContent = getTab(getSelectedTabIndex()).getContent();
}
List<FileItem> selectedItems = SolutionBrowserPanel.getInstance().getFilesListPanel().getSelectedFileItems();
EventBusUtil.EVENT_BUS.fireEvent(new SolutionBrowserCloseEvent(selectTabContent, selectedItems));
}
}
Aggregations