package jetbrains.mps.testHybridEditor.diagram.generated.editor; /*Generated by MPS */ import jetbrains.mps.editor.runtime.descriptor.AbstractEditorBuilder; import org.jetbrains.annotations.NotNull; import org.jetbrains.mps.openapi.model.SNode; import jetbrains.mps.openapi.editor.EditorContext; import jetbrains.mps.openapi.editor.cells.EditorCell; import jetbrains.mps.nodeEditor.cells.jetpad.ConnectorCell; import jetbrains.jetpad.model.property.Property; import jetbrains.mps.baseLanguage.tuples.runtime.Tuples; import jetbrains.jetpad.model.property.ValueProperty; import jetbrains.jetpad.mapper.Mapper; import jetbrains.jetpad.projectional.diagram.view.PolyLineConnection; import jetbrains.jetpad.mapper.Synchronizers; import jetbrains.jetpad.model.property.WritableProperty; import jetbrains.jetpad.projectional.view.View; import java.util.Set; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import jetbrains.mps.editor.runtime.selection.SelectionUtil; import jetbrains.mps.internal.collections.runtime.Sequence; import jetbrains.mps.nodeEditor.cells.jetpad.JetpadUtils; import jetbrains.jetpad.geometry.Rectangle; import jetbrains.mps.nodeEditor.cells.jetpad.DiagramCell; import jetbrains.mps.lang.editor.diagram.runtime.jetpad.views.ConnectorDecoratorView; import jetbrains.jetpad.model.property.ReadableProperty; import jetbrains.mps.baseLanguage.tuples.runtime.MultiTuple; import jetbrains.mps.baseLanguage.closures.runtime._FunctionTypes; /*package*/ class ConnectorInstance_diagram_EditorBuilder_a extends AbstractEditorBuilder { @NotNull private SNode myNode; public ConnectorInstance_diagram_EditorBuilder_a(@NotNull EditorContext context, @NotNull SNode node) { super(context); myNode = node; } @NotNull @Override public SNode getNode() { return myNode; } /*package*/ EditorCell createCell() { return createDiagramConnector_z1vupn_a(); } private EditorCell createDiagramConnector_z1vupn_a() { final ConnectorCell editorCell = new ConnectorInstance_diagram_EditorBuilder_a.ConnectorCellImpl_z1vupn_a(getEditorContext(), myNode); editorCell.setCellId("DiagramConnector_z1vupn_a"); editorCell.setBig(true); editorCell.setCellContext(getCellFactory().getCellContext()); ConnectorActionMap.setCellActions(editorCell, myNode, getEditorContext()); return editorCell; } public class ConnectorCellImpl_z1vupn_a extends ConnectorCell { protected Property<Tuples._2<SNode, SNode>> myInputPort = new ValueProperty<Tuples._2<SNode, SNode>>(); protected Property<Tuples._2<SNode, SNode>> myOutputPort = new ValueProperty<Tuples._2<SNode, SNode>>(); private ConnectorCellImpl_z1vupn_a(EditorContext editorContext, SNode node) { super(editorContext, node); synchronize(); } public Mapper<SNode, PolyLineConnection> createMapper() { return new Mapper<SNode, PolyLineConnection>(getSNode(), createConnection()) { @Override protected void registerSynchronizers(Mapper.SynchronizersConfiguration configuration) { super.registerSynchronizers(configuration); configuration.add(Synchronizers.forProperty(myInputPort, new WritableProperty<Tuples._2<SNode, SNode>>() { public void set(Tuples._2<SNode, SNode> port) { getTarget().toView().set(getTargetView(port)); } private View getTargetView(Tuples._2<SNode, SNode> port) { Mapper<? super SNode, ?> descendantMapper = getParent().getDescendantMapper(port._0()); if (descendantMapper == null) { return null; } Set<Mapper<? super SNode, ?>> mappers = descendantMapper.getMappingContext().getMappers(descendantMapper, SLinkOperations.getTarget(SLinkOperations.getTarget(getSNode(), MetaAdapterFactory.getContainmentLink(0x913a1d639e1948faL, 0xad03e33ecccd3814L, 0x20a804e2ec441516L, 0x49664459198225c0L, "source")), MetaAdapterFactory.getReferenceLink(0x913a1d639e1948faL, 0xad03e33ecccd3814L, 0x4966445919822461L, 0x49664459198225bdL, "metaPort"))); if (mappers.size() > 0) { return (View) mappers.iterator().next().getTarget(); } return (View) descendantMapper.getTarget(); } })); configuration.add(Synchronizers.forProperty(myOutputPort, new WritableProperty<Tuples._2<SNode, SNode>>() { public void set(Tuples._2<SNode, SNode> port) { getTarget().fromView().set(getTargetView(port)); if (getTarget().fromView().get() == null || getTarget().toView().get() == null) { getTarget().fromView().set(null); getTarget().toView().set(null); } } private View getTargetView(Tuples._2<SNode, SNode> port) { Mapper<? super SNode, ?> descendantMapper = getParent().getDescendantMapper(port._0()); if (descendantMapper == null) { return null; } Set<Mapper<? super SNode, ?>> mappers = descendantMapper.getMappingContext().getMappers(descendantMapper, SLinkOperations.getTarget(SLinkOperations.getTarget(getSNode(), MetaAdapterFactory.getContainmentLink(0x913a1d639e1948faL, 0xad03e33ecccd3814L, 0x20a804e2ec441516L, 0x49664459198225c6L, "target")), MetaAdapterFactory.getReferenceLink(0x913a1d639e1948faL, 0xad03e33ecccd3814L, 0x4966445919822461L, 0x49664459198225bdL, "metaPort"))); if (mappers.size() > 0) { return (View) mappers.iterator().next().getTarget(); } return (View) descendantMapper.getTarget(); } })); final View targetView = this.getTarget().view(); configuration.add(Synchronizers.forProperty(targetView.focused(), new WritableProperty<Boolean>() { public void set(Boolean isFocused) { if (isFocused && !(isSelected())) { SelectionUtil.selectCell(getContext(), getSNode(), getCellId()); } } })); configuration.add(Synchronizers.forProperty(mySelectedItem, new WritableProperty<Boolean>() { public void set(Boolean isSelected) { if (isSelected) { for (View view : Sequence.fromIterable(JetpadUtils.getAllChildren(targetView))) { if (view.focused().get()) { return; } } targetView.container().focusedView().set(targetView); } else if (!(isSelected) && targetView.focused().get()) { targetView.container().focusedView().set(null); } } })); configuration.add(Synchronizers.forProperty(targetView.bounds(), new WritableProperty<Rectangle>() { public void set(Rectangle rect) { DiagramCell diagramCell = getDiagramCell(); if (diagramCell == null) { return; } setX(rect.origin.x + diagramCell.getX()); setY(rect.origin.y + diagramCell.getY()); setWidth(rect.dimension.x); setHeight(rect.dimension.y); } })); } }; } public Mapper<SNode, ConnectorDecoratorView> createDecorationMapper() { return new Mapper<SNode, ConnectorDecoratorView>(getSNode(), createConnectorDecoratorView()) { @Override protected void registerSynchronizers(Mapper.SynchronizersConfiguration configuration) { super.registerSynchronizers(configuration); DiagramCell diagramCell = getDiagramCell(); if (diagramCell == null) { return; } final Mapper<? super SNode, ?> descendantMapper = getDiagramCell().getRootMapper().getDescendantMapper(getSNode()); if (descendantMapper == null) { return; } configuration.add(Synchronizers.forProperty(myErrorItem, getTarget().hasError)); configuration.add(Synchronizers.forProperty(((PolyLineConnection) descendantMapper.getTarget()).view().focused(), getTarget().isSelected)); ReadableProperty<Boolean> valid = ((PolyLineConnection) descendantMapper.getTarget()).view().valid(); configuration.add(Synchronizers.forProperty(valid, getTarget().isValid())); } }; } private ConnectorDecoratorView createConnectorDecoratorView() { ConnectorDecoratorView connectorDecoratorView = new ConnectorDecoratorView(); DiagramCell diagramCell = getDiagramCell(); if (diagramCell == null) { return connectorDecoratorView; } Mapper<? super SNode, ?> descendantMapper = getDiagramCell().getRootMapper().getDescendantMapper(getSNode()); if (descendantMapper == null) { return connectorDecoratorView; } connectorDecoratorView.setSegments(((PolyLineConnection) descendantMapper.getTarget()).getSegments()); return connectorDecoratorView; } public void synchronize() { myInputPort.set(MultiTuple.<SNode,SNode>from(SLinkOperations.getTarget(SLinkOperations.getTarget(getSNode(), MetaAdapterFactory.getContainmentLink(0x913a1d639e1948faL, 0xad03e33ecccd3814L, 0x20a804e2ec441516L, 0x49664459198225c0L, "source")), MetaAdapterFactory.getReferenceLink(0x913a1d639e1948faL, 0xad03e33ecccd3814L, 0x4966445919822461L, 0x49664459198225bcL, "block")), SLinkOperations.getTarget(SLinkOperations.getTarget(getSNode(), MetaAdapterFactory.getContainmentLink(0x913a1d639e1948faL, 0xad03e33ecccd3814L, 0x20a804e2ec441516L, 0x49664459198225c0L, "source")), MetaAdapterFactory.getReferenceLink(0x913a1d639e1948faL, 0xad03e33ecccd3814L, 0x4966445919822461L, 0x49664459198225bdL, "metaPort")))); myOutputPort.set(MultiTuple.<SNode,SNode>from(SLinkOperations.getTarget(SLinkOperations.getTarget(getSNode(), MetaAdapterFactory.getContainmentLink(0x913a1d639e1948faL, 0xad03e33ecccd3814L, 0x20a804e2ec441516L, 0x49664459198225c6L, "target")), MetaAdapterFactory.getReferenceLink(0x913a1d639e1948faL, 0xad03e33ecccd3814L, 0x4966445919822461L, 0x49664459198225bcL, "block")), SLinkOperations.getTarget(SLinkOperations.getTarget(getSNode(), MetaAdapterFactory.getContainmentLink(0x913a1d639e1948faL, 0xad03e33ecccd3814L, 0x20a804e2ec441516L, 0x49664459198225c6L, "target")), MetaAdapterFactory.getReferenceLink(0x913a1d639e1948faL, 0xad03e33ecccd3814L, 0x4966445919822461L, 0x49664459198225bdL, "metaPort")))); } private PolyLineConnection createConnection() { PolyLineConnection connection = new PolyLineConnection(); configureView(connection.view(), new _FunctionTypes._return_P0_E0<Boolean>() { public Boolean invoke() { return true; } }); return connection; } } }