package jetbrains.mps.lang.generator.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.EditorCell_Collection;
import jetbrains.mps.nodeEditor.cellLayout.CellLayout_Indent;
import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.AttributeOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.nodeEditor.cells.EditorCell_Constant;
import jetbrains.mps.openapi.editor.style.Style;
import jetbrains.mps.editor.runtime.style.StyleImpl;
import jetbrains.mps.lang.generator.editor.Styles_StyleSheet.macroStartStyleClass;
import jetbrains.mps.editor.runtime.style.StyleAttributes;
import jetbrains.mps.editor.runtime.style.FocusPolicy;
import jetbrains.mps.nodeEditor.cellMenu.CompositeSubstituteInfo;
import jetbrains.mps.nodeEditor.cellMenu.BasicCellContext;
import jetbrains.mps.nodeEditor.cellMenu.SubstituteInfoPartExt;
import jetbrains.mps.nodeEditor.cellMenu.SChildSubstituteInfoPartEx;
import java.util.List;
import jetbrains.mps.openapi.editor.cells.SubstituteAction;
import jetbrains.mps.nodeEditor.cellMenu.CellContext;
import jetbrains.mps.lang.editor.cellProviders.SingleRoleCellProvider;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import jetbrains.mps.openapi.editor.cells.CellActionType;
import jetbrains.mps.editor.runtime.impl.cellActions.CellAction_DeleteSmart;
import jetbrains.mps.openapi.editor.cells.DefaultSubstituteInfo;
import jetbrains.mps.nodeEditor.cellMenu.SChildSubstituteInfo;
import jetbrains.mps.openapi.editor.menus.transformation.SNodeLocation;
/*package*/ class IfMacro_EditorBuilder_a extends AbstractEditorBuilder {
@NotNull
private SNode myNode;
public IfMacro_EditorBuilder_a(@NotNull EditorContext context, @NotNull SNode node) {
super(context);
myNode = node;
}
@NotNull
@Override
public SNode getNode() {
return myNode;
}
/*package*/ EditorCell createCell() {
return createCollection_t4g6n2_a();
}
private EditorCell createCollection_t4g6n2_a() {
EditorCell_Collection editorCell = new EditorCell_Collection(getEditorContext(), myNode, new CellLayout_Indent());
editorCell.setCellId("Collection_t4g6n2_a");
editorCell.setBig(true);
editorCell.setCellContext(getCellFactory().getCellContext());
editorCell.addEditorCell(createCollection_t4g6n2_a0());
if (nodeCondition_t4g6n2_a1a()) {
editorCell.addEditorCell(createCollection_t4g6n2_b0());
}
return editorCell;
}
private boolean nodeCondition_t4g6n2_a1a() {
return Sequence.fromIterable(AttributeOperations.getChildNodesAndAttributes(myNode, MetaAdapterFactory.getContainmentLink(0xb401a68083254110L, 0x8fd384331ff25befL, 0x1047c1472deL, 0x1163aea5803L, "alternativeConsequence"))).isNotEmpty();
}
private EditorCell createCollection_t4g6n2_a0() {
EditorCell_Collection editorCell = new EditorCell_Collection(getEditorContext(), myNode, new CellLayout_Indent());
editorCell.setCellId("Collection_t4g6n2_a0");
editorCell.addEditorCell(createConstant_t4g6n2_a0a());
editorCell.addEditorCell(createComponent_t4g6n2_b0a());
if (nodeCondition_t4g6n2_a2a0()) {
editorCell.addEditorCell(createConstant_t4g6n2_c0a());
}
return editorCell;
}
private boolean nodeCondition_t4g6n2_a2a0() {
return (SLinkOperations.getTarget(myNode, MetaAdapterFactory.getContainmentLink(0xb401a68083254110L, 0x8fd384331ff25befL, 0x1047c1472deL, 0x1163aea5803L, "alternativeConsequence")) != null);
}
private EditorCell createConstant_t4g6n2_a0a() {
EditorCell_Constant editorCell = new EditorCell_Constant(getEditorContext(), myNode, "$IF$");
editorCell.setCellId("Constant_t4g6n2_a0a");
Style style = new StyleImpl();
new macroStartStyleClass(getEditorContext(), getNode()).apply(style, editorCell);
editorCell.getStyle().putAll(style);
if (true) {
editorCell.getStyle().set(StyleAttributes.FOCUS_POLICY, FocusPolicy.ATTRACTS_FOCUS);
}
MacroSymbol_Actions.setCellActions(editorCell, myNode, getEditorContext());
editorCell.setDefaultText("");
editorCell.setSubstituteInfo(new CompositeSubstituteInfo(getEditorContext(), new BasicCellContext(myNode), new SubstituteInfoPartExt[]{new IfMacro_EditorBuilder_a.IfMacro_component_cellMenu_t4g6n2_a0a0a(), new SChildSubstituteInfoPartEx(editorCell)}));
return editorCell;
}
public static class IfMacro_component_cellMenu_t4g6n2_a0a0a implements SubstituteInfoPartExt {
private replace_node_macro myComponent;
public IfMacro_component_cellMenu_t4g6n2_a0a0a() {
this.myComponent = new replace_node_macro();
}
public List<SubstituteAction> createActions(CellContext cellContext, EditorContext editorContext) {
return this.myComponent.createSubstituteActions(cellContext, editorContext);
}
}
private EditorCell createComponent_t4g6n2_b0a() {
EditorCell editorCell = getCellFactory().createEditorComponentCell(myNode, "jetbrains.mps.lang.generator.editor.NodeMacro_postfix");
Style style = new StyleImpl();
style.set(StyleAttributes.INDENT_LAYOUT_NO_WRAP, true);
editorCell.getStyle().putAll(style);
return editorCell;
}
private EditorCell createConstant_t4g6n2_c0a() {
EditorCell_Constant editorCell = new EditorCell_Constant(getEditorContext(), myNode, "/");
editorCell.setCellId("Constant_t4g6n2_c0a");
editorCell.setDefaultText("");
return editorCell;
}
private EditorCell createCollection_t4g6n2_b0() {
EditorCell_Collection editorCell = new EditorCell_Collection(getEditorContext(), myNode, new CellLayout_Indent());
editorCell.setCellId("Collection_t4g6n2_b0");
Style style = new StyleImpl();
style.set(StyleAttributes.SELECTABLE, false);
style.set(StyleAttributes.INDENT_LAYOUT_ON_NEW_LINE, true);
editorCell.getStyle().putAll(style);
editorCell.addEditorCell(createConstant_t4g6n2_a1a());
editorCell.addEditorCell(createRefNode_t4g6n2_b1a());
return editorCell;
}
private EditorCell createConstant_t4g6n2_a1a() {
EditorCell_Constant editorCell = new EditorCell_Constant(getEditorContext(), myNode, "$ELSE$");
editorCell.setCellId("Constant_t4g6n2_a1a");
Style style = new StyleImpl();
new macroStartStyleClass(getEditorContext(), getNode()).apply(style, editorCell);
editorCell.getStyle().putAll(style);
editorCell.setDefaultText("");
return editorCell;
}
private EditorCell createRefNode_t4g6n2_b1a() {
SingleRoleCellProvider provider = new IfMacro_EditorBuilder_a.alternativeConsequenceSingleRoleHandler_t4g6n2_b1a(myNode, MetaAdapterFactory.getContainmentLink(0xb401a68083254110L, 0x8fd384331ff25befL, 0x1047c1472deL, 0x1163aea5803L, "alternativeConsequence"), getEditorContext());
return provider.createCell();
}
private static class alternativeConsequenceSingleRoleHandler_t4g6n2_b1a extends SingleRoleCellProvider {
@NotNull
private SNode myNode;
public alternativeConsequenceSingleRoleHandler_t4g6n2_b1a(SNode ownerNode, SContainmentLink containmentLink, EditorContext context) {
super(containmentLink, context);
myNode = ownerNode;
}
@Override
@NotNull
public SNode getNode() {
return myNode;
}
protected EditorCell createChildCell(SNode child) {
EditorCell editorCell = getUpdateSession().updateChildNodeCell(child);
editorCell.setAction(CellActionType.DELETE, new CellAction_DeleteSmart(getNode(), MetaAdapterFactory.getContainmentLink(0xb401a68083254110L, 0x8fd384331ff25befL, 0x1047c1472deL, 0x1163aea5803L, "alternativeConsequence"), child));
editorCell.setAction(CellActionType.BACKSPACE, new CellAction_DeleteSmart(getNode(), MetaAdapterFactory.getContainmentLink(0xb401a68083254110L, 0x8fd384331ff25befL, 0x1047c1472deL, 0x1163aea5803L, "alternativeConsequence"), child));
installCellInfo(child, editorCell);
return editorCell;
}
private void installCellInfo(SNode child, EditorCell editorCell) {
if (editorCell.getSubstituteInfo() == null || editorCell.getSubstituteInfo() instanceof DefaultSubstituteInfo) {
editorCell.setSubstituteInfo(new SChildSubstituteInfo(editorCell, myNode, MetaAdapterFactory.getContainmentLink(0xb401a68083254110L, 0x8fd384331ff25befL, 0x1047c1472deL, 0x1163aea5803L, "alternativeConsequence"), child));
}
if (editorCell.getRole() == null) {
editorCell.setRole("alternativeConsequence");
}
Style style = new StyleImpl();
style.set(StyleAttributes.DRAW_BRACKETS, true);
style.set(StyleAttributes.INDENT_LAYOUT_NO_WRAP, true);
editorCell.getStyle().putAll(style);
}
@Override
protected EditorCell createEmptyCell() {
getCellFactory().pushCellContext();
getCellFactory().setNodeLocation(new SNodeLocation.FromParentAndLink(getNode(), MetaAdapterFactory.getContainmentLink(0xb401a68083254110L, 0x8fd384331ff25befL, 0x1047c1472deL, 0x1163aea5803L, "alternativeConsequence")));
try {
EditorCell editorCell = super.createEmptyCell();
editorCell.setCellId("empty_alternativeConsequence");
installCellInfo(null, editorCell);
setCellContext(editorCell);
return editorCell;
} finally {
getCellFactory().popCellContext();
}
}
protected String getNoTargetText() {
return "<no alternativeConsequence>";
}
}
}