|
|
Line 1: |
Line 1: |
− | {{ScoutPage|cat=Shared}}
| + | The Scout documentation has been moved to https://eclipsescout.github.io/. |
− | | + | |
− | This page contains some example Java code for a simple {{ScoutLink|Concepts|CodeType|CodeType}} having just two {{ScoutLink|Concepts|Code|codes}}:
| + | |
− | * <code>YesOrNoCodeType.YesCode</code>
| + | |
− | * <code>YesOrNoCodeType.NoCode</code>
| + | |
− | | + | |
− | | + | |
− | 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==
| + | |
− | <source lang="java">
| + | |
− | 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;
| + | |
− | }
| + | |
− | }
| + | |
− | }
| + | |
− | </source>
| + | |
− | | + | |
− | ==Usage==
| + | |
− | This code Type can be used in a {{ScoutLink|Concepts|SmartField|SmartField}} extending <code>AbstractSmartField<Boolean></code>
| + | |
− | <source lang="java">
| + | |
− | public class YesOrNoSmartField extends AbstractSmartField<Boolean> {
| + | |
− | | + | |
− | // other configuration of properties...
| + | |
− | | + | |
− | @Override
| + | |
− | protected Class<? extends ICodeType<?, Boolean>> getConfiguredCodeType() {
| + | |
− | return YesOrNoCodeType.class;
| + | |
− | }
| + | |
− | }
| + | |
− | </source>
| + | |
− | | + | |
− | ==In the SDK==
| + | |
− | {{ScoutLink|SDK|Explorer View|Explorer View}} proposes a graphical representation of this CodeType. It is possible to modify the corresponding Java code directly in the SDK.
| + | |
− | | + | |
− | [[Image:ScoutSDK_CodeType.png]]
| + | |