public void relayout(boolean updateFolding) { assert SwingUtilities.isEventDispatchThread() : "LeftEditorHighlighter.relayout() should be executed in eventDispatchThread"; SNode editedNode = myEditorComponent.getEditedNode(); // additional check - during editor dispose process some Folding area painters can be removed // calling relayout().. if (myEditorComponent.isDisposed() || (editedNode != null && jetbrains.mps.util.SNodeOperations.isDisposed(editedNode))) { return; } if (myRightToLeft) { recalculateFoldingAreaWidth(); updateSeparatorLinePosition(); if (updateFolding) { for (AbstractFoldingAreaPainter painter : myFoldingAreaPainters) { painter.relayout(); } // wee need to recalculateIconRenderersWidth only if one of collections was folded/unfolded recalculateIconRenderersWidth(); } recalculateTextColumnWidth(); } else { recalculateTextColumnWidth(); if (updateFolding) { for (AbstractFoldingAreaPainter painter : myFoldingAreaPainters) { painter.relayout(); } // wee need to recalculateIconRenderersWidth only if one of collections was folded/unfolded recalculateIconRenderersWidth(); } recalculateFoldingAreaWidth(); updateSeparatorLinePosition(); } updatePreferredSize(); }
public boolean canExecute(EditorContext context) { EditorCell selectedCell = getCellToPasteTo((EditorCell) context.getSelectedCell()); if (selectedCell == null) { return false; } SNode selectedNode = selectedCell.getSNode(); if (selectedNode == null || jetbrains.mps.util.SNodeOperations.isDisposed(selectedNode)) { return false; } List<SNode> pasteNodes = CopyPasteUtil.getNodesFromClipboard(selectedNode.getModel()); if (pasteNodes == null || pasteNodes.isEmpty()) { return CopyPasteUtil.isConversionAvailable(selectedNode.getModel(), selectedNode); } if (!new NodePaster(pasteNodes).canPaste(selectedCell)) { LOG.debug("Couldn't paste node here"); return false; } return true; }
private TypeCheckingContext getOrCreateContext( SNode node, ITypeContextOwner owner, boolean createIfAbsent) { ModelAccess.assertLegalRead(); if (node == null) return null; final SNode rootNode = node.getContainingRoot(); synchronized (myLock) { SNodeReference rootNodePointer = new jetbrains.mps.smodel.SNodePointer(rootNode); List<TypecheckingContextHolder> contextWithOwners = myTypeCheckingContexts.get(rootNodePointer); if (contextWithOwners == null && !createIfAbsent) return null; if (contextWithOwners == null) { contextWithOwners = new ArrayList<TypecheckingContextHolder>(4); myTypeCheckingContexts.put(rootNodePointer, contextWithOwners); } for (ListIterator<TypecheckingContextHolder> it = contextWithOwners.listIterator(); it.hasNext(); ) { TypecheckingContextHolder contextHolder = it.next(); if (contextHolder.getOwner() == owner) { if (!owner.reuseTypecheckingContext()) { assert createIfAbsent; return contextHolder.acquire(node); } else { // reuse the typechecking context if (!createIfAbsent) { return contextHolder.get(node); } final TypeCheckingContext ctx = contextHolder.acquire(node); // Dirty hack if (jetbrains.mps.util.SNodeOperations.isDisposed(ctx.getNode())) { removeContextForNode(rootNodePointer); LOG.error( "Type Checking Context had a disposed node inside. Node: " + node + " model: " + node.getModel()); return getOrCreateContext(node, owner, createIfAbsent); } return ctx; } } } // not found, create new if (!owner.reuseTypecheckingContext()) { assert createIfAbsent; final NonReusableTypecheckingContextHolder contextHolder = new NonReusableTypecheckingContextHolder(owner); contextWithOwners.add(contextHolder); return contextHolder.acquire(node); } else if (!createIfAbsent) { return null; } else { if (contextWithOwners.size() > 100) { if (!myReported) { myReported = true; LOG.warn( "Type checking context for node " + node.getPresentation() + " has too much owners"); } } final CountingTypecheckingContextHolder contextHolder = new CountingTypecheckingContextHolder(owner); contextWithOwners.add(contextHolder); return contextHolder.acquire(node); } } }