litesoft
@ 950
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.forms.client.components.impls.input; import org.litesoft.GWT.client.*; import org.litesoft.GWT.client.widgets.*; import org.litesoft.GWT.client.widgets.nonpublic.*; import org.litesoft.commonfoundation.base.*; import org.litesoft.core.simpletypes.*; import org.litesoft.uispecification.*; import com.google.gwt.core.client.*; import com.google.gwt.event.dom.client.*; import com.google.gwt.user.client.*; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.*; public class FormImageSelectOptions extends FormImageSelector implements ResourceKeyNameURLsAvailableCallback { private ResourceKeyNameURLprovider mProvider; private SimplePanel mPopupListWrapper; private PointXY mPointXY; public FormImageSelectOptions( String pFieldLabel, UiFont pLabelFont, String pTooltip, boolean pViewOnly, ResourceKeyNameURLprovider pProvider, Integer pInitialWidth, boolean pWidthNotStretchable, Integer pInitialHeight, boolean pHeightNotStretchable ) { super( pFieldLabel, pLabelFont, pTooltip, pViewOnly, pInitialWidth, pWidthNotStretchable, pInitialHeight, pHeightNotStretchable ); mProvider = pProvider; mPickerButtonTooltip = "Select Image from List"; DialogBox zDialogBox = new DialogBox( true ); zDialogBox.add( buildPickerPanel() ); zDialogBox.setText( mPickerButtonTooltip ); mPickerButton.setTitle( mPickerButtonTooltip ); Cursor.Pointer.set( mPickerButton ); setPicker( zDialogBox ); } @Override public Object getCurrentValue() { return getCurrentResourceKeyNameURL(); } @Override public void setCurrentValue( Object pNewValue ) { setCurrentResourceKeyNameURL( (pNewValue instanceof ResourceKeyNameURL) ? (ResourceKeyNameURL) pNewValue : null ); } private Widget buildPickerPanel() { VerticalPanel zListPanel = new VerticalPanel(); zListPanel.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_CENTER ); mPopupListWrapper = new SimplePanel(); mPopupListWrapper.setHeight( "200" ); Element zElement = mPopupListWrapper.getElement(); CommonElementHelper.setOverflowAuto( zElement ); DOM.setStyleAttribute( zElement, "borderBottom", "solid 1px black" ); zListPanel.add( mPopupListWrapper ); zListPanel.add( new Spacer( 5 ) ); zListPanel.add( buildButtonPanel() ); return zListPanel; } private Widget buildButtonPanel() { Button zCancel = new Button( "Cancel" ); zCancel.addClickHandler( new ClickHandler() { @Override public void onClick( ClickEvent event ) { mPicker.hide(); } } ); return zCancel; } private int mSelectedIndx = -1; @Override protected void LLshowPicker( PointXY pPointXY ) { switchToLoading(); mPointXY = pPointXY; ResourceKeyNameURL[] zURLs = mProvider.getLocalResourceKeyNameURLs(); if ( zURLs != null ) { resourceKeyNameURLsAvailable( zURLs ); } else { mProvider.requestResourceKeyNameURLs( this ); } } @Override public void resourceKeyNameURLsAvailable( ResourceKeyNameURL[] pResourceKeyNameURLs ) { ListGrid zListGrid = new ListGrid( pResourceKeyNameURLs ); zListGrid.clearSelectedRow(); HTMLTable.RowFormatter zRowFormatter = zListGrid.getOurRowFormatter(); if ( mSelectedIndx >= 0 ) { zRowFormatter.addStyleName( mSelectedIndx, "ItemRow-Selected" ); } mPopupListWrapper.setWidget( zListGrid ); super.LLshowPicker( mPointXY ); restoreFromLoading(); } @Override public void resourceRequestFailed( ResourceOptionsErrorType pErrorType, String pErrorText ) { restoreFromLoading(); pickerClosed( true ); String zNIA = "No Images Available"; String zBody = zNIA; String zDetail = null; if ( pErrorType != null ) { switch ( pErrorType ) { default: case ErrorReferenceNotFound: case ErrorNullReturned: case ErrorNotResourceOptions: case ErrorNotImplemented: pErrorText = DeCamelizer.resolve( pErrorType.toString() ); // Fall Thru case ErrorOther: zDetail = pErrorText; zBody += "\n\nServer Error"; break; case NoneAvailable: zBody += "\n\nPlease Upload Image(s) to Server"; break; } } AlertManager.alert( "FISO", zNIA, zBody, zDetail ); } private String mCurrentTooltip; private void switchToLoading() { mCurrentTooltip = mPickerButtonTooltip; mPickerButton.setTitle( "Loading..." ); Cursor.Wait.set( mPickerButton ); } private void restoreFromLoading() { mPickerButton.setTitle( mCurrentTooltip ); Cursor.Pointer.set( mPickerButton ); } private class ListGrid extends TightGrid { private ResourceKeyNameURL[] mResources; private RowFormatter mRowFormatter; private static final String STYLE = "FormSelectorImageRowLabel"; public ListGrid( ResourceKeyNameURL[] pURLs ) { super( pURLs.length, 2 ); mResources = pURLs; for ( int i = 0; i < pURLs.length; i++ ) { ResourceKeyNameURL zURL = pURLs[i]; SizeableDualImage zImage = new SizeableDualImage( zURL.getURL() ); zImage.setImageSize( 64, 48 ); Label zLabel = new Label( zURL.getValue() ); zLabel.addStyleName( STYLE ); setWidget( i, 0, zImage ); setWidget( i, 1, zLabel ); mRowFormatter = getRowFormatter(); if ( i % 2 == 0 ) { mRowFormatter.addStyleName( i, "FormSelectorImageItem-reg" ); } else { mRowFormatter.addStyleName( i, "FormSelectorImageItem-alt" ); } } sinkEvents( Event.ONCLICK | Event.ONMOUSEOVER | Event.ONMOUSEOUT ); } public RowFormatter getOurRowFormatter() { return mRowFormatter; } private ResourceKeyNameURL getResource( int pIndex ) { if ( (pIndex >= 0) && (pIndex <= mResources.length) ) { return mResources[pIndex]; } else { return null; } } private void clearSelectedRow() { for ( int i = 0; i < getRowCount(); i++ ) { String zStyle = mRowFormatter.getStyleName( i ); if ( zStyle.contains( "ItemRow-Selected" ) ) { mRowFormatter.removeStyleName( i, "ItemRow-Selected" ); } } } @Override public void onBrowserEvent( Event event ) { int zIndx = getRowIndexForEvent( event ); switch ( DOM.eventGetType( event ) ) { case Event.ONCLICK: { mSelectedIndx = zIndx; mPicker.hide(); mRowFormatter.removeStyleName( zIndx, "ItemRow-Mouseover" ); final ResourceKeyNameURL zResource = getResource( zIndx ); Scheduler.get().scheduleDeferred( new Command() { @Override public void execute() { setCurrentValue( zResource ); } } ); break; } case Event.ONMOUSEOVER: { mRowFormatter.addStyleName( zIndx, "ItemRow-Mouseover" ); break; } case Event.ONMOUSEOUT: { mRowFormatter.removeStyleName( zIndx, "ItemRow-Mouseover" ); break; } default: { // Do nothing } } } private int getRowIndexForEvent( Event event ) { Element td = getEventTargetCell( event ); if ( td == null ) { return -1; } Element tr = DOM.getParent( td ); Element body = DOM.getParent( tr ); return DOM.getChildIndex( body, tr ); } } } |
Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/forms/client/components/impls/input/FormImageSelectOptions.java
Revision | Author | Commited | Message |
---|---|---|---|
950 Diff | GeorgeS | Thu 19 Jun, 2014 17:57:04 +0000 | New Lines |
948 Diff | GeorgeS | Sat 07 Jun, 2014 23:42:39 +0000 | Jusefuls Formatter Updated to New Code Format |
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
942 Diff | GeorgeS | Mon 02 Jun, 2014 23:41:46 +0000 | Extracting commonfoundation |
243 Diff | GeorgeS | Sun 05 Jun, 2011 20:29:12 +0000 | |
154 Diff | GeorgeS | Tue 22 Mar, 2011 20:46:40 +0000 | |
151 Diff | GeorgeS | Thu 17 Mar, 2011 04:16:22 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
23 Diff | GeorgeS | Wed 24 Feb, 2010 00:34:32 +0000 | |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |