private Pair<EditorCell, String> getMatchingLabelAndCell(EditorCell editorCell) { SNode node = editorCell.getSNode(); while (editorCell != null && editorCell.getSNode() == node) { if (editorCell.getStyle().get(StyleAttributes.MATCHING_LABEL) != null) { return new Pair(editorCell, editorCell.getStyle().get(StyleAttributes.MATCHING_LABEL)); } editorCell = editorCell.getParent(); } return null; }
private EditorCell createProperty_lbdr4h_b0(EditorContext editorContext, SNode node) { CellProviderWithRole provider = new PropertyCellProvider(node, editorContext); provider.setRole("label"); provider.setNoTargetText(""); provider.setAllowsEmptyTarget(true); EditorCell editorCell; editorCell = provider.createEditorCell(editorContext); editorCell.setCellId("property_label"); Style style = new StyleImpl(); style.set( StyleAttributes.TEXT_COLOR, StyleRegistry.getInstance() .getSimpleColor( Antiquotation_Editor._StyleParameter_QueryFunction_lbdr4h_a0b0( (editorCell == null ? null : editorCell.getContext()), (editorCell == null ? null : editorCell.getSNode())))); editorCell.getStyle().putAll(style); editorCell.setSubstituteInfo(provider.createDefaultSubstituteInfo()); SNode attributeConcept = provider.getRoleAttribute(); Class attributeKind = provider.getRoleAttributeClass(); if (attributeConcept != null) { IOperationContext opContext = editorContext.getOperationContext(); EditorManager manager = EditorManager.getInstanceFromContext(opContext); return manager.createNodeRoleAttributeCell( editorContext, attributeConcept, attributeKind, editorCell); } else return editorCell; }
private void selectBraces(final EditorCell selectedCell) { final Pair<EditorCell, String> pair = getMatchingLabelAndCell(selectedCell); if (pair != null) { final EditorCell matchigCell = pair.o1; EditorCell validCellForNode = ((EditorComponent) matchigCell.getEditorComponent()) .getBigValidCellForNode(matchigCell.getSNode()); if (validCellForNode != null) { EditorCell editorCell = CellFinderUtil.findChildByCondition( validCellForNode, new Condition<EditorCell>() { @Override public boolean met(EditorCell cell) { return cell != matchigCell && cell.getSNode() == matchigCell.getSNode() && pair.o2.equals(cell.getStyle().get(StyleAttributes.MATCHING_LABEL)); } }, true); if (editorCell != null) { if (editorCell.getY() != matchigCell.getY()) { ((EditorComponent) matchigCell.getEditorComponent()) .leftHighlightCells( (jetbrains.mps.nodeEditor.cells.EditorCell) matchigCell, (jetbrains.mps.nodeEditor.cells.EditorCell) editorCell, BRACES_LEFT_HIGHTLIGHT_COLOR); } hightlightCell(editorCell); hightlightCell(matchigCell); } } } }
/** @deprecated Since MPS 3.5 use generated StyleClass */ @Deprecated public static void apply_InequationsGroupsLabel(Style style, EditorCell editorCell) { SNode node = (editorCell == null ? null : editorCell.getSNode()); EditorContext editorContext = (editorCell == null ? null : editorCell.getContext()); new TypesystemStyles_StyleSheet.InequationsGroupsLabelStyleClass(editorContext, node) .apply(style, editorCell); }
@Override public boolean acceptCell(EditorCell cell, EditorComponent editor) { if (cell == null) { return false; } return cell.isBig() && editor.isValid(cell) && cell.getSNode() == getNode(); }
private EditorCell createProperty_3uf681_a0(EditorContext editorContext, SNode node) { CellProviderWithRole provider = new PropertyCellProvider(node, editorContext); provider.setRole("name"); provider.setNoTargetText("<no name>"); EditorCell editorCell; editorCell = provider.createEditorCell(editorContext); editorCell.setCellId("property_name"); Style style = new StyleImpl(); style.set( StyleAttributes.NAVIGATABLE_NODE, 0, FigureParameterMapping_Editor._StyleParameter_QueryFunction_3uf681_a0a0( (editorCell == null ? null : editorCell.getContext()), (editorCell == null ? null : editorCell.getSNode()))); style.set(StyleAttributes.AUTO_DELETABLE, 0, true); editorCell.getStyle().putAll(style); FigureParameterMappingName_Actions.setCellActions(editorCell, node, editorContext); editorCell.setSubstituteInfo( new CompositeSubstituteInfo( editorContext, provider.getCellContext(), new SubstituteInfoPartExt[] { new FigureParameterMapping_Editor .FigureParameterMapping_generic_cellMenu_3uf681_a0a0() })); SNode attributeConcept = provider.getRoleAttribute(); Class attributeKind = provider.getRoleAttributeClass(); if (attributeConcept != null) { EditorManager manager = EditorManager.getInstanceFromContext(editorContext); return manager.createNodeRoleAttributeCell(attributeConcept, attributeKind, editorCell); } else return editorCell; }
public void execute(final SNode node, final EditorContext editorContext) { EditorCell selectedCell = editorContext.getSelectedCell(); if (!(selectedCell.isReferenceCell())) { return; } SNode contextNode = SNodeOperations.cast( selectedCell.getSNode(), "jetbrains.mps.lang.core.structure.BaseConcept"); if (contextNode == null) { return; } String role = selectedCell.getRole(); if (SNodeOperations.isInstanceOf( contextNode, "jetbrains.mps.lang.quotation.structure.ReferenceAntiquotation")) { SNode attributedNode = SNodeOperations.cast( SNodeOperations.getParent(contextNode), "jetbrains.mps.lang.core.structure.BaseConcept"); assert attributedNode != null; AttributeOperations.setAttribute( attributedNode, new IAttributeDescriptor.LinkAttribute( SConceptOperations.findConceptDeclaration( "jetbrains.mps.lang.quotation.structure.ReferenceAntiquotation"), role), null); return; } if (AttributeOperations.getAttribute( contextNode, new IAttributeDescriptor.LinkAttribute( SConceptOperations.findConceptDeclaration( "jetbrains.mps.lang.quotation.structure.ReferenceAntiquotation"), role)) != null) { AttributeOperations.setAttribute( contextNode, new IAttributeDescriptor.LinkAttribute( SConceptOperations.findConceptDeclaration( "jetbrains.mps.lang.quotation.structure.ReferenceAntiquotation"), role), null); } else { SNode referenceAntiquotation = SNodeFactoryOperations.setNewAttribute( contextNode, new IAttributeDescriptor.LinkAttribute( SConceptOperations.findConceptDeclaration( "jetbrains.mps.lang.quotation.structure.ReferenceAntiquotation"), role), "jetbrains.mps.lang.quotation.structure.ReferenceAntiquotation"); if (selectedCell.isSingleNodeCell()) { SPropertyOperations.set( referenceAntiquotation, "label", SPropertyOperations.getString( SNodeOperations.getConceptDeclaration(contextNode), "name")); } } }
public TypeEditorMessage(jetbrains.mps.openapi.editor.cells.EditorCell cell, String message) { super( cell.getSNode(), StyleRegistry.getInstance().getSimpleColor(Color.blue), message, myMessageOwner); this.myCell = cell; }
public static SNode getSNodeWRTReference(EditorCell cell) { SNode target = cell.getStyle().get(StyleAttributes.NAVIGATABLE_NODE); if (target != null) { return target; } SNode node = cell.getSNode(); String role = cell.getRole(); SNode referentNode = role == null ? null : node.getReferenceTarget(role); return referentNode != null ? referentNode : node; }
@Override public void setSubstituteInfo(SubstituteInfo substitueInfo) { super.setSubstituteInfo(substitueInfo); if (isTransparentCollection()) { for (EditorCell child : getEditorCells()) { if (child.getSNode() == getSNode()) { child.setSubstituteInfo(substitueInfo); } } } }
@Override public void setAction(CellActionType type, CellAction action) { super.setAction(type, action); if (isTransparentCollection()) { for (EditorCell child : getEditorCells()) { if (child.getSNode() == getSNode()) { child.setAction(type, action); } } } }
public boolean canExecute(final KeyEvent keyEvent, final EditorContext editorContext) { EditorCell contextCell = editorContext.getContextCell(); if ((contextCell == null)) { return false; } SNode contextNode = contextCell.getSNode(); if (contextNode == null) { return false; } return this.canExecute_internal( keyEvent, editorContext, contextNode, this.getSelectedNodes(editorContext)); }
public static void showCreateNewRootMenu( @NotNull jetbrains.mps.openapi.editor.EditorContext editorContext, @Nullable Setter<SNode> newRootHandler, @Nullable Condition<SConcept> conceptsFilter) { final EditorCell selectedCell = editorContext.getSelectedCell(); int x = selectedCell.getX(); int y = selectedCell.getY(); if (selectedCell instanceof EditorCell_Label) { y += selectedCell.getHeight(); } Component editorComponent = ((EditorContext) editorContext).getNodeEditorComponent(); final DataContext dataContext = DataManager.getInstance().getDataContext(editorComponent, x, y); final SModel model = selectedCell.getSNode().getModel(); if (conceptsFilter == null) { conceptsFilter = Condition.TRUE_CONDITION; } BaseGroup group = new BaseGroup(""); Set<SLanguage> modelLanguages = new SLanguageHierarchy(SModelOperations.getAllLanguageImports(model)).getExtended(); SLanguage[] languages = modelLanguages.toArray(new SLanguage[modelLanguages.size()]); Arrays.sort(languages, new ToStringComparator()); for (SLanguage language : languages) { boolean hasChildren = false; for (SAbstractConcept ac : language.getConcepts()) { if (!(ac instanceof SConcept)) { continue; } final SConcept concept = (SConcept) ac; if (concept.isRootable() && conceptsFilter.met(concept)) { group.add(new AddNewRootAction(model, concept, newRootHandler)); hasChildren = true; } } if (hasChildren) { group.addSeparator(); } } ListPopup popup = JBPopupFactory.getInstance() .createActionGroupPopup( IdeBundle.message("title.popup.new.element"), group, dataContext, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false); // popup.showInBestPositionFor(dataContext); popup.show(new RelativePoint(editorComponent, new Point(x, y))); }
private boolean isApplicableToNode(final SNode node, final EditorContext editorContext) { EditorCell selectedCell = editorContext.getSelectedCell(); if (!(selectedCell.isReferenceCell())) { return false; } SNode contextNode = SNodeOperations.cast( selectedCell.getSNode(), "jetbrains.mps.lang.core.structure.BaseConcept"); if (contextNode == null) { return false; } return true; }
private boolean canPasteBefore(EditorCell selectedCell, List<SNode> pasteNodes) { if (!APICellAdapter.isFirstPositionInBigCell(selectedCell)) return false; SNode anchor = selectedCell.getSNode(); if (anchor.getParent() == null) return false; NodeAndRole nodeAndRole = new NodePaster(pasteNodes).getActualAnchorNode(anchor, anchor.getRoleInParent(), false); if (nodeAndRole == null) return false; EditorCell targetCell = selectedCell.getEditorComponent().findNodeCell(nodeAndRole.myNode); return targetCell != null && ((jetbrains.mps.nodeEditor.cells.EditorCell) targetCell) .getFirstLeaf(CellConditions.SELECTABLE) == selectedCell && new NodePaster(pasteNodes).canPasteRelative(nodeAndRole.myNode); }
public void installCellInfo(SNode child, EditorCell editorCell) { editorCell.setSubstituteInfo( new DefaultChildSubstituteInfo( myOwnerNode, myContainmentLink.getDeclarationNode(), myEditorContext)); if (editorCell.getRole() == null) { editorCell.setRole("body"); } Style style = new StyleImpl(); style.set( StyleAttributes.INDENT_LAYOUT_NEW_LINE, 0, BaseMethodDeclaration_BodyComponent._StyleParameter_QueryFunction_fao2ea_a0b0( (editorCell == null ? null : editorCell.getContext()), (editorCell == null ? null : editorCell.getSNode()))); style.set(StyleAttributes.INDENT_LAYOUT_INDENT, 0, true); editorCell.getStyle().putAll(style); }
@Override public boolean canExecute(EditorContext context) { Selection selection = context.getSelectionManager().getSelection(); List<SNode> pasteNodes = CopyPasteUtil.getNodesFromClipboard(selection.getSelectedNodes().get(0).getModel()); if (pasteNodes == null || pasteNodes.isEmpty()) { // it used to be ok because conversion would be invoked in this case return false; } boolean disposed = false; for (SNode node : selection.getSelectedNodes()) { if (!SNodeUtil.isAccessible(node, MPSModuleRepository.getInstance())) { disposed = true; break; } } boolean canPasteWithRemove = !disposed && canPasteViaNodePasterWithRemove(selection.getSelectedNodes(), pasteNodes); if (selection instanceof SingularSelection && (selection instanceof EditorCellLabelSelection && !isCompletelySelected((EditorCellLabelSelection) selection) || (selection instanceof EditorCellSelection && !canPasteWithRemove))) { EditorCell selectedCell = getCellToPasteTo(context.getSelectedCell()); if (selectedCell == null) { return false; } SNode selectedNode = selectedCell.getSNode(); if (selectedNode == null || !(SNodeUtil.isAccessible(selectedNode, MPSModuleRepository.getInstance()))) { return false; } return canPasteViaNodePaster(selectedCell, pasteNodes); } else if ((selection instanceof MultipleSelection || selection instanceof EditorCellSelection) && canPasteWithRemove) { return true; } return false; }
public boolean canExecute(final EditorContext editorContext) { EditorCell contextCell = editorContext.getContextCell(); if ((contextCell == null)) { return false; } SNode contextNode = contextCell.getSNode(); if (contextNode == null) { return false; } if (!(SNodeOperations.isInstanceOf( contextNode, MetaAdapterFactory.getConcept( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x32175ac2e6fcc181L, "jetbrains.mps.baseLanguage.structure.IncompleteMemberDeclaration")))) { return false; } return true; }
public void execute(EditorContext editorContext) { EditorCell selectedCell = editorContext.getSelectedCell(); if (selectedCell == null) { return; } final String cellId = selectedCell.getCellId(); SNode actualSelectedNode = selectedCell.getSNode(); boolean isLabel = selectedCell instanceof EditorCell_Label; int startPosition = (isLabel ? ((EditorCell_Label) selectedCell).getSelectionStart() : -1); int endPosition = (isLabel ? ((EditorCell_Label) selectedCell).getSelectionEnd() : -1); SNode nodeToSelect = CommentUtil.commentOut(myNode); editorContext.flushEvents(); if (cellId != null) { EditorCell newNodeCell = editorContext.getEditorComponent().findNodeCell(actualSelectedNode); if (newNodeCell != null) { EditorCell cellToSelect = CellFinderUtil.findChildByCondition( newNodeCell, new Condition<EditorCell>() { public boolean met(EditorCell cell) { return eq_9lx3n0_a0a0a0a1a0a0b0j0h(cell.getCellId(), cellId); } }, true, true); if (cellToSelect != null) { if (isLabel) { editorContext .getSelectionManager() .setSelection(actualSelectedNode, cellId, startPosition, endPosition); } else { editorContext.getSelectionManager().setSelection(actualSelectedNode, cellId); } return; } } } SelectionUtil.selectCell(editorContext, nodeToSelect, SelectionManager.LAST_EDITABLE_CELL); }
private static SNode check_j6szs9_a0c0a(EditorCell checkedDotOperand) { if (null != checkedDotOperand) { return checkedDotOperand.getSNode(); } return null; }
public static boolean isOnRightBoundary(EditorCell cell) { EditorCell nextLeaf = APICellAdapter.getNextLeaf(cell); return nextLeaf == null || nextLeaf.getSNode() != cell.getSNode(); }
public static boolean isOnLeftBoundary(EditorCell cell) { EditorCell prevLeaf = APICellAdapter.getPrevLeaf(cell); return prevLeaf == null || prevLeaf.getSNode() != cell.getSNode(); }
@Override public void execute(final EditorContext context) { LOG.assertLog( context.getRepository().getModelAccess().isCommandAction(), "This action must be performed in command"); final EditorComponent editorComponent = (EditorComponent) context.getEditorComponent(); final Selection selection = editorComponent.getSelectionManager().getSelection(); final List<SNode> selectedNodes = selection.getSelectedNodes(); // this is used in case node is in repo to pass it into invokeLater final List<SNodeReference> selectedReferences = new ArrayList<SNodeReference>(); for (SNode node : selectedNodes) { selectedReferences.add(node.getReference()); } final CellInfo pasteTargetCellInfo; final SNode cellNodeSelected; final SNodeReference selectedCellReference; if (selection instanceof SingularSelection) { EditorCell pasteTargetCell = getCellToPasteTo(context.getSelectedCell()); if (pasteTargetCell == null) { return; } pasteTargetCellInfo = APICellAdapter.getCellInfo(pasteTargetCell); cellNodeSelected = pasteTargetCell.getSNode(); selectedCellReference = cellNodeSelected.getReference(); } else { pasteTargetCellInfo = null; cellNodeSelected = null; selectedCellReference = null; } final SModel modelToPaste = selectedNodes.get(0).getModel(); // sometimes model is not in repository (paste in merge dialog) final boolean inRepository = modelToPaste.getReference().resolve(context.getRepository()) != null; // FIXME relationship between Project and Editor needs attention, it's bad to extract final Project mpsProject = ProjectHelper.getProject(context.getRepository()); if (mpsProject == null) { LOG.warning("Paste needs a project to show a dialog for additional imports"); return; } final PasteNodeData pasteNodeData = CopyPasteUtil.getPasteNodeDataFromClipboard(modelToPaste); // FIXME why SwingUtlities? Is it necessary to execute in EDT thread? If yes, use ThreadUtils. // If not, use any other thread than UI, e.g. app's pooled one. SwingUtilities.invokeLater( new Runnable() { @Override public void run() { final Runnable addImportsRunnable = CopyPasteUtil.addImportsWithDialog(pasteNodeData, modelToPaste, mpsProject); context .getRepository() .getModelAccess() .executeCommandInEDT( new Runnable() { @Override public void run() { if (addImportsRunnable != null) { addImportsRunnable.run(); } List<SNode> pasteNodes = pasteNodeData.getNodes(); List<SNode> currentSelectedNodes; if (!inRepository) { currentSelectedNodes = selectedNodes; } else { currentSelectedNodes = new ArrayList<SNode>(); for (SNodeReference ref : selectedReferences) { currentSelectedNodes.add( ref.resolve(MPSModuleRepository.getInstance())); } } NodePaster nodePaster = new NodePaster(pasteNodes); boolean disposed = checkDisposedSelectedNodes(currentSelectedNodes, selectedReferences); boolean canPasteWithRemove = !disposed && nodePaster.canPasteWithRemove(currentSelectedNodes); if (selection instanceof SingularSelection && (selection instanceof EditorCellLabelSelection && !isCompletelySelected((EditorCellLabelSelection) selection) || (selection instanceof EditorCellSelection && !canPasteWithRemove))) { EditorCell selectedCell = pasteTargetCellInfo.findCell(editorComponent); assert selectedCell != null; if (canPasteBefore(selectedCell, pasteNodes)) { SNode selectedNode = inRepository ? selectedCellReference.resolve( MPSModuleRepository.getInstance()) : cellNodeSelected; if (checkDisposed(selectedCellReference, cellNodeSelected)) { return; } new NodePaster(pasteNodes) .pasteRelative(selectedNode, PastePlaceHint.BEFORE_ANCHOR); } else { new NodePaster(pasteNodes).paste(selectedCell); } } else if ((selection instanceof MultipleSelection || selection instanceof EditorCellSelection) && canPasteWithRemove) { nodePaster.pasteWithRemove(currentSelectedNodes); } else { return; } Set<SReference> requireResolveReferences = new HashSet<SReference>(); for (SReference ref : pasteNodeData.getRequireResolveReferences()) { // ref can be detached from modeltoPaste while using copy/paste handlers if (ref.getSourceNode() == null || ref.getSourceNode().getModel() == null) continue; requireResolveReferences.add(ref); } ResolverComponent.getInstance() .resolveScopesOnly(requireResolveReferences, context.getRepository()); // set selection editorComponent.getUpdater().flushModelEvents(); SNode lastNode = pasteNodes.get(pasteNodes.size() - 1); editorComponent .getSelectionManager() .setSelection(lastNode, SelectionManager.LAST_CELL, -1); } }); } }); }
public void execute(final EditorContext editorContext) { EditorCell contextCell = editorContext.getContextCell(); this.execute_internal( editorContext, contextCell.getSNode(), this.getSelectedNodes(editorContext)); }
public void registerAsBigCell(EditorCell cell) { myBigCellsMap.put(cell.getSNode(), new WeakReference<EditorCell>(cell)); }