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

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

Introduction

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

Prototype

public static String createUniqueId() 

Source Link

Document

A helper method for creating unique IDs for elements within dynamically- generated HTML.

Usage

From source file:com.edgenius.wiki.gwt.client.login.LoginForm.java

License:Open Source License

public LoginForm(DialogBox dialog, Button sender, String redirUrl, final boolean offline) {
    this.offline = offline;
    this.dialog = dialog;
    this.sender = sender;

    if (offline) {
        this.initWidget(offlineBinder.createAndBindUi(this));
    } else {// w w w .  j  a va 2 s  . c o m
        this.initWidget(onlineBinder.createAndBindUi(this));
    }

    final String containerID = HTMLPanel.createUniqueId();
    DOM.setElementAttribute(form.getElement(), "id", containerID);

    form.addSubmitHandler(this);
    form.addSubmitCompleteHandler(this);

    form.setAction(GwtClientUtils.getBaseUrl() + "j_spring_security_check");
    form.setMethod(FormPanel.METHOD_POST);

    KeyDownHandler enterSubmit = GwtClientUtils.createEnterSubmitListener(form);

    username.addKeyDownHandler(enterSubmit);
    username.addKeyPressHandler(cleanMessageListener);

    password.addKeyDownHandler(enterSubmit);
    password.addKeyPressHandler(cleanMessageListener);

    remeberme.addKeyDownHandler(enterSubmit);

    //first disable,only this user failed login several times later in given period, captcha will show up
    captcha.disable();
    captcha.getCaptchaInputWidget().addKeyPressHandler(cleanMessageListener);
    captcha.getCaptchaInputWidget().addKeyDownHandler(enterSubmit);

    //hardcode for server side parameter name
    redir.setValue(redirUrl);
    focus();

}

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

License:Open Source License

private void diffMessage(final DiffListModel model) {

    diffMessage.cleanMessage();//from ww  w  .ja v  a 2  s .c o  m

    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.ViewPanel.java

License:Open Source License

private void historyDiffMessage(final PageModel model) {
    String spaceUname = model.spaceUname;
    String currentTitle = model.currentTitle;

    message.cleanMessage();//from w  w  w. ja va 2  s  . c  om

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

    String idp1 = null, idp2 = null, idp3 = null, idp4 = null, idn1 = null, idn2 = null, idn3 = null,
            idn4 = null;
    if (model.nextHistoryItem != null) {
        idn1 = HTMLPanel.createUniqueId();
        idn2 = HTMLPanel.createUniqueId();
        idn3 = HTMLPanel.createUniqueId();
        idn4 = 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 class='diff' id='")
                .append(idn4).append("'></div></div>");

    }
    buf.append("<div class='current'>").append(Msg.consts.revision()).append(" ").append(model.pageVersion)
            .append("</div>");
    if (model.prevHistoryItem != null) {
        idp1 = HTMLPanel.createUniqueId();
        idp2 = HTMLPanel.createUniqueId();
        idp3 = HTMLPanel.createUniqueId();
        idp4 = HTMLPanel.createUniqueId();

        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 class='diff' id='")
                .append(idp4).append("'></div></div>");
    }
    buf.append("</div></div>");
    HTMLPanel msgPanel = new HTMLPanel(buf.toString());
    Hyperlink retCurrentVerBtn = new Hyperlink(Msg.consts.return_latest_version(),
            GwtUtils.getSpacePageToken(spaceUname, currentTitle));
    msgPanel.add(new Label(Msg.consts.view_history()), id1);
    msgPanel.add(retCurrentVerBtn, id2);

    if (model.prevHistoryItem != null) {
        historyNextPrevMsg(msgPanel, model.prevHistoryItem, model.uid, idp1, idp2, idp3, idp4);
    }
    if (model.nextHistoryItem != null) {
        historyNextPrevMsg(msgPanel, model.nextHistoryItem, model.uid, idn1, idn2, idn3, idn4);
    }

    HorizontalPanel panel = new HorizontalPanel();
    panel.add(msgPanel);
    message.warning(panel, false);
}

From source file:com.edgenius.wiki.gwt.client.render.PageRender.java

License:Open Source License

/**
 * @param spaceUname // ww w.  ja  v  a2s .  co  m
 * @param panel
 * @param model
 * @param pieces: could be pageContent, or side bar content 
 * @param isPreivew: if this render is for preview window
 */
public void renderContent(final String spaceUname, PageModel page, List<RenderPiece> pieces,
        boolean isPreivew) {
    //most stuff only need renderPiece, except PageAuthorPanel at moment
    widgetRenderContent = new StringBuffer();
    widgetCounter.clear();
    widgetContainer.clear();

    panel.clear();

    if (pieces != null) {
        int size = pieces.size();
        for (int idx = 0; idx < size; idx++) {
            Object piece = pieces.get(idx);
            if (piece instanceof LinkModel) {
                LinkModel ln = (LinkModel) piece;
                if (listeners != null) {
                    fireRenderEvent(ln.getView());
                }
                final String anchorTxt = StringUtil.isBlank(ln.getAnchor()) ? ""
                        : (EscapeUtil.escapeToken(ln.getAnchor().trim()));
                if (anchorTxt.length() != 0 && StringUtil.isBlank(ln.getLink())) {
                    //[view>#anchor] style: will only redirect to anchor in same page
                    ClickLink link = new ClickLink(ln.getView(), true);
                    link.addClickHandler(new ClickHandler() {
                        public void onClick(ClickEvent event) {
                            GwtClientUtils.gotoAnchor(anchorTxt);
                        }
                    });
                    panel.add(link);
                } else if (ln.getType() == LinkModel.LINK_TO_CLIENT_CLICK_LINK) {
                    final String[] token = LinkUtil.parseCLinkParamters(ln.getLink());
                    if (token != null && token.length > 0) {
                        //If it has anchor field, it will be treated as hyper link.Otherwise, ClickLink
                        if (!StringUtil.isEmpty(ln.getAnchor())) {
                            //now it only support user popup - so need to consolidate if want to more functions 
                            EventfulHyperLink link = new EventfulHyperLink(ln.getView(), ln.getAnchor());
                            String method = token[0];
                            String[] params = null;
                            if (token.length > 1) {
                                params = new String[token.length - 1];
                                for (int idx1 = 1; idx1 < token.length; idx1++) {
                                    params[idx1 - 1] = token[idx1];
                                }
                            }
                            JavascriptExposer.run(method, params, link);
                            panel.add(link);
                        } else {
                            //click link
                            ClickLink link = new ClickLink(ln.getView(), true);
                            link.addClickHandler(new ClickHandler() {
                                public void onClick(ClickEvent event) {
                                    String method = token[0];
                                    String[] params = null;
                                    if (token.length > 1) {
                                        params = new String[token.length - 1];
                                        for (int idx = 1; idx < token.length; idx++) {
                                            params[idx - 1] = token[idx];
                                        }
                                    }
                                    JavascriptExposer.run(method, params, (Widget) event.getSource());
                                }
                            });
                            panel.add(link);
                        }
                    } else {
                        panel.add(new HTML(ln.getView()));
                        Log.error("Unable pasre link with type 'client click link':" + ln.getLink());
                    }
                } else if (ln.getType() == LinkModel.LINK_TO_SERVER_CLICK_LINK) {

                } else {
                    if (isPreivew) {
                        ClickLink link = new ClickLink(ln.getView(), true);
                        link.addClickHandler(new ClickHandler() {
                            public void onClick(ClickEvent event) {
                                Window.alert(Msg.consts.preview_disable_link());
                            }
                        });
                        panel.add(link);
                    } else {
                        String tokenName = ln.getLink();

                        String linkSpaceUname = ln.getSpaceUname();
                        //extspace or current space,  if null(failure tolerance) use current spaceUname as value
                        linkSpaceUname = (linkSpaceUname == null || linkSpaceUname.trim().length() == 0)
                                ? spaceUname
                                : linkSpaceUname;
                        if (ln.getType() == LinkModel.LINK_TO_CREATE_FLAG) {
                            //$CREATE ,for link to non-exist page, or for "PAGE_NOT_FOUND" case
                            tokenName = GwtUtils.buildToken(PageMain.TOKEN_CREATE, linkSpaceUname, tokenName);
                        } else if (ln.getType() == LinkModel.LINK_TO_CREATE_HOME_FLAG) {
                            tokenName = GwtUtils.buildToken(PageMain.TOKEN_CREATE_HOME, linkSpaceUname,
                                    tokenName);
                        } else if (ln.getType() == LinkModel.LINK_TO_OPEN_NEW_WIN) {
                            //no use so far
                            tokenName = GwtUtils.buildToken(PageMain.TOKEN_OPEN_NEW_WINDOW, linkSpaceUname,
                                    tokenName);
                        } else if (ln.getType() == LinkModel.LINK_TO_HYPER_TOKEN) {
                            //keep token unchanged - nothing to do here.
                        } else
                            tokenName = GwtUtils.getSpacePageToken(linkSpaceUname, tokenName);

                        tokenName += (anchorTxt == "" ? "" : "#" + anchorTxt);
                        Hyperlink link = new Hyperlink(ln.getView(), true, tokenName);
                        panel.add(link);
                    }
                }
            } else if (piece instanceof MacroModel) {
                MacroModel rs = (MacroModel) piece;
                if (rs != null) {

                    if (rs.macroName.equalsIgnoreCase(SharedConstants.MACRO_SPACE_ADMIN)) {
                        SpaceAdminRenderWidget adminPanel = new SpaceAdminRenderWidget(spaceUname);
                        panel.add(adminPanel);
                        widgetContainer.add(adminPanel);
                        adminPanel.onLoad(HTMLPanel.createUniqueId(), currentUser, this);

                    } else if (rs.macroName.equalsIgnoreCase(SharedConstants.MACRO_NOTIFY_SYSADMIN)) {
                        SendingNotifyRenderWidget adminPanel = new SendingNotifyRenderWidget();
                        panel.add(adminPanel);
                        widgetContainer.add(adminPanel);
                        adminPanel.onLoad(HTMLPanel.createUniqueId(), currentUser, this);
                    } else if (rs.macroName.equals(SharedConstants.MACRO_TAG_CLOUD)) {
                        TagCloudRenderWidget macroPanel = new TagCloudRenderWidget(spaceUname);
                        panel.add(macroPanel);
                        widgetContainer.add(macroPanel);
                        macroPanel.onLoad(HTMLPanel.createUniqueId(), currentUser, this);
                    } else if (rs.macroName.equals(SharedConstants.MACRO_TEMPLATE_LIST)) {
                        TemplateListRenderWidget macroPanel = new TemplateListRenderWidget(spaceUname);
                        panel.add(macroPanel);
                        widgetContainer.add(macroPanel);
                        macroPanel.onLoad(HTMLPanel.createUniqueId(), currentUser, this);
                    } else if (rs.macroName.equals(SharedConstants.MACRO_SEARCH)) {
                        String keyword = (String) rs.values.get(NameConstants.KEYWORD);
                        SearchRenderWidget macroPanel = new SearchRenderWidget(keyword);
                        panel.add(macroPanel);
                        widgetContainer.add(macroPanel);
                        macroPanel.onLoad(HTMLPanel.createUniqueId(), currentUser, this);
                    } else if (rs.macroName.equals(SharedConstants.MACRO_USER_PROFILE)) {
                        String username = rs.values.get(NameConstants.USERNAME);
                        UserProfileRenderWidget macroPanel = new UserProfileRenderWidget(username);
                        panel.add(macroPanel);
                        widgetContainer.add(macroPanel);
                        macroPanel.onLoad(HTMLPanel.createUniqueId(), currentUser, this);

                    } else if (rs.macroName.equals(SharedConstants.MACRO_INCLUDE)) {
                        String src = rs.values.get(NameConstants.SRC);

                        LinkModel link = LinkUtil.parseMarkup(src);
                        if (StringUtil.isBlank(link.getSpaceUname())) {
                            //if @space is blank, treat as current space 
                            link.setSpaceUname(spaceUname);
                        }
                        IncludeRenderWidget includePanel = new IncludeRenderWidget(link);
                        panel.add(includePanel);
                        widgetContainer.add(includePanel);
                        includePanel.onLoad(HTMLPanel.createUniqueId(), currentUser, this);

                    } else if (rs.macroName.equals(SharedConstants.MACRO_COMMENT)) {
                        String title = (String) rs.values.get(NameConstants.TITLE);
                        ClickLink comment = new ClickLink(title);
                        comment.addClickHandler(new ClickHandler() {
                            public void onClick(ClickEvent event) {
                                if (BaseEntryPoint.I != null && BaseEntryPoint.I instanceof PageMain) {
                                    PageMain main = ((PageMain) BaseEntryPoint.I);
                                    if (main.getVisiblePanelIndex() == PageMain.VIEW_PANEL) {
                                        main.viewPanel.tabPanel.newComment();
                                        return;
                                    }
                                }
                                Window.alert(Msg.consts.not_available_mode());
                            }
                        });
                        widgetRenderContent.append(title);
                        panel.add(comment);
                    } else if (rs.macroName.equals(SharedConstants.MACRO_PORTAL)) {
                        boolean show = BooleanUtil.toBooleanTrue(rs.values.get(NameConstants.SHOWLOGO));
                        int column = NumberUtil.toInt(rs.values.get(NameConstants.COLUMNS), -1);
                        if (column == -1) {
                            //this is just for makes this macro can tolerance spell error - colunm or columns
                            column = NumberUtil.toInt(rs.values.get(NameConstants.COLUMN), -1);
                        }
                        if (column == -1) {
                            column = SharedConstants.DEFAULT_PORTAL_COLUMNS;
                        }
                        if (visitor == null) {
                            //default portal visitor - don't use InstancePortalVisitor as it is dangerous to change default dashboard
                            visitor = new HomePortalVisitor();
                        }
                        Portal portal = new Portal(visitor, column, show);
                        panel.add(portal);
                        widgetContainer.add(portal);
                        portal.onLoad(HTMLPanel.createUniqueId(), currentUser, this);
                    } else if (rs.macroName.equals(SharedConstants.MACRO_FEEDBACK)) {
                        String imgOn = rs.values.get(NameConstants.IMAGE);
                        HasClickHandlers btn;
                        if (StringUtil.isBlank(imgOn)) {
                            //text base link
                            String title = (String) rs.values.get(NameConstants.TITLE);
                            btn = new ClickLink(title);
                        } else {
                            btn = new Image(imgOn);
                        }
                        btn.addClickHandler(new ClickHandler() {
                            public void onClick(ClickEvent event) {
                                FeedbackDialog dialog = new FeedbackDialog();
                                dialog.showbox();
                            }
                        });

                        //for hide welcome message
                        widgetRenderContent.append("feedback");//NON-I18N
                        panel.add((Widget) btn);
                    } else if (rs.macroName.equals(SharedConstants.MACRO_SIGNUP)) {
                        String imgOn = rs.values.get(NameConstants.IMAGE);
                        HasClickHandlers btn;
                        if (StringUtil.isBlank(imgOn)) {
                            //text base link
                            String title = (String) rs.values.get(NameConstants.TITLE);
                            btn = new ClickLink(title);
                        } else {
                            btn = new Image(imgOn);
                        }
                        btn.addClickHandler(new ClickHandler() {
                            public void onClick(ClickEvent event) {
                                LoginDialog dialogue = new LoginDialog(LoginDialog.SINGUP);
                                dialogue.showbox();
                            }
                        });

                        //for hide welcome message
                        widgetRenderContent.append("signup");//NON-I18N
                        panel.add((Widget) btn);
                    }
                }
            } else if (piece instanceof TextModel) {
                String text = ((TextModel) piece).toString();
                panel.add(text);
                if (listeners != null) {
                    fireRenderEvent(text);
                }
            }
        }
    }

    panel.submit();

    if (listeners != null) {
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
            public void execute() {
                attemptFireRenderEnd();
            }

        });
    }
}

From source file:com.edgenius.wiki.gwt.client.render.RenderPanel.java

License:Open Source License

/**
 * All RenderPanel instance must have an unique id value. This is useful for renderCallback(id) to 
 * look up the specified RenderPanel scripts and eval them.
 * @param id//from  www  .  j a va2  s .c o m
 */
public RenderPanel() {
    panelID = HTMLPanel.createUniqueId();
    DOM.setElementAttribute(this.getElement(), "id", panelID);
}

From source file:com.edgenius.wiki.gwt.client.render.RenderPanel.java

License:Open Source License

/**
 * I don't remember exactly as old bug database is hacked and removed. The reason why use this method to 
 * add render content is because HTML DOM Hierarchy model. If simply use FlowPanel.add(), it may break DOM hierarchy in 
 * some case./*from   w w w .j  av  a  2 s.  c o m*/
 * Submit the latest content, must be call after any modify content method, such as remove(), add(), insert()
 * or iterator.remove() etc.
 */
public void submit() {
    StringBuffer render = new StringBuffer();
    Map<String, Widget> widgetMap = new HashMap<String, Widget>();

    int size = content.size();
    if (size == 0) {
        //IE issue, if content is blank, the right size author info panel will 100% width to occupy entire page
        render.append("&nbsp;");
    } else {
        for (int idx = 0; idx < size; idx++) {
            Object obj = content.get(idx);
            if (obj instanceof String) {
                render.append((String) obj);
            } else if (obj instanceof Widget) {
                String uid = HTMLPanel.createUniqueId();
                widgetMap.put(uid, (Widget) obj);
                //surround with <![CDATA[]]>: This is fix bug when render something like: {html}<!{html}{feedback}
                //Render content "!<<span id=123></span>" in FF and IE will break document.getElementById()
                //This means the HTMLPanel can't work as the span element can not be found out.
                //use <![CDATA[]]> rather than <!----> is because if "<![" is before text, then <!----> won't work.
                //but <![CDATA[]]> work both <! or <![ before the macro widget.
                render.append("<![CDATA[]]><span id='" + uid + "'></span><![CDATA[]]>");
            }
        }
    }

    HTMLPanel panel = new HTMLPanel(render.toString());

    for (Entry<String, Widget> entry : widgetMap.entrySet()) {
        panel.add(entry.getValue(), entry.getKey());

    }
    //reset panel to empty, then render new content
    clearPanel();

    super.add(panel);
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        public void execute() {
            renderCallback(panelID);
        }
    });
}

From source file:com.edgenius.wiki.gwt.client.widgets.AutoResizeTextArea.java

License:Open Source License

public AutoResizeTextArea() {
    super();/*from w  w  w.  j av  a  2s  .c  om*/
    id = HTMLPanel.createUniqueId();
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        public void execute() {
            DOM.setElementAttribute(AutoResizeTextArea.this.getElement(), "id", id);
            initAutoResize(id);
        }
    });
    this.addFocusHandler(KeyCaptureListener.instance());
    this.addBlurHandler(KeyCaptureListener.instance());
}

From source file:com.edgenius.wiki.gwt.client.widgets.UploadDialog.java

License:Open Source License

public UploadDialog(AttachmentPanel attachmentPanel, final String spaceUname, String pageUuid,
        final PageType draft) {
    this.setText(Msg.consts.upload());
    this.setIcon(new Image(IconBundle.I.get().upload()));

    this.attachmentPanel = attachmentPanel;
    this.spaceUname = spaceUname;
    this.pageUuid = pageUuid;
    this.draft = draft;

    FlowPanel busyPanel = new FlowPanel();
    String id = HTMLPanel.createUniqueId();
    HTMLPanel busyPanelDiv = new HTMLPanel("<span></span><div id='" + id + "'></div>");
    busyPanelDiv.add(IconBundle.I.loading(), id);
    busyPanel.add(busyPanelDiv);/*w  w  w.ja v a  2  s. c o m*/
    busyPanelDiv.setStyleName(Css.BUSY_PANEL);
    busyPanelDiv.addStyleName("upload");

    deck.add(busyPanel);

    //If editing, always save auto draft - 2 scenarios: first if  pageUuid is null, means new page, must be save draft.
    //otherwise, an existing page, however, user needs a draft to reload these draft attachments - I set it always save draft that is 100% perfect because here 
    //does not check if this editing already has a draft saved. 
    if (attachmentPanel.getPageMain().getVisiblePanelIndex() == PageMain.EDIT_PANEL) {
        //           if(StringUtil.isBlank(pageUuid)){
        //could a unsaved new page - save a auto draft then turn page again
        attachmentPanel.getPageMain().editPanel.saveDraft(PageSaveMethod.SAVE_AUTO_DRAFT_STAY_IN_EDIT,
                new Callback<String>() {
                    @Override
                    public void callback(String pageUuid) {
                        UploadDialog.this.pageUuid = pageUuid;
                        Frame upload = new Frame(GwtClientUtils.getBaseUrl() + "pages/upload?uname="
                                + URL.encodeQueryString(spaceUname) + "&puuid=" + pageUuid + "&draft="
                                + draft.value());
                        upload.setSize("100%", "100%");
                        deck.add(upload);
                    }
                });
        //          }
    } else {
        Frame upload = new Frame(GwtClientUtils.getBaseUrl() + "pages/upload?uname="
                + URL.encodeQueryString(spaceUname) + "&puuid=" + pageUuid + "&draft=" + draft.value());
        upload.setSize("100%", "100%");
        deck.add(upload);
    }

    deck.showWidget(0);
    this.setWidget(deck);
    deck.setSize("100%", "100%");
    this.addStyleName(Css.UPLOAD_DIALOG_BOX);
    this.addDialogListener(this);

    this.bindJSMethod(this);

}

From source file:com.google.gwt.sample.kitchensink.client.Layouts.java

License:Apache License

public Layouts() {
    HTML contents = new HTML("This is a <code>ScrollPanel</code> contained at "
            + "the center of a <code>DockPanel</code>.  " + "By putting some fairly large contents "
            + "in the middle and setting its size explicitly, it becomes a "
            + "scrollable area within the page, but without requiring the use of " + "an IFRAME."
            + "Here's quite a bit more meaningless text that will serve primarily "
            + "to make this thing scroll off the bottom of its visible area.  "
            + "Otherwise, you might have to make it really, really small in order "
            + "to see the nifty scroll bars!");
    ScrollPanel scroller = new ScrollPanel(contents);
    scroller.setStyleName("ks-layouts-Scroller");

    DockPanel dock = new DockPanel();
    dock.setHorizontalAlignment(DockPanel.ALIGN_CENTER);
    HTML north0 = new HTML("This is the <i>first</i> north component", true);
    HTML east = new HTML("<center>This<br>is<br>the<br>east<br>component</center>", true);
    HTML south = new HTML("This is the south component");
    HTML west = new HTML("<center>This<br>is<br>the<br>west<br>component</center>", true);
    HTML north1 = new HTML("This is the <b>second</b> north component", true);
    dock.add(north0, DockPanel.NORTH);//from   w w  w  . j a  v a  2s . co  m
    dock.add(east, DockPanel.EAST);
    dock.add(south, DockPanel.SOUTH);
    dock.add(west, DockPanel.WEST);
    dock.add(north1, DockPanel.NORTH);
    dock.add(scroller, DockPanel.CENTER);

    FlowPanel flow = new FlowPanel();
    for (int i = 0; i < 8; ++i)
        flow.add(new CheckBox("Flow " + i));

    HorizontalPanel horz = new HorizontalPanel();
    horz.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE);
    horz.add(new Button("Button"));
    horz.add(new HTML("<center>This is a<br>very<br>tall thing</center>", true));
    horz.add(new Button("Button"));

    VerticalPanel vert = new VerticalPanel();
    vert.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    vert.add(new Button("Small"));
    vert.add(new Button("--- BigBigBigBig ---"));
    vert.add(new Button("tiny"));

    MenuBar menu = new MenuBar();
    MenuBar menu0 = new MenuBar(true), menu1 = new MenuBar(true);
    menu.addItem("menu0", menu0);
    menu.addItem("menu1", menu1);
    menu0.addItem("child00", (Command) null);
    menu0.addItem("child01", (Command) null);
    menu0.addItem("child02", (Command) null);
    menu1.addItem("child10", (Command) null);
    menu1.addItem("child11", (Command) null);
    menu1.addItem("child12", (Command) null);

    String id = HTMLPanel.createUniqueId();
    HTMLPanel html = new HTMLPanel("This is an <code>HTMLPanel</code>.  It allows you to add "
            + "components inside existing HTML, like this:" + "<span id='" + id + "'></span>"
            + "Notice how the menu just fits snugly in there?  Cute.");
    DOM.setStyleAttribute(menu.getElement(), "display", "inline");
    html.add(menu, id);

    VerticalPanel panel = new VerticalPanel();
    panel.setSpacing(8);
    panel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);

    panel.add(makeLabel("Dock Panel"));
    panel.add(dock);
    panel.add(makeLabel("Flow Panel"));
    panel.add(flow);
    panel.add(makeLabel("Horizontal Panel"));
    panel.add(horz);
    panel.add(makeLabel("Vertical Panel"));
    panel.add(vert);
    panel.add(makeLabel("HTML Panel"));
    panel.add(html);

    initWidget(panel);
    setStyleName("ks-layouts");
}

From source file:com.google.livingstories.client.lsp.ContentRenderer.java

License:Apache License

/**
 * Find the custom tags in the HTML and process them.
 *//*from  w w  w  .j  a  va  2 s  .c o  m*/
private HTMLPanel processTagsInChunk(String chunk) {
    HTMLPanel contentPanel = new HTMLPanel(chunk);

    try {
        // Process each type of tag
        for (ContentTag tag : contentTags) {
            NodeList<Element> tagNodeList = contentPanel.getElement().getElementsByTagName(tag.getTagName());
            List<Element> tagElements = new ArrayList<Element>();
            for (int i = 0; i < tagNodeList.getLength(); i++) {
                // First iterate over the node list and copy all the elements into a new list. Can't 
                // iterate and modify them at the same time because the list changes dynamically.
                tagElements.add(tagNodeList.getItem(i));
            }

            for (Element tagElement : tagElements) {
                Widget widget = tag.createWidgetToReplaceTag(tagElement);

                if (widget != null) {
                    // To replace the existing tag with the widget created above, the HTMLPanel needs
                    // to have the id of the element being replaced. Since we can't expect users to assign
                    // unique ids in every tag, we do this here automatically.
                    String uniqueId = HTMLPanel.createUniqueId();
                    tagElement.setId(uniqueId);
                    contentPanel.addAndReplaceElement(widget, uniqueId);
                }
            }
        }
    } catch (Exception e) {
        // Just return the panel with the original content
    }

    return contentPanel;
}