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.text; 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.ShowcaseSource; 23 import com.google.gwt.sample.showcase.client.ShowcaseAnnotations.ShowcaseStyle; 24 import com.google.gwt.user.client.rpc.AsyncCallback; 25 import com.google.gwt.user.client.ui.Grid; 26 import com.google.gwt.user.client.ui.RichTextArea; 27 import com.google.gwt.user.client.ui.Widget; 28 29 /** 30 * Example file. 31 */ 32 @ShowcaseStyle({ 33 ".gwt-RichTextArea", ".hasRichTextToolbar", ".gwt-RichTextToolbar", 34 ".cw-RichText"}) 35 public class CwRichText extends ContentWidget { 36 /** 37 * The constants used in this Content Widget. 38 */ 39 @ShowcaseSource 40 public static interface CwConstants extends Constants { cwRichTextDescription()41 String cwRichTextDescription(); 42 cwRichTextName()43 String cwRichTextName(); 44 } 45 46 /** 47 * Constructor. 48 * 49 * @param constants the constants 50 */ CwRichText(CwConstants constants)51 public CwRichText(CwConstants constants) { 52 super(constants.cwRichTextName(), constants.cwRichTextDescription(), true); 53 } 54 55 /** 56 * Initialize this example. 57 */ 58 @ShowcaseSource 59 @Override onInitialize()60 public Widget onInitialize() { 61 // Create the text area and toolbar 62 RichTextArea area = new RichTextArea(); 63 area.ensureDebugId("cwRichText-area"); 64 area.setSize("100%", "14em"); 65 RichTextToolbar toolbar = new RichTextToolbar(area); 66 toolbar.ensureDebugId("cwRichText-toolbar"); 67 toolbar.setWidth("100%"); 68 69 // Add the components to a panel 70 Grid grid = new Grid(2, 1); 71 grid.setStyleName("cw-RichText"); 72 grid.setWidget(0, 0, toolbar); 73 grid.setWidget(1, 0, area); 74 return grid; 75 } 76 77 @Override asyncOnInitialize(final AsyncCallback<Widget> callback)78 protected void asyncOnInitialize(final AsyncCallback<Widget> callback) { 79 GWT.runAsync(CwRichText.class, new RunAsyncCallback() { 80 81 public void onFailure(Throwable caught) { 82 callback.onFailure(caught); 83 } 84 85 public void onSuccess() { 86 callback.onSuccess(onInitialize()); 87 } 88 }); 89 } 90 } 91