All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.rap.rwt.template.TextCell Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2013 EclipseSource and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    EclipseSource - initial API and implementation
 ******************************************************************************/
package org.eclipse.rap.rwt.template;

import org.eclipse.rap.json.JsonObject;
import org.eclipse.rap.rwt.internal.util.ParamCheck;


/**
 * Defines a region in a template that displays a text.
 *
 * @since 2.2
 */
public class TextCell extends Cell  {

  private static final String TYPE_TEXT = "text";
  private static final String PROPERTY_TEXT = "text";
  private static final String PROPERTY_WRAP = "wrap";
  private String text;
  private boolean wrap;

  /**
   * Constructs a new text cell and adds it to the given template.
   */
  public TextCell( Template template ) {
    super( template, TYPE_TEXT );
  }

  /**
   * Sets the text to be displayed in the cell if the bindingIndex is not set.
   * Can be used to display a static text.
   *
   * @param text the text to display, must not be null
   * @return the cell itself, to enable method chaining
   */
  public TextCell setText( String text ) {
    ParamCheck.notNull( text, "text" );
    this.text = text;
    return this;
  }

  String getText() {
    return text;
  }

  /**
   * Enables automatic line wrapping. The default is false.
   *
   * @param wrap true to enable automatic line wrapping
   * @return the cell itself, to enable method chaining
   */
  public TextCell setWrap( boolean wrap ) {
    this.wrap = wrap;
    return this;
  }

  boolean isWrap() {
    return wrap;
  }

  @Override
  protected JsonObject toJson() {
    JsonObject json = super.toJson();
    if( text != null ) {
      json.add( PROPERTY_TEXT, text );
    }
    if( wrap ) {
      json.add( PROPERTY_WRAP, wrap );
    }
    return json;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy