Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/Java/GWT/OldClient/src/org/litesoft/GWT/forms/client/components/factories/input/UiComboBoxWidgetFactory.java

Diff revisions: vs.
  @@ -1,9 +1,6 @@
1 1 // This Source Code is in the Public Domain per: http://unlicense.org
2 2 package org.litesoft.GWT.forms.client.components.factories.input;
3 3
4 - import java.io.*;
5 - import java.util.*;
6 -
7 4 import org.litesoft.GWT.forms.client.components.factories.*;
8 5 import org.litesoft.GWT.forms.client.components.impls.input.*;
9 6 import org.litesoft.GWT.forms.client.nonpublic.*;
  @@ -14,12 +11,13 @@
14 11
15 12 import com.google.gwt.user.client.ui.*;
16 13
17 - public class UiComboBoxWidgetFactory implements InputWidgetFactory
18 - {
14 + import java.io.*;
15 + import java.util.*;
16 +
17 + public class UiComboBoxWidgetFactory implements InputWidgetFactory {
19 18 public Widget create( FormInstanceComponentHandler pComponentHandler, //
20 19 UiInputDef pUiDef, AttributeMetaData pMetaData,
21 - boolean pHasHorizontalPeer )
22 - {
20 + boolean pHasHorizontalPeer ) {
23 21 ComboBoxMetaData zMD = (ComboBoxMetaData) pMetaData;
24 22
25 23 String zLabelText = !pUiDef.isLabelLess() ? zMD.getExternalText() : null;
  @@ -30,13 +28,11 @@
30 28 createFormComboBox( zLabelText, zLabelFont, zTooltip ) ).init();
31 29 }
32 30
33 - protected FormComboBox createFormComboBox( String pLabelText, UiFont pLabelFont, String pTooltip )
34 - {
31 + protected FormComboBox createFormComboBox( String pLabelText, UiFont pLabelFont, String pTooltip ) {
35 32 return new FormComboBox( pLabelText, pLabelFont, pTooltip );
36 33 }
37 34
38 - private static final class MyFormAdapter extends AbstractFormRequireableAttributeAdapter
39 - {
35 + private static final class MyFormAdapter extends AbstractFormRequireableAttributeAdapter {
40 36 private FormComboBox mFC;
41 37 private SimpleKeyValuePair mOptionZero;
42 38 private SimpleKeyValuePair[] mValidOptions;
  @@ -44,58 +40,47 @@
44 40 private boolean mHasFocus = false;
45 41
46 42 public MyFormAdapter( FormInstanceComponentHandler pComponentHandler, //
47 - ComboBoxMetaData pMD, FormComboBox pFC )
48 - {
43 + ComboBoxMetaData pMD, FormComboBox pFC ) {
49 44 super( pComponentHandler, pMD, pMD, pFC );
50 45 mFC = pFC;
51 46 mFC.addItem( mOptionZero = pMD.getNoSendOptionZero() );
52 47 mFC.addItems( mValidOptions = pMD.getValidOptions() );
53 48 }
54 49
55 - public void updateValidOptions( Serializable[] pValidOptions )
56 - {
50 + public void updateValidOptions( Serializable[] pValidOptions ) {
57 51 convertOptions( pValidOptions );
58 - if ( !mHasFocus || mFC.areOptionsAlwaysUpdatable() )
59 - {
52 + if ( !mHasFocus || mFC.areOptionsAlwaysUpdatable() ) {
60 53 LLupdateValidOptions();
61 54 }
62 55 }
63 56
64 - private void convertOptions( Serializable[] pValidOptions )
65 - {
57 + private void convertOptions( Serializable[] pValidOptions ) {
66 58 mNewValidOptions.clear();
67 - if ( pValidOptions != null )
68 - {
69 - for ( Serializable zValidOption : pValidOptions )
70 - {
59 + if ( pValidOptions != null ) {
60 + for ( Serializable zValidOption : pValidOptions ) {
71 61 SimpleKeyValuePair option = convertOption( zValidOption );
72 - if ( option != null )
73 - {
62 + if ( option != null ) {
74 63 mNewValidOptions.add( option );
75 64 }
76 65 }
77 66 }
78 67 }
79 68
80 - private void LLupdateValidOptions()
81 - {
82 - if ( !mNewValidOptions.isEmpty() )
83 - {
69 + private void LLupdateValidOptions() {
70 + if ( !mNewValidOptions.isEmpty() ) {
84 71 // save the currently select & null it if it is the default option zero
85 72 SimpleKeyValuePair selected = convertOption( mFC.getSelectedKeyValuePair() );
86 73
87 74 mFC.setSelectedIndex( -1 );
88 75
89 76 // Remove all the old options
90 - for ( SimpleKeyValuePair zValuePair : mValidOptions )
91 - {
77 + for ( SimpleKeyValuePair zValuePair : mValidOptions ) {
92 78 mFC.removeItem( zValuePair );
93 79 }
94 80 // Add all the new ones & note if old current selected was found
95 81 mValidOptions = new SimpleKeyValuePair[mNewValidOptions.size()];
96 82 boolean found = false;
97 - for ( int i = 0; i < mNewValidOptions.size(); i++ )
98 - {
83 + for ( int i = 0; i < mNewValidOptions.size(); i++ ) {
99 84 SimpleKeyValuePair option = (SimpleKeyValuePair) mNewValidOptions.get( i );
100 85 found |= option.equals( selected );
101 86 mFC.addItem( mValidOptions[i] = option );
  @@ -106,66 +91,53 @@
106 91 }
107 92 }
108 93
109 - protected Object getComponentCurrentValue()
110 - {
94 + protected Object getComponentCurrentValue() {
111 95 Object rv = super.getComponentCurrentValue();
112 96 return !areEqual( rv, mOptionZero ) ? rv : null;
113 97 }
114 98
115 - protected void setComponentCurrentValue( Object pCurrentValue )
116 - {
117 - if ( pCurrentValue == null )
118 - {
99 + protected void setComponentCurrentValue( Object pCurrentValue ) {
100 + if ( pCurrentValue == null ) {
119 101 pCurrentValue = mOptionZero;
120 102 }
121 103 super.setComponentCurrentValue( pCurrentValue );
122 104 }
123 105
124 - protected Serializable convertComponentValueToSendable( Object pValue )
125 - {
106 + protected Serializable convertComponentValueToSendable( Object pValue ) {
126 107 return !areEqual( pValue, mOptionZero ) ? (Serializable) pValue : null;
127 108 }
128 109
129 - protected Object convertSendableToComponentValue( Serializable pValue )
130 - {
110 + protected Object convertSendableToComponentValue( Serializable pValue ) {
131 111 return convertOption( pValue );
132 112 }
133 113
134 - protected String convertComponentValueToString( Object pValue )
135 - {
136 - if ( pValue instanceof SimpleKeyValuePair )
137 - {
114 + protected String convertComponentValueToString( Object pValue ) {
115 + if ( pValue instanceof SimpleKeyValuePair ) {
138 116 return "@" + ((SimpleKeyValuePair) pValue).getKey();
139 117 }
140 118 return (pValue == null) ? "null" : "?" + pValue;
141 119 }
142 120
143 - protected Object convertStringToComponentValue( String pValue )
144 - {
145 - if ( (pValue == null) || pValue.equals( "null" ) )
146 - {
121 + protected Object convertStringToComponentValue( String pValue ) {
122 + if ( (pValue == null) || pValue.equals( "null" ) ) {
147 123 return null;
148 124 }
149 125 return pValue.startsWith( "@" ) ? pValue.substring( 1 ) : pValue;
150 126 }
151 127
152 - public void focusOccured()
153 - {
128 + public void focusOccured() {
154 129 super.focusOccured();
155 130 mHasFocus = true;
156 131 }
157 132
158 - public void blurOccurred()
159 - {
133 + public void blurOccurred() {
160 134 mHasFocus = false;
161 135 LLupdateValidOptions();
162 136 super.blurOccurred();
163 137 }
164 138
165 - private SimpleKeyValuePair convertOption( Serializable pValue )
166 - {
167 - if ( pValue == null )
168 - {
139 + private SimpleKeyValuePair convertOption( Serializable pValue ) {
140 + if ( pValue == null ) {
169 141 return null;
170 142 }
171 143 SimpleKeyValuePair rv = (pValue instanceof SimpleKeyValuePair) ? //