use of org.netbeans.core.WindowSystem in project netbeans-rcp-lite by outersky.
the class ResetWindowsAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
final WindowSystem ws = Lookup.getDefault().lookup(WindowSystem.class);
if (null == ws) {
// unsupported window system implementation
Logger.getLogger(ResetWindowsAction.class.getName()).log(Level.INFO, // NOI18N
"Reset Windows action does not support custom WindowSystem implementations.");
return;
}
final WindowManagerImpl wm = WindowManagerImpl.getInstance();
// cancel full-screen mode
MainWindow.getInstance().setFullScreenMode(false);
wm.getMainWindow().setExtendedState(JFrame.NORMAL);
// NOI18N
TopComponentGroupImpl projectTCGroup = (TopComponentGroupImpl) wm.findTopComponentGroup("OpenedProjects");
final boolean isProjectsTCGroupOpened = null != projectTCGroup && projectTCGroup.isOpened();
// get a list of editor windows that should stay open even after the reset
final TopComponent[] editors = collectEditors();
// close all other windows just in case they hold some references to editor windows
wm.closeNonEditorViews();
// hide the main window to hide some window operations before the actual reset is performed
wm.getMainWindow().setVisible(false);
// find an editor window that will be activated after the reset (may be null)
final TopComponent activeEditor = wm.getArbitrarySelectedEditorTopComponent();
// make sure that componentHidden() gets called on all opened and selected editors
// so that they can reset their respective states and/or release some listeners
wm.deselectEditorTopComponents();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// find the local folder that must be deleted
try {
FileObject rootFolder = PersistenceManager.getDefault().getRootLocalFolder();
if (reset && null != rootFolder) {
for (FileObject fo : rootFolder.getChildren()) {
if (PersistenceManager.COMPS_FOLDER.equals(fo.getName()))
// do not delete settings files
continue;
fo.delete();
}
}
} catch (IOException ioE) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioE);
}
// reset the window system
ws.hide();
WindowManagerImpl.getInstance().resetModel();
// keep mappings to TopComponents created so far
PersistenceManager.getDefault().reset();
PersistenceHandler.getDefault().clear();
ws.load();
ws.show();
if (isProjectsTCGroupOpened) {
// NOI18N
TopComponentGroup tcGroup = wm.findTopComponentGroup("OpenedProjects");
if (null != tcGroup)
tcGroup.open();
}
// NOI18N
ModeImpl editorMode = (ModeImpl) wm.findMode("editor");
RegistryImpl registry = (RegistryImpl) TopComponent.getRegistry();
// re-open editor windows that were opened before the reset
for (int i = 0; i < editors.length && null != editorMode; i++) {
ModeImpl mode = (ModeImpl) wm.findMode(editors[i]);
if (null == mode) {
RetainLocation retainLocation = editors[i].getClass().getAnnotation(RetainLocation.class);
if (null != retainLocation) {
String preferedModeName = retainLocation.value();
mode = (ModeImpl) wm.findMode(preferedModeName);
}
}
if (null == mode) {
mode = editorMode;
}
if (null != mode)
mode.addOpenedTopComponentNoNotify(editors[i]);
// #210380 - do not call componentOpened on the editors
registry.addTopComponent(editors[i]);
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Frame mainWindow = wm.getMainWindow();
mainWindow.invalidate();
mainWindow.repaint();
}
});
// activate some editor window
if (null != activeEditor) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
activeEditor.requestActive();
}
});
}
}
});
}
use of org.netbeans.core.WindowSystem in project netbeans-rcp-lite by outersky.
the class Utilities method resetTabbedContainers.
public static void resetTabbedContainers() {
WindowSystem ws = Lookup.getDefault().lookup(WindowSystem.class);
ws.hide();
ws.show();
}
Aggregations