Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Scout/Concepts/CodeType/Example"

< Scout‎ | Concepts‎ | CodeType
(Code)
(Update to Luna)
Line 12: Line 12:
 
==Code==
 
==Code==
 
<source lang="java">
 
<source lang="java">
public class YesOrNoCodeType extends AbstractCodeType<String> {
+
public class YesOrNoCodeType extends AbstractCodeType<String, Boolean> {
 +
 
 
   private static final long serialVersionUID = 1L;
 
   private static final long serialVersionUID = 1L;
   public static final String ID = "YesOrNo";
+
   public static final String ID = "YesNo";
  
 +
  /**
 +
  * @throws org.eclipse.scout.commons.exception.ProcessingException
 +
  */
 
   public YesOrNoCodeType() throws ProcessingException {
 
   public YesOrNoCodeType() throws ProcessingException {
 
     super();
 
     super();
  }
 
 
  @Override
 
  protected String getConfiguredText() {
 
    return TEXTS.get("YesOrNo");
 
 
   }
 
   }
  
Line 31: Line 30:
  
 
   @Order(10.0)
 
   @Order(10.0)
   public class YesCode extends AbstractCode<Boolean> {
+
   public static class YesCode extends AbstractCode<Boolean> {
 +
 
 
     private static final long serialVersionUID = 1L;
 
     private static final long serialVersionUID = 1L;
     public final Boolean ID = Boolean.TRUE;
+
     public static final Boolean ID = Boolean.TRUE;
  
 
     @Override
 
     @Override
Line 47: Line 47:
  
 
   @Order(20.0)
 
   @Order(20.0)
   public class NoCode extends AbstractCode<Boolean> {
+
   public static class NoCode extends AbstractCode<Boolean> {
 +
 
 
     private static final long serialVersionUID = 1L;
 
     private static final long serialVersionUID = 1L;
     public final Boolean ID = Boolean.FALSE;
+
     public static final Boolean ID = Boolean.FALSE;
  
 
     @Override
 
     @Override
Line 68: Line 69:
 
<source lang="java">
 
<source lang="java">
 
public class YesOrNoSmartField extends AbstractSmartField<Boolean> {
 
public class YesOrNoSmartField extends AbstractSmartField<Boolean> {
   // other configuration of properties.
+
 
 +
   // other configuration of properties...
 +
 
 
   @Override
 
   @Override
   protected Class<? extends ICodeType<?>> getConfiguredCodeType(){
+
   protected Class<? extends ICodeType<?, Boolean>> getConfiguredCodeType() {
 
     return YesOrNoCodeType.class;
 
     return YesOrNoCodeType.class;
 
   }
 
   }

Revision as of 05:21, 22 July 2014

The Scout documentation has been moved to https://eclipsescout.github.io/.

This page contains some example Java code for a simple The Scout documentation has been moved to https://eclipsescout.github.io/. having just two The Scout documentation has been moved to https://eclipsescout.github.io/.:

  • YesOrNoCodeType.YesCode
  • YesOrNoCodeType.NoCode


Notice that the CodeType Id is a String and that both code have an Boolean Id.

The definition of codes is reduced to an Id and a Text, but we could also imagine to configure the IconId or the Tooltip.

Code

public class YesOrNoCodeType extends AbstractCodeType<String, Boolean> {
 
  private static final long serialVersionUID = 1L;
  public static final String ID = "YesNo";
 
  /**
   * @throws org.eclipse.scout.commons.exception.ProcessingException
   */
  public YesOrNoCodeType() throws ProcessingException {
    super();
  }
 
  @Override
  public String getId() {
    return ID;
  }
 
  @Order(10.0)
  public static class YesCode extends AbstractCode<Boolean> {
 
    private static final long serialVersionUID = 1L;
    public static final Boolean ID = Boolean.TRUE;
 
    @Override
    protected String getConfiguredText() {
      return TEXTS.get("Yes");
    }
 
    @Override
    public Boolean getId() {
      return ID;
    }
  }
 
  @Order(20.0)
  public static class NoCode extends AbstractCode<Boolean> {
 
    private static final long serialVersionUID = 1L;
    public static final Boolean ID = Boolean.FALSE;
 
    @Override
    protected String getConfiguredText() {
      return TEXTS.get("No");
    }
 
    @Override
    public Boolean getId() {
      return ID;
    }
  }
}

Usage

This code Type can be used in a The Scout documentation has been moved to https://eclipsescout.github.io/. extending AbstractSmartField<Boolean>

public class YesOrNoSmartField extends AbstractSmartField<Boolean> {
 
  // other configuration of properties...
 
  @Override
  protected Class<? extends ICodeType<?, Boolean>> getConfiguredCodeType() {
    return YesOrNoCodeType.class;
  }
}

In the SDK

The Scout documentation has been moved to https://eclipsescout.github.io/. proposes a graphical representation of this CodeType. It is possible to modify the corresponding Java code directly in the SDK.

ScoutSDK CodeType.png

Back to the top