Example usage for com.google.gwt.user.client.ui HTMLPanel add

List of usage examples for com.google.gwt.user.client.ui HTMLPanel add

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui HTMLPanel add.

Prototype

public void add(Widget widget, String id) 

Source Link

Document

Adds a child widget to the panel, contained within the HTML element specified by a given id.

Usage

From source file:asquare.gwt.tk.demo.client.DropDownPanelPanel.java

License:Apache License

public DropDownPanelPanel() {
    HorizontalPanel outer = new HorizontalPanel();
    outer.setSize("100%", "100%");

    setWidget(outer);//from   w  w  w . ja  va2s.  c  o  m

    BasicPanel left = new BasicPanel();
    DOM.setAttribute(left.getElement(), "id", "dropDown-left");

    DropDownPanel dropDown1 = new DropDownPanel();
    DOM.setAttribute(dropDown1.getElement(), "id", "dropDown-1");
    dropDown1.setHeaderText("Drop Down 1", false);
    Image image = new Image("icecube.jpg");
    image.setSize("100px", "100px");
    dropDown1.add(image);
    dropDown1.setOpen(true);
    left.add(dropDown1);

    DropDownPanel dropDown2 = new DropDownPanel();
    DOM.setAttribute(dropDown2.getElement(), "id", "dropDown-2");
    dropDown2.setHeaderText("Drop Down 2", true);
    image = new Image("icecube.jpg");
    image.setSize("100px", "250px");
    dropDown2.add(image);
    left.add(dropDown2);

    outer.add(left);
    outer.setCellWidth(left, "1px");

    String content = "<H2>Drop Down Panel</H2>"
            + "<p>This widget consists of a hideable content DIV and an optional header DIV.</p>"
            + "<p>The content can be <span id='open'></span>&nbsp;&amp; <span id='close'></span>&nbsp;programatically.</p>"
            + "<p>The headers prevent selection of the text within them. In IE this is done in a special implementation using an <code>onselectstart</code> listener which returns <code>false</code>. In other browsers, <code>DOM.eventPreventDefault(Event)</code> for <code>Event.ONMOUSEDOWN</code> suffices. </p>"
            + "<p>You can add a listener to the DropDownPanel and make layout changes when the it opens/closes (e.g. maximize its parent element when it opens). </p>"
            + "<p>The tip-down arrows on the left are background images applied through CSS rules. <em>Note: we cannot put a border around the header itself because in IE the background image would be obscured by the border.</em></p>"
            + "<h4>Known problems</h4>"
            + "<ul><li>In IE, the cursor reverts to the system arrow after opening the headers on the left. This is a result of changing the tipdown arrow background image. (Alternative: insert the image with <code>DropDownPanel.setHeaderText()</code> and then change it via a DropDownListener.)</li></ul>"
            + "<p>Tested in IE 6 (Win), Firefox 1.5 (Win), Opera 8 (win) and Safari 2.0.4 (Mac) in Strict and Quirks modes.</p>";
    DropDownPanel dropDown3 = new DropDownPanel();
    DOM.setAttribute(dropDown3.getElement(), "id", "dropDown-3");
    dropDown3.setHeaderText("Drop&nbsp;Down&nbsp;3", true);
    HTMLPanel center = new HTMLPanel(content);
    SimpleHyperLink close = new SimpleHyperLink("hidden");
    SimpleHyperLink open = new SimpleHyperLink("shown");
    center.add(close, "close");
    center.add(open, "open");
    dropDown3.add(center);
    dropDown3.setOpen(true);
    outer.add(dropDown3);

    final DropDownPanel dropDown4 = new DropDownPanel();
    DOM.setAttribute(dropDown4.getElement(), "id", "dropDown-4");
    image = new Image("icecube.jpg");
    image.setSize("200px", "250px");
    dropDown4.add(image);
    outer.add(dropDown4);
    outer.setCellWidth(dropDown4, "1px");

    open.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dropDown4.setOpen(true);
        }
    });
    close.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dropDown4.setOpen(false);
        }
    });
}

From source file:asquare.gwt.tkdemo.client.demos.DialogPanel.java

License:Apache License

private Widget createDoc() {
    String content = "<H2>ModalDialog</H2>" + "<h4>Features</h4>" + "<ul>"
            + "<li>automatic centering in browser's main viewport</li>"
            + "<li>light box effect (using <span id='glassPanelRef'></span>)</li>"
            + "<li>caption allows child widgets</li>" + "<li>caption prevents text selection</li>"
            + "<li>focus management and containment (internal tab cycle)</li>"
            + "<li>can focus a widget upon dismissal</li>"
            + "<li>minimim size enforcement for content panel (optional, default is 200 x 75 px)</li>" + "</ul>"
            + "<H2>AlertDialog</H2>" + "<h4>Features</h4>" + "<ul>"
            + "<li>icon in the caption indicates severity</li>"
            + "<li>default button is automatically focused</li>" + "<li>cancel button is mapped to Esc key</li>"
            + "<li>button hot keys + Esc + Enter</li>" + "<li>focus cycle traversable with arrow keys</li>"
            + "</ul>";
    HTMLPanel description = new HTMLPanel(content);
    Hyperlink glassPanelLink = new Hyperlink("GlassPanel", false, GlassPanelDemo.NAME);
    DomUtil.setStyleAttribute(glassPanelLink, "display", "inline");
    description.add(glassPanelLink, "glassPanelRef");
    description.setStyleName("description division");
    return description;
}

From source file:asquare.gwt.tkdemo.client.demos.DropDownPanelPanel.java

License:Apache License

public DropDownPanelPanel() {
    HorizontalPanel outer = new HorizontalPanel();
    outer.setSize("100%", "100%");

    initWidget(outer);/*from w ww . j  ava2  s  .  com*/

    BasicPanel left = new BasicPanel();
    left.addStyleName("division");
    DomUtil.setAttribute(left, "id", "dropDown-left");

    DropDownPanel dropDown1 = new DropDownPanel();
    DomUtil.setAttribute(dropDown1, "id", "dropDown-1");
    dropDown1.setHeaderText("Drop Down 1", false);
    HTML dd1Content = new HTML("This DropDownPanel uses CSS to change the header image.");
    dropDown1.add(dd1Content);
    dropDown1.setOpen(true);
    left.add(dropDown1);

    final DropDownPanel dropDown2 = new DropDownPanel();
    DomUtil.setAttribute(dropDown2, "id", "dropDown-2");
    final String closedHeader = "<img src='triangle.gif'/>&nbsp;Drop Down 2";
    final String openHeader = "<img src='opentriangle.gif'/>&nbsp;Drop Down 2";
    dropDown2.setHeaderText(closedHeader, true);
    dropDown2.addDropDownListener(new DropDownListener() {
        public void dropDownClosed(DropDownPanel sender) {
            dropDown2.setHeaderText(closedHeader, true);
        }

        public void dropDownOpened(DropDownPanel sender) {
            dropDown2.setHeaderText(openHeader, true);
        }
    });
    HTML dd2Content = new HTML("This DropDownPanel uses a listener to change the header image.");
    dropDown2.add(dd2Content);
    dropDown2.setOpen(true);
    left.add(dropDown2);

    outer.add(left);
    outer.setCellWidth(left, "1px");

    String content = "<H2>DropDownPanel</H2>"
            + "<p>This widget consists of a hideable content DIV and an optional header DIV.</p>"
            + "<p>The content can be <span id='open'></span>&nbsp;&amp; <span id='close'></span>&nbsp;programatically.</p>"
            + "<p>The headers prevent selection of the text within them. In IE this is done in a special implementation using an <code>onselectstart</code> listener which returns <code>false</code>. In other browsers, <code>DOM.eventPreventDefault(Event)</code> for <code>Event.ONMOUSEDOWN</code> suffices. </p>"
            + "<p>You can add a listener to the DropDownPanel and make layout changes when the it opens/closes (e.g. maximize its parent element when it opens). </p>"
            + "<p><em>Note: we cannot put a border around the Drop Down 1 header because in IE the background image would be obscured by the border.</em></p>";
    DropDownPanel dropDown3 = new DropDownPanel();
    dropDown3.addStyleName("division");
    DomUtil.setAttribute(dropDown3, "id", "dropDown-3");
    dropDown3.setHeaderText("Drop&nbsp;Down&nbsp;3", true);
    HTMLPanel center = new HTMLPanel(content);
    center.addStyleName("description");
    SimpleHyperLink close = new SimpleHyperLink("hidden");
    SimpleHyperLink open = new SimpleHyperLink("shown");
    center.add(close, "close");
    center.add(open, "open");
    dropDown3.add(center);
    dropDown3.setOpen(true);
    outer.add(dropDown3);

    final DropDownPanel dropDown4 = new DropDownPanel();
    dropDown4.addStyleName("division");
    DomUtil.setAttribute(dropDown4, "id", "dropDown-4");
    Image image = new Image("icecube.jpg");
    image.setSize("200px", "250px");
    dropDown4.add(image);
    outer.add(dropDown4);
    outer.setCellWidth(dropDown4, "1px");

    open.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            dropDown4.setOpen(true);
        }
    });
    close.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            dropDown4.setOpen(false);
        }
    });
}

From source file:com.cgxlib.xq.client.plugins.widgets.WidgetsUtils.java

License:Apache License

/**
 * Attach a widget to the GWT widget list. Normally used when XQ
 * creates widgets wrapping existing dom elements.
 * It does nothing if the widget is already attached to another widget.
 *
 * @param widget            to attach/*from  ww  w.  ja  v  a 2s.  c o  m*/
 * @param firstParentWidget the parent widget,
 *                          If it is null and it is not inside any other widget, we just add
 *                          the widget to the gwt detach list
 */
public static void attachWidget(Widget widget, Widget firstParentWidget) {
    if (widget != null && widget.getParent() == null) {
        if (firstParentWidget == null) {
            firstParentWidget = getFirstParentWidget(widget);
            if (firstParentWidget == null) {
                RootPanel.detachOnWindowClose(widget);
                widgetOnAttach(widget);
            } else {
                attachWidget(widget, firstParentWidget);
            }
        } else if (firstParentWidget instanceof HTMLPanel) {
            HTMLPanel h = (HTMLPanel) firstParentWidget;
            Element p = widget.getElement().getParentElement();
            if (p != null) {
                h.add(widget, p);
            } else {
                h.add(widget);
            }
        } else if (firstParentWidget instanceof HasOneWidget) {
            ((HasOneWidget) firstParentWidget).setWidget(widget);
        } else if (firstParentWidget instanceof HasWidgets) {
            try {
                ((HasWidgets) firstParentWidget).add(widget);
            } catch (UnsupportedOperationException e) {
                // Some widgets like 'table' has no implementation of 'add(widget)'
                widgetSetParent(widget, firstParentWidget);
            }
        } else {
            widgetSetParent(widget, firstParentWidget);
        }
    }
}

From source file:com.dominichenko.pet.gwt.phys2d.client.utils.Shutter.java

License:Apache License

/**
 * Private constructor prevents creating additional instances of shutter.
 *//*from  w w  w .  j  av a 2 s .c  o m*/
private Shutter() {
    panel = new PopupPanel();
    panel.setAnimationEnabled(true);
    panel.setGlassEnabled(true);
    panel.setModal(true);
    panel.setStylePrimaryName("shutter");
    SafeHtml loading = new ImageLoadingCell.DefaultRenderers().getLoadingRenderer().render(null);
    HTMLPanel hp = new HTMLPanel(
            "<div id='shutter_img'>" + loading.asString() + "</div>" + "<div id='shutter_label'></div>");
    hp.setSize("100%", "100%");
    label = new Label(DEF_LABEL);
    hp.add(label, "shutter_label");
    panel.add(hp);
}

From source file:com.edgenius.wiki.gwt.client.BaseEntryPoint.java

License:Open Source License

private void initSearch() {
    if (isOffline()) {
        return;/*from w ww.j av a  2 s.  c om*/
    }

    String id1 = HTMLPanel.createUniqueId();
    HTMLPanel panel = new HTMLPanel("<span id='" + id1 + "'></span>");
    searchBox.addFocusHandler(KeyCaptureListener.instance());
    searchBox.addBlurHandler(KeyCaptureListener.instance());
    searchBox.setStyleName(Css.SEARCH_INPUT);
    searchBox.addKeyDownHandler(new KeyDownHandler() {
        public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                doSearch(searchBox.getText());
            }
        }

    });

    panel.add(searchBox, id1);

    RootPanel.get("search").add(panel);

}

From source file:com.edgenius.wiki.gwt.client.home.porlet.MessagePortlet.java

License:Open Source License

/**
 * A common callback success, as this portlet can accept response from Portlet invoke 
 * or from a message send refresh callback.
 *///from www. j a v a2 s . c om
private void callback(GeneralModel model, MessageListModel msgs) {
    busy(false);
    messagePanel.clear();
    if (!GwtClientUtils.preSuccessCheck(model, null)) {
        //show error message on item part rather than general error message on HTML page above
        messagePanel.add(ErrorCode.getMessage(model.errorCode, model.errorMsg));
        return;
    }

    if (msgs.list.size() == 0) {
        none.setStyleName(Css.PORTLET_WEAK_TEXT);
        messagePanel.add(none);
        return;
    }

    for (Iterator<MessageModel> iter = msgs.list.iterator(); iter.hasNext();) {
        final MessageModel msg = iter.next();
        String puid = HTMLPanel.createUniqueId();
        String puid1 = HTMLPanel.createUniqueId();
        String puid2 = HTMLPanel.createUniqueId();
        String puid3 = HTMLPanel.createUniqueId();
        HTMLPanel msgPanel = new HTMLPanel("<div style=\"display:inline;font-weight:bold;\" id=\"" + puid1
                + "\"></div>" + "<div style=\"display:inline\" id=\"" + puid2
                + "\"></div> <div class=\"weaktext\">" + Msg.consts.by() + "</div><div class=\"weaklink\" id=\""
                + puid + "\"></div><div class=\"weaktext\">" + Msg.consts.on() + " "
                + GwtClientUtils.toDisplayDate(msg.date) + "</div>" + "<div style=\"display:inline\" id=\""
                + puid3 + "\"></div>");

        if ((msg.targetType == SharedConstants.MSG_TARGET_USER
                //TODO: how to distinguish the contributor and admin?
                || msg.targetType == SharedConstants.MSG_TARGET_SPACE_CONTRIBUTE_USERS
                || msg.targetType == SharedConstants.MSG_TARGET_SPACE_ADMIN_ONLY)
                && !StringUtil.isBlank(msg.target)) {
            msgPanel.add(new Label(
                    (msg.targetType == SharedConstants.MSG_TARGET_USER ? "@" : "@@") + msg.target + " "),
                    puid1);
        }
        if (msg.targetType == SharedConstants.MSG_TARGET_INSTANCE_ADMIN_ONLY
                && StringUtil.isBlank(msg.target)) {
            //message to system admin
            Image msgAdmin = new Image(IconBundle.I.get().error());
            msgAdmin.setTitle(Msg.consts.msg_to_admin());
            msgPanel.add(msgAdmin, puid1);
        }

        //don't use UserProfileLink - click user link will invoke reply message, rather than jump to user profile
        //UserProfileLink authorPop = new UserProfileLink(msg.author, null,msg.author,msg.authorPortrait);
        ClickLink authorPop = new ClickLink(msg.authorUsername);
        //auto popup for user profile
        new UserPopup(authorPop, null, msg.authorUsername, msg.authorPortrait);
        authorPop.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent evt) {
                if (msg.authorUid != -1) {
                    postPanel.fillTarget(SharedConstants.MSG_TARGET_USER, msg.authorUsername);
                } else {
                    //reply anonymous means to all 
                    postPanel.fillTarget(null, null);
                }
                postPanel.focusToEnd(true);
            }
        });

        msgPanel.add(new Label(msg.text), puid2);
        msgPanel.add(authorPop, puid);
        if (msg.removable) {
            Image bin = new Image(IconBundle.I.get().bin_close());
            bin.setTitle(Msg.consts.delete());
            bin.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    if (Window.confirm(Msg.consts.confirm_delete_message())) {
                        NotificationControllerAsync notifyController = ControllerFactory
                                .getNotificationController();
                        notifyController.deleteMessage(currentPage, msg.uid, new NotificationCallback());
                    }
                }
            });
            msgPanel.add(bin, puid3);
        }

        DOM.setStyleAttribute(msgPanel.getElement(), "display", "inline");

        HorizontalPanel itemPanel = new HorizontalPanel();
        Widget portrait = GwtClientUtils.createUserSmallPortrait(msg.authorPortrait,
                SharedConstants.PORTRAIT_SIZE_SMALL);
        itemPanel.add(portrait);
        itemPanel.setCellWidth(portrait, "50px");
        itemPanel.add(msgPanel);
        messagePanel.add(itemPanel);
    }

    clearControl();

    controlBar.setPaginationInfo(msgs.hasPre, msgs.hasNxt, msgs.currentPage);
    addControl(controlBar);
}

From source file:com.edgenius.wiki.gwt.client.page.DiffPanel.java

License:Open Source License

private void diffMessage(final DiffListModel model) {

    diffMessage.cleanMessage();/*from   w w  w  .  ja va2s  .  com*/

    String id1 = HTMLPanel.createUniqueId();
    //head
    StringBuffer buf = new StringBuffer("<div class='historyAction diff'><div class='msg' id='").append(id1)
            .append("'></div>");
    buf.append("<div class='action'>");

    buf.append(
            "<div class='indicator diff-text'><div class='diff-insertion'>Added</div> <div class='diff-deletion'>Deleted</div></div>");
    //diff 1
    String idp1 = null, idp2 = null, idp3 = null, idn1 = null, idn2 = null, idn3 = null;
    idn1 = HTMLPanel.createUniqueId();
    idn2 = HTMLPanel.createUniqueId();
    idn3 = HTMLPanel.createUniqueId();
    buf.append("<div class='round next'><div class='version' id='").append(idn1)
            .append("'></div><div class='author' id='").append(idn2).append("'></div><div class='date' id='")
            .append(idn3).append("'></div></div>");
    //diff 2
    idp1 = HTMLPanel.createUniqueId();
    idp2 = HTMLPanel.createUniqueId();
    idp3 = HTMLPanel.createUniqueId();

    buf.append("<div class='current'>vs</div>");

    buf.append("<div class='round prev'><div class='version' id='").append(idp1)
            .append("'></div><div class='author' id='").append(idp2).append("'></div><div class='date' id='")
            .append(idp3).append("'></div></div>");

    //end
    buf.append("</div></div>");

    //put this message into 
    HTMLPanel msgPanel = new HTMLPanel(buf.toString());
    msgPanel.add(new Label(Msg.consts.comparing_view()), id1);

    diffActionMsg(msgPanel, model.prevHistoryItem, idn1, idn2, idn3);
    diffActionMsg(msgPanel, model.nextHistoryItem, idp1, idp2, idp3);

    HorizontalPanel panel = new HorizontalPanel();
    panel.add(msgPanel);

    diffMessage.warning(panel, false);
}

From source file:com.edgenius.wiki.gwt.client.page.DiffPanel.java

License:Open Source License

private void diffActionMsg(HTMLPanel msgPanel, final PageItemModel history, String idp1, String idp2,
        String idp3) {/*  ww w.jav a  2 s  . com*/

    String spaceUname = PageMain.getSpaceUname();

    Hyperlink preLink;
    if (history.version == SharedConstants.CURRENT) {
        //latest page
        preLink = new Hyperlink(Msg.consts.latest(), GwtUtils.getSpacePageToken(spaceUname, history.title));
    } else {
        preLink = new Hyperlink(Msg.consts.revision() + " " + history.version,
                GwtUtils.buildToken(PageMain.TOKEN_HISTORY, spaceUname, String.valueOf(history.uid)));
    }

    UserProfileLink modifier = new UserProfileLink(history.modifier, spaceUname, history.modifierUsername,
            history.modifierPortrait);
    Label modifiedDate = new Label(GwtClientUtils.toDisplayDate(history.modifiedDate));

    msgPanel.add(preLink, idp1);
    msgPanel.add(modifier, idp2);
    msgPanel.add(modifiedDate, idp3);
}

From source file:com.edgenius.wiki.gwt.client.page.EditPanel.java

License:Open Source License

public EditPanel(final PageMain main) {
    super(main);/*from w ww  .j av  a 2s .  co m*/

    main.addPanelSwitchListener(this);

    contentArea = new Editor(main, false);
    main.editorRegistry.register(contentArea);

    titleBox.setTabIndex(1);
    if (!AbstractEntryPoint.isOffline()) {
        tagBox.setTabIndex(2);
    }
    contentArea.setTabIndex(3);
    tagBox.setHint(Msg.consts.tags() + "...");

    titleBox.addBlurHandler(new BlurHandler() {
        public void onBlur(BlurEvent event) {
            //display the final saved title
            titleBox.setText(StringUtil.shrinkSpaces(titleBox.getText()));

            validSave();
        }
    });

    if (!AbstractEntryPoint.isOffline()) {
        templatePanel = new TemplatesPanel(main, this);
        templatePanel.setVisible(false);
        templateBtn.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                //toggle template panel
                templatePanel.toggle();
            }
        });
    }

    //       Label titleLabel = new Label(Msg.consts.title());

    //attachment
    attPanel = new AttachmentPanel(main, false);
    attachmentBtn = new AttachmentButton(attPanel);
    contentArea.bindAttachmentPanel(attPanel);

    //must put below above 2 sentences: attPanel is created 
    main.registerAttachmentPanel(attPanel);

    //tag, att, location, notification 
    //       Label tagLabel = new Label(Msg.consts.tags());
    noticeCheckbox.setValue(true);

    //content
    ContentChangeListener changeListener = new ContentChangeListener();
    contentArea.addKeyPressHandler(changeListener);
    contentArea.addChangeHandler(changeListener);

    //hide first, show when fillPanel() according to PageAttribute.NO_ATTACHMENT
    attachmentBtn.setVisible(false);
    //hide attachment initial
    attPanel.setVisible(false);

    titleBox.setStyleName(Css.TITLE_BOX);

    draftStatusBar.setStyleName(Css.DRAFT_STATUS_MSG);

    //main content panel, contains contentPanel, diffContent and SideBar panel.
    FlexTable mainPanel = new FlexTable();
    mainPanel.setCellPadding(0);
    mainPanel.setCellSpacing(0);
    mainPanel.setWidget(0, 0, contentArea);
    mainPanel.setWidget(0, 1, diffContent);

    mainPanel.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT,
            HasVerticalAlignment.ALIGN_TOP);
    mainPanel.getCellFormatter().setAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT,
            HasVerticalAlignment.ALIGN_TOP);
    mainPanel.setWidth("100%");

    diffMessage.setVisible(false);
    //build panel
    HTMLPanel hpanel = new HTMLPanel(readEditLayout());
    hpanel.add(message, "_message");
    hpanel.add(diffMessage, "_diff_message");
    hpanel.add(titleBox, "_title");
    hpanel.add(draftStatusBar, "_draft_message");
    if (!AbstractEntryPoint.isOffline()) {
        hpanel.add(tagBox, "_tags");
        hpanel.add(noticeCheckbox, "_notification");
    }
    hpanel.add(functionBtnBar, "_actions");
    hpanel.add(attachmentBtn, "_attchments");
    hpanel.add(attPanel, "_attchments_panel");
    if (!AbstractEntryPoint.isOffline()) {
        templateBtn.setStyleName(Css.ATT_BTN);
        hpanel.add(templateBtn, "_templates");
        hpanel.add(templatePanel, "_templates_panel");
    }
    hpanel.add(mainPanel, "_body");

    this.setWidget(hpanel);
}