1 /* 2 * Copyright 2008 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 package com.google.gwt.sample.showcase.client.content.panels; 17 18 import com.google.gwt.core.client.GWT; 19 import com.google.gwt.core.client.RunAsyncCallback; 20 import com.google.gwt.i18n.client.Constants; 21 import com.google.gwt.sample.showcase.client.ContentWidget; 22 import com.google.gwt.sample.showcase.client.ShowcaseAnnotations.ShowcaseData; 23 import com.google.gwt.sample.showcase.client.ShowcaseAnnotations.ShowcaseSource; 24 import com.google.gwt.sample.showcase.client.ShowcaseAnnotations.ShowcaseStyle; 25 import com.google.gwt.user.client.rpc.AsyncCallback; 26 import com.google.gwt.user.client.ui.CheckBox; 27 import com.google.gwt.user.client.ui.FlowPanel; 28 import com.google.gwt.user.client.ui.Widget; 29 30 /** 31 * Example file. 32 */ 33 @ShowcaseStyle(".cw-FlowPanel-checkBox") 34 public class CwFlowPanel extends ContentWidget { 35 /** 36 * The constants used in this Content Widget. 37 */ 38 @ShowcaseSource 39 public static interface CwConstants extends Constants { cwFlowPanelDescription()40 String cwFlowPanelDescription(); 41 cwFlowPanelItem()42 String cwFlowPanelItem(); 43 cwFlowPanelName()44 String cwFlowPanelName(); 45 } 46 47 /** 48 * An instance of the constants. 49 */ 50 @ShowcaseData 51 private final CwConstants constants; 52 53 /** 54 * Constructor. 55 * 56 * @param constants the constants 57 */ CwFlowPanel(CwConstants constants)58 public CwFlowPanel(CwConstants constants) { 59 super( 60 constants.cwFlowPanelName(), constants.cwFlowPanelDescription(), true); 61 this.constants = constants; 62 } 63 64 /** 65 * Initialize this example. 66 */ 67 @ShowcaseSource 68 @Override onInitialize()69 public Widget onInitialize() { 70 // Create a Flow Panel 71 FlowPanel flowPanel = new FlowPanel(); 72 flowPanel.ensureDebugId("cwFlowPanel"); 73 74 // Add some content to the panel 75 for (int i = 0; i < 30; i++) { 76 CheckBox checkbox = new CheckBox(constants.cwFlowPanelItem() + " " + i); 77 checkbox.addStyleName("cw-FlowPanel-checkBox"); 78 flowPanel.add(checkbox); 79 } 80 81 // Return the content 82 return flowPanel; 83 } 84 85 @Override asyncOnInitialize(final AsyncCallback<Widget> callback)86 protected void asyncOnInitialize(final AsyncCallback<Widget> callback) { 87 GWT.runAsync(CwFlowPanel.class, new RunAsyncCallback() { 88 89 public void onFailure(Throwable caught) { 90 callback.onFailure(caught); 91 } 92 93 public void onSuccess() { 94 callback.onSuccess(onInitialize()); 95 } 96 }); 97 } 98 } 99