Search in sources :

Example 1 with WindowSystem

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();
                    }
                });
            }
        }
    });
}
Also used : WindowSystem(org.netbeans.core.WindowSystem) JFrame(javax.swing.JFrame) Frame(java.awt.Frame) WindowManagerImpl(org.netbeans.core.windows.WindowManagerImpl) ModeImpl(org.netbeans.core.windows.ModeImpl) RetainLocation(org.openide.windows.RetainLocation) IOException(java.io.IOException) TopComponentGroup(org.openide.windows.TopComponentGroup) TopComponentGroupImpl(org.netbeans.core.windows.TopComponentGroupImpl) RegistryImpl(org.netbeans.core.windows.RegistryImpl) FileObject(org.openide.filesystems.FileObject) TopComponent(org.openide.windows.TopComponent)

Example 2 with WindowSystem

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();
}
Also used : WindowSystem(org.netbeans.core.WindowSystem)

Aggregations

WindowSystem (org.netbeans.core.WindowSystem)2 Frame (java.awt.Frame)1 IOException (java.io.IOException)1 JFrame (javax.swing.JFrame)1 ModeImpl (org.netbeans.core.windows.ModeImpl)1 RegistryImpl (org.netbeans.core.windows.RegistryImpl)1 TopComponentGroupImpl (org.netbeans.core.windows.TopComponentGroupImpl)1 WindowManagerImpl (org.netbeans.core.windows.WindowManagerImpl)1 FileObject (org.openide.filesystems.FileObject)1 RetainLocation (org.openide.windows.RetainLocation)1 TopComponent (org.openide.windows.TopComponent)1 TopComponentGroup (org.openide.windows.TopComponentGroup)1