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.widgets; 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.Showcase; 23 import com.google.gwt.sample.showcase.client.ShowcaseAnnotations.ShowcaseData; 24 import com.google.gwt.sample.showcase.client.ShowcaseAnnotations.ShowcaseSource; 25 import com.google.gwt.sample.showcase.client.ShowcaseAnnotations.ShowcaseStyle; 26 import com.google.gwt.sample.showcase.client.ShowcaseConstants; 27 import com.google.gwt.user.client.rpc.AsyncCallback; 28 import com.google.gwt.user.client.ui.HTML; 29 import com.google.gwt.user.client.ui.Hyperlink; 30 import com.google.gwt.user.client.ui.VerticalPanel; 31 import com.google.gwt.user.client.ui.Widget; 32 33 /** 34 * Example file. 35 */ 36 @ShowcaseStyle(".gwt-Hyperlink") 37 public class CwHyperlink extends ContentWidget { 38 /** 39 * The constants used in this Content Widget. 40 */ 41 @ShowcaseSource 42 public static interface CwConstants extends Constants { cwHyperlinkChoose()43 String cwHyperlinkChoose(); 44 cwHyperlinkDescription()45 String cwHyperlinkDescription(); 46 cwHyperlinkName()47 String cwHyperlinkName(); 48 } 49 50 /** 51 * An instance of the constants. 52 */ 53 @ShowcaseData 54 private final CwConstants constants; 55 56 /** 57 * Constructor. 58 * 59 * @param constants the constants 60 */ CwHyperlink(CwConstants constants)61 public CwHyperlink(CwConstants constants) { 62 super( 63 constants.cwHyperlinkName(), constants.cwHyperlinkDescription(), true); 64 this.constants = constants; 65 } 66 67 /** 68 * Initialize this example. 69 */ 70 @ShowcaseSource 71 @Override onInitialize()72 public Widget onInitialize() { 73 // Add a label 74 VerticalPanel vPanel = new VerticalPanel(); 75 vPanel.add(new HTML(constants.cwHyperlinkChoose())); 76 vPanel.setSpacing(5); 77 78 // Add a hyper link to each section in the Widgets category 79 ShowcaseConstants allConstants = (ShowcaseConstants) constants; 80 vPanel.add(getHyperlink(CwCheckBox.class, allConstants.cwCheckBoxName())); 81 vPanel.add( 82 getHyperlink(CwRadioButton.class, allConstants.cwRadioButtonName())); 83 vPanel.add( 84 getHyperlink(CwBasicButton.class, allConstants.cwBasicButtonName())); 85 vPanel.add( 86 getHyperlink(CwCustomButton.class, allConstants.cwCustomButtonName())); 87 vPanel.add( 88 getHyperlink(CwFileUpload.class, allConstants.cwFileUploadName())); 89 vPanel.add( 90 getHyperlink(CwDatePicker.class, allConstants.cwDatePickerName())); 91 92 // Return the panel 93 return vPanel; 94 } 95 96 @Override asyncOnInitialize(final AsyncCallback<Widget> callback)97 protected void asyncOnInitialize(final AsyncCallback<Widget> callback) { 98 GWT.runAsync(CwHyperlink.class, new RunAsyncCallback() { 99 100 public void onFailure(Throwable caught) { 101 callback.onFailure(caught); 102 } 103 104 public void onSuccess() { 105 callback.onSuccess(onInitialize()); 106 } 107 }); 108 } 109 110 /** 111 * Get a {@link Hyperlink} to a section based on the name of the 112 * {@link ContentWidget} example. 113 * 114 * @param cwClass the {@link ContentWidget} class 115 * @param name the name to display for the link 116 * @return a {@link Hyperlink} 117 */ 118 @ShowcaseSource getHyperlink( Class<C> cwClass, String name)119 private <C extends ContentWidget> Hyperlink getHyperlink( 120 Class<C> cwClass, String name) { 121 Hyperlink link = new Hyperlink( 122 name, Showcase.getContentWidgetToken(cwClass)); 123 link.ensureDebugId("cwHyperlink-" + cwClass.getName()); 124 return link; 125 } 126 } 127