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.user.client.rpc.AsyncCallback; 25 import com.google.gwt.user.client.ui.Button; 26 import com.google.gwt.user.client.ui.HorizontalPanel; 27 import com.google.gwt.user.client.ui.Widget; 28 29 /** 30 * Example file. 31 */ 32 public class CwHorizontalPanel extends ContentWidget { 33 /** 34 * The constants used in this Content Widget. 35 */ 36 @ShowcaseSource 37 public static interface CwConstants extends Constants { cwHorizontalPanelButton()38 String cwHorizontalPanelButton(); 39 cwHorizontalPanelDescription()40 String cwHorizontalPanelDescription(); 41 cwHorizontalPanelName()42 String cwHorizontalPanelName(); 43 } 44 45 /** 46 * An instance of the constants. 47 */ 48 @ShowcaseData 49 private final CwConstants constants; 50 51 /** 52 * Constructor. 53 * 54 * @param constants the constants 55 */ CwHorizontalPanel(CwConstants constants)56 public CwHorizontalPanel(CwConstants constants) { 57 super(constants.cwHorizontalPanelName(), 58 constants.cwHorizontalPanelDescription(), false); 59 this.constants = constants; 60 } 61 62 /** 63 * Initialize this example. 64 */ 65 @ShowcaseSource 66 @Override onInitialize()67 public Widget onInitialize() { 68 // Create a Horizontal Panel 69 HorizontalPanel hPanel = new HorizontalPanel(); 70 hPanel.setSpacing(5); 71 72 // Add some content to the panel 73 for (int i = 1; i < 5; i++) { 74 hPanel.add(new Button(constants.cwHorizontalPanelButton() + " " + i)); 75 } 76 77 // Return the content 78 hPanel.ensureDebugId("cwHorizontalPanel"); 79 return hPanel; 80 } 81 82 @Override asyncOnInitialize(final AsyncCallback<Widget> callback)83 protected void asyncOnInitialize(final AsyncCallback<Widget> callback) { 84 GWT.runAsync(CwHorizontalPanel.class, new RunAsyncCallback() { 85 86 public void onFailure(Throwable caught) { 87 callback.onFailure(caught); 88 } 89 90 public void onSuccess() { 91 callback.onSuccess(onInitialize()); 92 } 93 }); 94 } 95 } 96