/** * Closes a document window. * * @param documentWindow The document window to be closed. * @return {@code true} on success */ public boolean closeWindow(DocumentWindow documentWindow) { Optional<WorkspaceTopComponent> anyWorkspace = WindowUtilities .getOpened(WorkspaceTopComponent.class) .filter(tc -> tc.getTopComponents().contains(documentWindow.getTopComponent())).findAny(); if (anyWorkspace.isPresent()) { return anyWorkspace.get().removeTopComponent(documentWindow.getTopComponent()); } else { return removeOpenedWindow(documentWindow); } }
boolean removeOpenedWindow(DocumentWindow documentWindow) { if (openDocumentWindows.remove(documentWindow)) { if (getSelectedWindow() == documentWindow) { setSelectedWindow(null); } boolean isClosed = documentWindow.getTopComponent().close(); if (isClosed) { fireWindowEvent(Event.Type.WINDOW_CLOSED, documentWindow); } return isClosed; } return false; }
/** * Requests that the given document window is being selected. * * @param documentWindow The document window to be selected. */ public void requestSelected(DocumentWindow documentWindow) { TopComponent topComponent = documentWindow.getTopComponent(); List<WorkspaceTopComponent> showingWorkspaces = WorkspaceTopComponent.findShowingInstances(); for (WorkspaceTopComponent showingWorkspace : showingWorkspaces) { if (showingWorkspace.getTopComponents().contains(topComponent)) { showingWorkspace.requestActiveTopComponent(topComponent); return; } } topComponent.requestActive(); }
/** * Opens a document window. * <p> * Document windows are initially opened in the NetBeans {@code "editor"} mode which * is the central panel of the main frame. * * @param documentWindow The document window to be opened. * @return {@code true} on success */ public boolean openWindow(DocumentWindow documentWindow) { TopComponent topComponent = documentWindow.getTopComponent(); WorkspaceTopComponent workspaceTopComponent = WorkspaceTopComponent.findShowingInstance(); if (workspaceTopComponent != null) { workspaceTopComponent.addTopComponent(topComponent); return true; } Mode editor = WindowManager.getDefault().findMode("editor"); if (editor.dockInto(topComponent)) { topComponent.open(); return true; } return false; }