@Override public void propertyChange(PropertyChangeEvent evt) { if (TopComponent.Registry.PROP_ACTIVATED.equals(evt.getPropertyName())) { Object newValue = evt.getNewValue(); if (newValue instanceof DocumentWindow) { setSelectedWindow((DocumentWindow) newValue); } } else if (TopComponent.Registry.PROP_TC_OPENED.equals(evt.getPropertyName())) { Object newValue = evt.getNewValue(); if (newValue instanceof DocumentWindow) { addOpenedWindow((DocumentWindow) newValue); } } else if (TopComponent.Registry.PROP_TC_CLOSED.equals(evt.getPropertyName())) { Object newValue = evt.getNewValue(); if (newValue instanceof DocumentWindow) { removeOpenedWindow((DocumentWindow) newValue); } } } }
/** * 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); } }
private void notifyClosed(TopComponent topComponent) { NotifiableComponent.get(topComponent).componentClosed(); if (topComponent instanceof DocumentWindow) { DocumentWindowManager.getDefault().removeOpenedWindow((DocumentWindow) topComponent); } }