Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/forms/client/components/impls/input/FormSuggestBox.java

Diff revisions: vs.
  @@ -1,112 +1,112 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.forms.client.components.impls.input;
3 -
4 - import org.litesoft.GWT.client.widgets.*;
5 - import org.litesoft.GWT.forms.client.components.nonpublic.*;
6 - import org.litesoft.commonfoundation.typeutils.*;
7 - import org.litesoft.uispecification.*;
8 -
9 - import com.google.gwt.core.client.*;
10 - import com.google.gwt.event.dom.client.*;
11 - import com.google.gwt.user.client.*;
12 - import com.google.gwt.user.client.ui.*;
13 -
14 - import java.util.*;
15 -
16 - public class FormSuggestBox extends AbstractOneLineTextElement {
17 - /**
18 - * @param pFieldLabel - empty means labelless
19 - * @param pLabelFont - null no label font adjustment
20 - * @param pTooltip - empty means no tooltip
21 - * @param pDisplayCharsWidth - null means floodX
22 - * @param pMaxChars - null means unlimited?
23 - * @param pOptions - Valid Options
24 - */
25 - public FormSuggestBox( String pFieldLabel, UiFont pLabelFont, String pTooltip, Integer pDisplayCharsWidth, Integer pMaxChars, String... pOptions ) {
26 - this( pFieldLabel, pLabelFont, pTooltip, pDisplayCharsWidth, pMaxChars, createOracle( pOptions ) );
27 - }
28 -
29 - public FormSuggestBox( String pFieldLabel, UiFont pLabelFont, String pTooltip, Integer pDisplayCharsWidth, Integer pMaxChars, List<String> pOptions ) {
30 - this( pFieldLabel, pLabelFont, pTooltip, pDisplayCharsWidth, pMaxChars, createOracle( pOptions ) );
31 - }
32 -
33 - public FormSuggestBox( String pFieldLabel, UiFont pLabelFont, String pTooltip, Integer pDisplayCharsWidth, Integer pMaxChars, SuggestOracle pSuggestList ) {
34 - this( pFieldLabel, pLabelFont, pTooltip, pDisplayCharsWidth, pMaxChars, new SuggestBoxChangeListenable( pSuggestList ) );
35 - }
36 -
37 - public FormSuggestBox( String pFieldLabel, UiFont pLabelFont, String pTooltip, Integer pDisplayCharsWidth, Integer pMaxChars,
38 - SuggestBoxChangeListenable pSuggestBox ) {
39 - super( pSuggestBox, pSuggestBox.getTextBox(), pTooltip, "frmSuggestBox", false, pDisplayCharsWidth, pMaxChars );
40 - initialize( pFieldLabel, pLabelFont, pTooltip );
41 - }
42 -
43 - @Override
44 - protected void initialize( String pFieldLabel, UiFont pLabelFont, String pTooltip ) {
45 - super.initialize( pFieldLabel, pLabelFont, pTooltip );
46 - getTextBox().addFocusHandler( new FocusHandler() {
47 - @Override
48 - public void onFocus( FocusEvent event ) {
49 - Scheduler.get().scheduleDeferred( new Command() {
50 - @Override
51 - public void execute() {
52 - if ( !isSuggestionListShowing() ) {
53 - if ( Strings.noEmpty( getTextBox().getText() ) == null ) {
54 - showSuggestionList();
55 - }
56 - }
57 - }
58 - } );
59 - }
60 - } );
61 - }
62 -
63 - @Override
64 - protected void fireBlurListeners() {
65 - setCurrentValue( getCurrentValue() ); // todo: Is this how to force an Error?
66 - super.fireBlurListeners();
67 - }
68 -
69 - public SuggestBoxChangeListenable getTextBox() {
70 - return (SuggestBoxChangeListenable) mInputWidget;
71 - }
72 -
73 - // *** Suggest Box Support ***/
74 -
75 - public boolean isSuggestionListShowing() {
76 - Widget zWidget = getInjectedInputWidget();
77 - return ((SuggestBoxChangeListenable) zWidget).isSuggestionListShowing(); // use: DefaultSuggestionDisplay.isSuggestionListShowing()
78 - }
79 -
80 - public void showSuggestionList() {
81 - Widget zWidget = getInjectedInputWidget();
82 - ((SuggestBoxChangeListenable) zWidget).showSuggestionList();
83 - }
84 -
85 - private static SuggestOracle createOracle( String[] pOptions ) {
86 - List<String> zOptions = Collections.emptyList();
87 - if ( pOptions != null ) {
88 - zOptions = Arrays.asList( pOptions );
89 - }
90 - return createOracle( zOptions );
91 - }
92 -
93 - private static SuggestOracle createOracle( List<String> pOptions ) {
94 - MultiWordSuggestOracle zOracle = new MultiWordSuggestOracle();
95 -
96 - if ( Lists.isNotNullOrEmpty( pOptions ) ) {
97 - zOracle.addAll( pOptions );
98 -
99 - List<String> zList = new ArrayList<String>();
100 - for ( int i = 0; i < pOptions.size(); i++ ) {
101 - if ( i < 9 ) {
102 - zList.add( pOptions.get( i ) );
103 - } else {
104 - zList.add( "--- More Options ---" );
105 - break;
106 - }
107 - }
108 - zOracle.setDefaultSuggestionsFromText( zList );
109 - }
110 - return zOracle;
111 - }
112 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.forms.client.components.impls.input;
3 +
4 + import org.litesoft.GWT.client.widgets.*;
5 + import org.litesoft.GWT.forms.client.components.nonpublic.*;
6 + import org.litesoft.commonfoundation.base.*;
7 + import org.litesoft.uispecification.*;
8 +
9 + import com.google.gwt.core.client.*;
10 + import com.google.gwt.event.dom.client.*;
11 + import com.google.gwt.user.client.*;
12 + import com.google.gwt.user.client.ui.*;
13 +
14 + import java.util.*;
15 +
16 + public class FormSuggestBox extends AbstractOneLineTextElement {
17 + /**
18 + * @param pFieldLabel - empty means labelless
19 + * @param pLabelFont - null no label font adjustment
20 + * @param pTooltip - empty means no tooltip
21 + * @param pDisplayCharsWidth - null means floodX
22 + * @param pMaxChars - null means unlimited?
23 + * @param pOptions - Valid Options
24 + */
25 + public FormSuggestBox( String pFieldLabel, UiFont pLabelFont, String pTooltip, Integer pDisplayCharsWidth, Integer pMaxChars, String... pOptions ) {
26 + this( pFieldLabel, pLabelFont, pTooltip, pDisplayCharsWidth, pMaxChars, createOracle( pOptions ) );
27 + }
28 +
29 + public FormSuggestBox( String pFieldLabel, UiFont pLabelFont, String pTooltip, Integer pDisplayCharsWidth, Integer pMaxChars, List<String> pOptions ) {
30 + this( pFieldLabel, pLabelFont, pTooltip, pDisplayCharsWidth, pMaxChars, createOracle( pOptions ) );
31 + }
32 +
33 + public FormSuggestBox( String pFieldLabel, UiFont pLabelFont, String pTooltip, Integer pDisplayCharsWidth, Integer pMaxChars, SuggestOracle pSuggestList ) {
34 + this( pFieldLabel, pLabelFont, pTooltip, pDisplayCharsWidth, pMaxChars, new SuggestBoxChangeListenable( pSuggestList ) );
35 + }
36 +
37 + public FormSuggestBox( String pFieldLabel, UiFont pLabelFont, String pTooltip, Integer pDisplayCharsWidth, Integer pMaxChars,
38 + SuggestBoxChangeListenable pSuggestBox ) {
39 + super( pSuggestBox, pSuggestBox.getTextBox(), pTooltip, "frmSuggestBox", false, pDisplayCharsWidth, pMaxChars );
40 + initialize( pFieldLabel, pLabelFont, pTooltip );
41 + }
42 +
43 + @Override
44 + protected void initialize( String pFieldLabel, UiFont pLabelFont, String pTooltip ) {
45 + super.initialize( pFieldLabel, pLabelFont, pTooltip );
46 + getTextBox().addFocusHandler( new FocusHandler() {
47 + @Override
48 + public void onFocus( FocusEvent event ) {
49 + Scheduler.get().scheduleDeferred( new Command() {
50 + @Override
51 + public void execute() {
52 + if ( !isSuggestionListShowing() ) {
53 + if ( ConstrainTo.significantOrNull( getTextBox().getText() ) == null ) {
54 + showSuggestionList();
55 + }
56 + }
57 + }
58 + } );
59 + }
60 + } );
61 + }
62 +
63 + @Override
64 + protected void fireBlurListeners() {
65 + setCurrentValue( getCurrentValue() ); // todo: Is this how to force an Error?
66 + super.fireBlurListeners();
67 + }
68 +
69 + public SuggestBoxChangeListenable getTextBox() {
70 + return (SuggestBoxChangeListenable) mInputWidget;
71 + }
72 +
73 + // *** Suggest Box Support ***/
74 +
75 + public boolean isSuggestionListShowing() {
76 + Widget zWidget = getInjectedInputWidget();
77 + return ((SuggestBoxChangeListenable) zWidget).isSuggestionListShowing(); // use: DefaultSuggestionDisplay.isSuggestionListShowing()
78 + }
79 +
80 + public void showSuggestionList() {
81 + Widget zWidget = getInjectedInputWidget();
82 + ((SuggestBoxChangeListenable) zWidget).showSuggestionList();
83 + }
84 +
85 + private static SuggestOracle createOracle( String[] pOptions ) {
86 + List<String> zOptions = Collections.emptyList();
87 + if ( pOptions != null ) {
88 + zOptions = Arrays.asList( pOptions );
89 + }
90 + return createOracle( zOptions );
91 + }
92 +
93 + private static SuggestOracle createOracle( List<String> pOptions ) {
94 + MultiWordSuggestOracle zOracle = new MultiWordSuggestOracle();
95 +
96 + if ( Currently.isNotNullOrEmpty( pOptions ) ) {
97 + zOracle.addAll( pOptions );
98 +
99 + List<String> zList = new ArrayList<String>();
100 + for ( int i = 0; i < pOptions.size(); i++ ) {
101 + if ( i < 9 ) {
102 + zList.add( pOptions.get( i ) );
103 + } else {
104 + zList.add( "--- More Options ---" );
105 + break;
106 + }
107 + }
108 + zOracle.setDefaultSuggestionsFromText( zList );
109 + }
110 + return zOracle;
111 + }
112 + }