Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/OldClient/src/org/litesoft/GWT/forms/client/components/factories/others/BaseFormComponentFactory.java

Diff revisions: vs.
  @@ -1,73 +1,73 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.forms.client.components.factories.others;
3 -
4 - import org.litesoft.GWT.forms.client.components.factories.*;
5 - import org.litesoft.GWT.forms.client.nonpublic.*;
6 - import org.litesoft.commonfoundation.typeutils.Objects;
7 - import org.litesoft.ui.def.*;
8 - import org.litesoft.ui.def.nonpublic.*;
9 - import org.litesoft.ui.def.nonpublic.support.*;
10 -
11 - import com.google.gwt.user.client.ui.*;
12 -
13 - import java.util.*;
14 -
15 - public class BaseFormComponentFactory implements FormComponentFactory {
16 - public static final BaseFormComponentFactory INSTANCE = new BaseFormComponentFactory();
17 - private Map<UiD_Type, FormComponentFactory> mTypeToFactory = new HashMap<UiD_Type, FormComponentFactory>();
18 -
19 - private BaseFormComponentFactory() {
20 - addMapping( UiActionDef.TYPE, /* */ new UiActionWidgetFactory() );
21 - addMapping( UiHiddenAttributeDef.TYPE, /* */ new UiHiddenAttributeWidgetFactory() );
22 - addMapping( UiImageDef.TYPE, /* */ new UiImageWidgetFactory() );
23 - addMapping( UiInputActionDef.TYPE, /* */ new UiInputActionWidgetFactory() );
24 - addMapping( UiInputImageDef.TYPE, /* */ new UiInputImageWidgetFactory() );
25 - addMapping( UiInputDef.TYPE, /* */ new UiInputWidgetFactory() );
26 - addMapping( UiLabelDef.TYPE, /* */ new UiLabelWidgetFactory() );
27 - addMapping( UiSpacerDef.TYPE, /* */ new UiSpacerWidgetFactory() );
28 - addMapping( UiTreeMenuDef.TYPE, /* */ new UiTreeMenuWidgetFactory() );
29 - addMapping( UiViewDef.TYPE, /* */ UiViewWidgetFactory.INSTANCE );
30 - }
31 -
32 - public void addMapping( UiD_Type pUiDefType, FormComponentFactory pTypeFactory ) {
33 - Object prev = assertMappingAdjustment( pUiDefType, pTypeFactory );
34 - if ( prev != null ) {
35 - throw new IllegalStateException(
36 - "Duplicate FormComponentFactory for type (" + pUiDefType + "):" + //
37 - "\n prev: " + prev + //
38 - "\n new: " + pTypeFactory );
39 - }
40 - mTypeToFactory.put( pUiDefType, pTypeFactory );
41 - }
42 -
43 - public void replaceMapping( UiD_Type pUiDefType, FormComponentFactory pTypeFactory ) {
44 - Object prev = assertMappingAdjustment( pUiDefType, pTypeFactory );
45 - if ( prev == null ) {
46 - throw new IllegalStateException(
47 - "No Existing FormComponentFactory for type (" + pUiDefType + "):" + //
48 - "\n new: " + pTypeFactory );
49 - }
50 - mTypeToFactory.put( pUiDefType, pTypeFactory );
51 - }
52 -
53 - private Object assertMappingAdjustment( UiD_Type pUiDefType, FormComponentFactory pTypeFactory ) {
54 - Objects.assertNotNull( "UiDefType", pUiDefType );
55 - Objects.assertNotNull( "TypeFactory", pTypeFactory );
56 -
57 - return mTypeToFactory.get( pUiDefType );
58 - }
59 -
60 - private FormComponentFactory getMapping( UiD_Type pUiDefType ) {
61 - return mTypeToFactory.get( pUiDefType );
62 - }
63 -
64 - public Widget create( FormInstanceComponentHandler pComponentHandler, UiDef pUiDef,
65 - FormMetaData pFormMetaData, boolean pHasHorizontalPeer ) {
66 - FormComponentFactory factory = getMapping( pUiDef.getType() );
67 - if ( factory == null ) {
68 - return new Label( "No FormComponentFactory for type: " + pUiDef.getType() );
69 - }
70 - return factory.create( pComponentHandler, pUiDef, pFormMetaData,
71 - pHasHorizontalPeer );
72 - }
73 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.forms.client.components.factories.others;
3 +
4 + import org.litesoft.GWT.forms.client.components.factories.*;
5 + import org.litesoft.GWT.forms.client.nonpublic.*;
6 + import org.litesoft.commonfoundation.base.*;
7 + import org.litesoft.ui.def.*;
8 + import org.litesoft.ui.def.nonpublic.*;
9 + import org.litesoft.ui.def.nonpublic.support.*;
10 +
11 + import com.google.gwt.user.client.ui.*;
12 +
13 + import java.util.*;
14 +
15 + public class BaseFormComponentFactory implements FormComponentFactory {
16 + public static final BaseFormComponentFactory INSTANCE = new BaseFormComponentFactory();
17 + private Map<UiD_Type, FormComponentFactory> mTypeToFactory = new HashMap<UiD_Type, FormComponentFactory>();
18 +
19 + private BaseFormComponentFactory() {
20 + addMapping( UiActionDef.TYPE, /* */ new UiActionWidgetFactory() );
21 + addMapping( UiHiddenAttributeDef.TYPE, /* */ new UiHiddenAttributeWidgetFactory() );
22 + addMapping( UiImageDef.TYPE, /* */ new UiImageWidgetFactory() );
23 + addMapping( UiInputActionDef.TYPE, /* */ new UiInputActionWidgetFactory() );
24 + addMapping( UiInputImageDef.TYPE, /* */ new UiInputImageWidgetFactory() );
25 + addMapping( UiInputDef.TYPE, /* */ new UiInputWidgetFactory() );
26 + addMapping( UiLabelDef.TYPE, /* */ new UiLabelWidgetFactory() );
27 + addMapping( UiSpacerDef.TYPE, /* */ new UiSpacerWidgetFactory() );
28 + addMapping( UiTreeMenuDef.TYPE, /* */ new UiTreeMenuWidgetFactory() );
29 + addMapping( UiViewDef.TYPE, /* */ UiViewWidgetFactory.INSTANCE );
30 + }
31 +
32 + public void addMapping( UiD_Type pUiDefType, FormComponentFactory pTypeFactory ) {
33 + Object prev = assertMappingAdjustment( pUiDefType, pTypeFactory );
34 + if ( prev != null ) {
35 + throw new IllegalStateException(
36 + "Duplicate FormComponentFactory for type (" + pUiDefType + "):" + //
37 + "\n prev: " + prev + //
38 + "\n new: " + pTypeFactory );
39 + }
40 + mTypeToFactory.put( pUiDefType, pTypeFactory );
41 + }
42 +
43 + public void replaceMapping( UiD_Type pUiDefType, FormComponentFactory pTypeFactory ) {
44 + Object prev = assertMappingAdjustment( pUiDefType, pTypeFactory );
45 + if ( prev == null ) {
46 + throw new IllegalStateException(
47 + "No Existing FormComponentFactory for type (" + pUiDefType + "):" + //
48 + "\n new: " + pTypeFactory );
49 + }
50 + mTypeToFactory.put( pUiDefType, pTypeFactory );
51 + }
52 +
53 + private Object assertMappingAdjustment( UiD_Type pUiDefType, FormComponentFactory pTypeFactory ) {
54 + Confirm.isNotNull( "UiDefType", pUiDefType );
55 + Confirm.isNotNull( "TypeFactory", pTypeFactory );
56 +
57 + return mTypeToFactory.get( pUiDefType );
58 + }
59 +
60 + private FormComponentFactory getMapping( UiD_Type pUiDefType ) {
61 + return mTypeToFactory.get( pUiDefType );
62 + }
63 +
64 + public Widget create( FormInstanceComponentHandler pComponentHandler, UiDef pUiDef,
65 + FormMetaData pFormMetaData, boolean pHasHorizontalPeer ) {
66 + FormComponentFactory factory = getMapping( pUiDef.getType() );
67 + if ( factory == null ) {
68 + return new Label( "No FormComponentFactory for type: " + pUiDef.getType() );
69 + }
70 + return factory.create( pComponentHandler, pUiDef, pFormMetaData,
71 + pHasHorizontalPeer );
72 + }
73 + }