package jetbrains.mps.lang.editor.figures.library; /*Generated by MPS */ import jetbrains.jetpad.model.property.Property; import jetbrains.jetpad.model.property.ValueProperty; import jetbrains.jetpad.cell.TextCell; import jetbrains.jetpad.cell.toView.CellView; import jetbrains.jetpad.values.Color; import jetbrains.jetpad.mapper.MapperFactory; import jetbrains.jetpad.mapper.Mapper; import jetbrains.jetpad.mapper.Synchronizers; import jetbrains.jetpad.model.property.WritableProperty; import jetbrains.jetpad.base.Registration; import jetbrains.jetpad.cell.text.TextEditing; public class NamedBoxFigure extends BoxFigure { public Property<Boolean> editable = new ValueProperty<Boolean>(true); private TextCell myCell = new TextCell(); public NamedBoxFigure() { this(new NamedBoxFigure.NamedBoxFigureMapperFactory()); } public NamedBoxFigure(NamedBoxFigure.NamedBoxFigureMapperFactory factory) { CellView cellView = new CellView(); myCell.textColor().set(Color.GRAY); myCell.text().set("<<No text>>"); cellView.cell.set(myCell); children().add(cellView); if (factory != null) { factory.createMapper(this).attachRoot(); } } public Property<String> nameText() { return myCell.text(); } private static class NamedBoxFigureMapperFactory implements MapperFactory<NamedBoxFigure, NamedBoxFigure> { public Mapper<? extends NamedBoxFigure, ? extends NamedBoxFigure> createMapper(NamedBoxFigure figure) { return new NamedBoxFigure.NamedBoxFigureMapper<NamedBoxFigure>(figure); } } protected static class NamedBoxFigureMapper<T extends NamedBoxFigure> extends BoxFigure.BoxFigureMapper<T> { protected NamedBoxFigureMapper(T figure) { super(figure); } @Override protected void registerSynchronizers(Mapper.SynchronizersConfiguration configuration) { super.registerSynchronizers(configuration); configuration.add(Synchronizers.forProperty(getSource().editable, new WritableProperty<Boolean>() { private Registration myRegistration; public void set(Boolean editable) { if (editable) { NamedBoxFigure source = getSource(); myRegistration = source.myCell.addTrait(TextEditing.textEditing()); } else if (myRegistration != null) { myRegistration.remove(); myRegistration = null; } } })); } } }