001 /*
002 * Copyright 2012 GWT-Bootstrap
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package com.github.gwtbootstrap.client.ui;
017
018 import com.github.gwtbootstrap.client.ui.base.AlertBase;
019 import com.github.gwtbootstrap.client.ui.constants.AlertType;
020 import com.github.gwtbootstrap.client.ui.constants.Constants;
021
022 /**
023 * Alert block widget with more padding than {@link Alert}. It has a dedicated
024 * heading in an extra row.
025 *
026 * <p>
027 * <h3>UiBinder Usage:</h3>
028 * <code>{@code <b:AlertBlock heading="Warning." type="ERROR">Something went wrong...</AlertBlock>}</code>
029 * </p>
030 * <p>
031 * All parameters are optional and map to the class's setters.
032 * </p>
033 *
034 * @since 2.0.4.0
035 *
036 * @author Dominik Mayer
037 *
038 * @see Alert
039 * @see <a
040 * href="http://twitter.github.com/bootstrap/components.html#alerts">Bootstrap
041 * documentation</a>
042 */
043 public class AlertBlock extends AlertBase {
044
045 private Heading heading = new Heading(4);
046
047 /**
048 * Creates an empty widget with a close icon.
049 */
050 public AlertBlock() {
051 this("");
052 }
053
054 public AlertBlock(String html) {
055 super(html);
056 setUp();
057 }
058
059 private void setUp() {
060 super.addStyleName(Constants.ALERT_BLOCK);
061 heading.setStyleName(Constants.ALERT_HEADING);
062 getHeadingContainer().add(heading);
063 }
064
065 /**
066 * Initializes the widget with an optional close icon.
067 *
068 * @param hasClose
069 * whether the Alert should have a close icon.
070 */
071 public AlertBlock(boolean hasClose) {
072 super("", hasClose);
073 setUp();
074 }
075
076 /**
077 * Creates an Alert with a close icon and the given style.
078 *
079 * @param type
080 * of the Alert
081 */
082 public AlertBlock(AlertType type) {
083 super(type);
084 setUp();
085 }
086
087 /**
088 * {@inheritDoc}
089 */
090 @Override
091 public void setType(AlertType type) {
092 super.setType(type);
093 addStyleName(Constants.ALERT_BLOCK);
094 }
095
096 /**
097 * Sets the text of an optional heading. It is wrapped in {@code <h4>} tags
098 * and placed above the text.
099 */
100 @Override
101 public void setHeading(String text) {
102 heading.setText(text);
103 }
104 }