1 19 20 package org.netbeans.core.windows.actions; 21 22 import java.awt.event.ActionEvent ; 23 import java.io.IOException ; 24 import javax.swing.AbstractAction ; 25 import javax.swing.JFrame ; 26 import javax.swing.SwingUtilities ; 27 import org.netbeans.core.NbTopManager; 28 import org.netbeans.core.windows.PersistenceHandler; 29 import org.netbeans.core.windows.WindowManagerImpl; 30 import org.netbeans.core.windows.persistence.PersistenceManager; 31 import org.openide.ErrorManager; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileSystem; 34 import org.openide.filesystems.Repository; 35 import org.openide.util.Lookup; 36 import org.openide.util.NbBundle; 37 import org.openide.windows.TopComponent; 38 39 44 public class ResetWindowsAction extends AbstractAction { 45 46 47 public ResetWindowsAction() { 48 putValue(NAME, NbBundle.getMessage(CloneDocumentAction.class, "CTL_ResetWindows" ) ); } 50 51 public void actionPerformed(ActionEvent e) { 52 final NbTopManager.WindowSystem ws = (NbTopManager.WindowSystem)Lookup.getDefault().lookup( NbTopManager.WindowSystem.class ); 53 if( null == ws ) { 54 return; 57 } 58 59 WindowManagerImpl wm = WindowManagerImpl.getInstance(); 60 61 wm.getMainWindow().setExtendedState( JFrame.NORMAL ); 62 63 final TopComponent[] editors = wm.getEditorTopComponents(); 65 66 wm.closeNonEditorViews(); 68 69 wm.getMainWindow().setVisible( false ); 71 72 final TopComponent activeEditor = wm.getArbitrarySelectedEditorTopComponent(); 74 wm.deselectEditorTopComponents(); 77 78 SwingUtilities.invokeLater( new Runnable () { 79 public void run() { 80 FileSystem fs = Repository.getDefault().getDefaultFileSystem(); 82 FileObject rootFolder = fs.getRoot().getFileObject( PersistenceManager.ROOT_LOCAL_FOLDER ); 83 if( null != rootFolder ) { 84 try { 85 for( FileObject fo : rootFolder.getChildren() ) { 86 if( PersistenceManager.COMPS_FOLDER.equals( fo.getName() ) ) 87 continue; fo.delete(); 89 } 90 } catch( IOException ioE ) { 91 ErrorManager.getDefault().notify( ErrorManager.INFORMATIONAL, ioE ); 92 } 93 } 94 95 ws.hide(); 97 WindowManagerImpl.getInstance().resetModel(); 98 PersistenceManager.getDefault().reset(); PersistenceHandler.getDefault().clear(); 100 ws.load(); 101 ws.show(); 102 103 for( int i=0; i<editors.length; i++ ) { 105 editors[i].open(); 106 } 107 if( null != activeEditor ) { 109 SwingUtilities.invokeLater( new Runnable () { 110 public void run() { 111 activeEditor.requestActive(); 112 } 113 }); 114 } 115 } 116 }); 117 } 118 } 119 | Popular Tags |