private boolean isPredicateApplicable(Predicate predicate, DocumentWindow documentWindow) { Object document = documentWindow.getDocument(); Object view = documentWindow.getView(); Class<?> actualDocType = document != null ? document.getClass() : Object.class; Class<?> actualViewType = view != null ? view.getClass() : Object.class; Class<?> requestedDocType = predicate.getDocType(); Class<?> requestedViewType = predicate.getViewType(); return requestedDocType.isAssignableFrom(actualDocType) && requestedViewType.isAssignableFrom(actualViewType); }
void setSelectedWindow(DocumentWindow newValue) { DocumentWindow oldValue = this.selectedDocumentWindow; if (oldValue != newValue) { this.selectedDocumentWindow = newValue; if (oldValue != null) { oldValue.componentDeselected(); fireWindowEvent(Event.Type.WINDOW_DESELECTED, oldValue); } if (newValue != null) { newValue.componentSelected(); fireWindowEvent(Event.Type.WINDOW_SELECTED, 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); } }
@Override public void windowClosed(DocumentWindowManager.Event<Object, ProductSceneView> e) { removePPL(e.getWindow().getView()); } }
private static <T extends ProductNode> void closeDocumentWindow(T productNode) { WindowUtilities.getOpened(DocumentWindow.class) .filter(dw -> (dw.getDocument() instanceof ProductNode) && (dw.getDocument() == productNode)) .forEach(dw -> DocumentWindowManager.getDefault().closeWindow(dw)); }
@Override public void windowOpened(DocumentWindowManager.Event<Object, ProductSceneView> e) { addPPL(e.getWindow().getView()); }
.filter(dw -> (dw.getDocument() instanceof ProductNode) && ((ProductNode) dw.getDocument()).getProduct() == product) .forEach(dw -> DocumentWindowManager.getDefault().closeWindow(dw)); SnapApp.getDefault().getProductManager().removeProduct(product);
@Override public void windowSelected(DocumentWindowManager.Event<Object, ProductSceneView> e) { ProductSceneView view = e.getWindow().getView(); view.addPixelPositionListener(this); }
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; }
@Override public void windowDeselected(DocumentWindowManager.Event<Object, ProductSceneView> e) { ProductSceneView view = e.getWindow().getView(); view.removePixelPositionListener(this); }
/** * 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; }