Example usage for com.google.gwt.user.client.ui Anchor wrap

List of usage examples for com.google.gwt.user.client.ui Anchor wrap

Introduction

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

Prototype

public static Anchor wrap(Element element) 

Source Link

Document

Creates an Anchor widget that wraps an existing <a> element.

Usage

From source file:com.eduworks.gwt.client.pagebuilder.PageAssembler.java

License:Apache License

/** preserves event handlers on element to be wrapped */
public static Widget elementToWidget(Element e, String typ) {
    Widget result = null;/*w ww . j  a v a2  s.c o  m*/
    if (e != null) {
        int eventsSunk = DOM.getEventsSunk(e);
        EventListener el = DOM.getEventListener(e);
        if (typ == TEXT)
            result = TextBox.wrap(e);
        else if (typ == TEXT_AREA)
            result = TextArea.wrap(e);
        else if (typ == PASSWORD)
            result = PasswordTextBox.wrap(e);
        else if (typ == LABEL)
            result = Label.wrap(e);
        else if (typ == A)
            result = Anchor.wrap(e);
        else if (typ == IMAGE)
            result = Image.wrap(e);
        else if (typ == SELECT)
            result = ListBox.wrap(e);
        else if (typ == HIDDEN)
            result = Hidden.wrap(e);
        else if (typ == FILE)
            result = FileUpload.wrap(e);
        else if (typ == FORM)
            result = FormPanel.wrap(e, true);
        else if (typ == FRAME)
            result = Frame.wrap(e);
        else if (typ == SUBMIT)
            result = SubmitButton.wrap(e);
        else if (typ == BUTTON)
            result = Button.wrap(e);
        else if (typ == CHECK_BOX)
            result = SimpleCheckBox.wrap(e);
        DOM.sinkEvents(e, eventsSunk);
        DOM.setEventListener(e, el);
    } else {
        if (typ == TEXT)
            result = new TextBox();
        else if (typ == TEXT_AREA)
            result = new TextArea();
        else if (typ == PASSWORD)
            result = new PasswordTextBox();
        else if (typ == LABEL)
            result = new Label();
        else if (typ == A)
            result = new Anchor();
        else if (typ == SELECT)
            result = new ListBox();
        else if (typ == IMAGE)
            result = new Image();
        else if (typ == HIDDEN)
            result = new Hidden();
        else if (typ == FILE)
            result = new FileUpload();
        else if (typ == FORM)
            result = new FormPanel();
        else if (typ == FRAME)
            result = new Frame();
        else if (typ == SUBMIT)
            result = new SubmitButton();
        else if (typ == BUTTON)
            result = new Button();
        else if (typ == CHECK_BOX)
            result = SimpleCheckBox.wrap(e);
    }
    return result;
}

From source file:com.eduworks.gwt.client.pagebuilder.PageAssembler.java

License:Apache License

/** preserves event handlers on element to be wrapped  */
public static Widget elementToWidget(String elementName, String typ) {
    Widget result = null;//from  w w  w  .j av  a  2  s  .co  m
    Element e = DOM.getElementById(elementName);
    if (e != null) {
        int eventsSunk = DOM.getEventsSunk(e);
        EventListener el = DOM.getEventListener(e);
        if (typ == TEXT)
            result = TextBox.wrap(e);
        else if (typ == TEXT_AREA)
            result = TextArea.wrap(e);
        else if (typ == PASSWORD)
            result = PasswordTextBox.wrap(e);
        else if (typ == LABEL)
            result = Label.wrap(e);
        else if (typ == A)
            result = Anchor.wrap(e);
        else if (typ == SELECT)
            result = ListBox.wrap(e);
        else if (typ == IMAGE)
            result = Image.wrap(e);
        else if (typ == HIDDEN)
            result = Hidden.wrap(e);
        else if (typ == FILE)
            result = FileUpload.wrap(e);
        else if (typ == FORM)
            result = FormPanel.wrap(e, true);
        else if (typ == FRAME)
            result = Frame.wrap(e);
        else if (typ == SUBMIT)
            result = SubmitButton.wrap(e);
        else if (typ == BUTTON)
            result = Button.wrap(e);
        else if (typ == CHECK_BOX)
            result = SimpleCheckBox.wrap(e);
        DOM.sinkEvents(e, eventsSunk);
        DOM.setEventListener(e, el);
    } else {
        if (typ == TEXT)
            result = new TextBox();
        else if (typ == TEXT_AREA)
            result = new TextArea();
        else if (typ == PASSWORD)
            result = new PasswordTextBox();
        else if (typ == LABEL)
            result = new Label();
        else if (typ == A)
            result = new Anchor();
        else if (typ == IMAGE)
            result = new Image();
        else if (typ == SELECT)
            result = new ListBox();
        else if (typ == HIDDEN)
            result = new Hidden();
        else if (typ == FILE)
            result = new FileUpload();
        else if (typ == FORM)
            result = new FormPanel();
        else if (typ == FRAME)
            result = new Frame();
        else if (typ == SUBMIT)
            result = new SubmitButton();
        else if (typ == BUTTON)
            result = new Button();
        else if (typ == CHECK_BOX)
            result = SimpleCheckBox.wrap(e);
    }
    return result;
}

From source file:com.tsa.puridiom.client.msrrequest.MSRRequestUI.java

License:Apache License

private void addClickEventToSubmitButton() {
    Anchor a = Anchor.wrap(Document.get().getElementById("submitButton"));
    a.addClickHandler(new ClickHandler() {
        @Override/*from   ww  w  .ja  v  a2  s  .c  o  m*/
        public void onClick(ClickEvent event) {
            List<ContactInfo> orderList1 = (List<ContactInfo>) MSRRequestData.get()
                    .getDataProvider(Category.ORDER1).getList();
            List<ContactInfo> orderList2 = (List<ContactInfo>) MSRRequestData.get()
                    .getDataProvider(Category.ORDER2).getList();
            List<ContactInfo> orderList3 = (List<ContactInfo>) MSRRequestData.get()
                    .getDataProvider(Category.ORDER3).getList();
            List<ContactInfo> orderList4 = (List<ContactInfo>) MSRRequestData.get()
                    .getDataProvider(Category.ORDER4).getList();
            List<ContactInfo> orderList5 = (List<ContactInfo>) MSRRequestData.get()
                    .getDataProvider(Category.ORDER5).getList();
            List<ContactInfo> orderList6 = (List<ContactInfo>) MSRRequestData.get()
                    .getDataProvider(Category.ORDER6).getList();

            RootPanel.get("hidden")
                    .add(new Hidden("source_type_cmb1", sourceType1.getValue(sourceType1.getSelectedIndex())));

            for (ContactInfo contactInfo : orderList1) {
                RootPanel.get("hidden")
                        .add(new Hidden("source_ic_history_bucket1", contactInfo.getIcHistory()));
                RootPanel.get("hidden")
                        .add(new Hidden("source_ic_req_line_bucket1", contactInfo.getIcReqLine()));
            }

            RootPanel.get("hidden")
                    .add(new Hidden("source_type_cmb2", sourceType2.getValue(sourceType2.getSelectedIndex())));

            for (ContactInfo contactInfo : orderList2) {
                RootPanel.get("hidden")
                        .add(new Hidden("source_ic_history_bucket2", contactInfo.getIcHistory()));
                RootPanel.get("hidden")
                        .add(new Hidden("source_ic_req_line_bucket2", contactInfo.getIcReqLine()));
            }

            RootPanel.get("hidden")
                    .add(new Hidden("source_type_cmb3", sourceType3.getValue(sourceType3.getSelectedIndex())));

            for (ContactInfo contactInfo : orderList3) {
                RootPanel.get("hidden")
                        .add(new Hidden("source_ic_history_bucket3", contactInfo.getIcHistory()));
                RootPanel.get("hidden")
                        .add(new Hidden("source_ic_req_line_bucket3", contactInfo.getIcReqLine()));
            }

            RootPanel.get("hidden")
                    .add(new Hidden("source_type_cmb4", sourceType4.getValue(sourceType4.getSelectedIndex())));

            for (ContactInfo contactInfo : orderList4) {
                RootPanel.get("hidden")
                        .add(new Hidden("source_ic_history_bucket4", contactInfo.getIcHistory()));
                RootPanel.get("hidden")
                        .add(new Hidden("source_ic_req_line_bucket4", contactInfo.getIcReqLine()));
            }

            RootPanel.get("hidden")
                    .add(new Hidden("source_type_cmb5", sourceType5.getValue(sourceType5.getSelectedIndex())));

            for (ContactInfo contactInfo : orderList5) {
                RootPanel.get("hidden")
                        .add(new Hidden("source_ic_history_bucket5", contactInfo.getIcHistory()));
                RootPanel.get("hidden")
                        .add(new Hidden("source_ic_req_line_bucket5", contactInfo.getIcReqLine()));
            }

            RootPanel.get("hidden")
                    .add(new Hidden("source_type_cmb6", sourceType6.getValue(sourceType6.getSelectedIndex())));

            for (ContactInfo contactInfo : orderList6) {
                RootPanel.get("hidden")
                        .add(new Hidden("source_ic_history_bucket6", contactInfo.getIcHistory()));
                RootPanel.get("hidden")
                        .add(new Hidden("source_ic_req_line_bucket6", contactInfo.getIcReqLine()));
            }

            submitForm();
        }
    });
}

From source file:de.uni_koeln.spinfo.maalr.webapp.ui.common.client.HiJax.java

License:Apache License

public static Anchor getAnchor(String elementId) {
    try {//  ww w.  j a  v a2 s .c  o m
        Element element = DOM.getElementById(elementId);
        Anchor anchor = Anchor.wrap(element);
        anchor.setStylePrimaryName("anchorwrapper");
        return anchor;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:de.uni_koeln.spinfo.maalr.webapp.ui.user.client.User.java

License:Apache License

private void updateLanguageLinks(Element element) {
    String attribute = null;//from  www  .ja v a  2 s. co m
    try {
        attribute = element.getAttribute("class");
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    if (attribute != null && attribute.contains("lang_select")) {
        final Anchor anchor = Anchor.wrap(element);
        final String langParam = anchor.getHref().substring(anchor.getHref().lastIndexOf('?'));
        HiJax.hijackAnchor(anchor, new Command() {

            @Override
            public void execute() {
                String url = Window.Location.getPath() + langParam + "#" + History.getToken();
                Window.Location.assign(url);
            }
        });
    } else {
        for (int i = 0; i < element.getChildCount(); i++) {
            Node child = element.getChild(i);
            Element e = child.cast();
            updateLanguageLinks(e);
        }
    }
}

From source file:eml.studio.client.IndexPage.java

License:Open Source License

/**
 * IndexPage module load method//from  ww w . j a  va  2  s . co  m
 */
@Override
public void onModuleLoad() {
    init();
    loginPanel.addGuestLoginHandler(new GuestLoginHandler());
    loginPanel.addSignInHandler(new SignInHandler());
    loginPanel.addSignUpHandler(new SignUpHandler());
    loginPanel.addForgetPwdHandler(new ForgetPwdHandler());

    loginPanel.addDomHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == 13) {
                enterLogin();
            }
        }
    }, KeyUpEvent.getType());

    Element elem = DOM.getElementById("bda-login-a");
    loginAnchor = Anchor.wrap(elem);
    loginAnchor.setText(Constants.logUIMsg.login());
    DOM.sinkEvents(elem, Event.ONCLICK);
    DOM.setEventListener(elem, new EventListener() {
        @Override
        public void onBrowserEvent(Event event) {
            if (Event.ONCLICK == event.getTypeInt()) {
                registerPanel.hide();
                forgetPwdPanel.hide();

                if (loginPanel.isShowing())
                    loginPanel.hide();
                else {
                    loginPanel.showRelativeTo(loginAnchor);
                }
            }
        }

    });

    elem = DOM.getElementById("bda-logout-a");
    elem.setInnerText(Constants.logUIMsg.logout());
    DOM.sinkEvents(elem, Event.ONCLICK);
    DOM.setEventListener(elem, new EventListener() {
        @Override
        public void onBrowserEvent(Event event) {
            if (Event.ONCLICK == event.getTypeInt()) {
                accountSrv.logout(new AsyncCallback<Void>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        Window.Location.reload();
                    }

                    @Override
                    public void onSuccess(Void result) {
                        Window.Location.reload();
                    }

                });
            }
        }

    });

    Window.addResizeHandler(new ResizeHandler() {

        @Override
        public void onResize(ResizeEvent event) {
            if (loginPanel.isShowing())
                loginPanel.showRelativeTo(loginAnchor);
            if (registerPanel.isShowing())
                registerPanel.showRelativeTo(loginAnchor);
        }

    });

}

From source file:org.spiffyui.client.nav.NavItem.java

License:Apache License

/**
 * Create a new NavItem//from w  w  w. ja v a2  s.  c om
 * 
 * @param id     the id of the navigator item
 * @param displayName
 *               the display name of the navigation item
 * @param title  the title or tooltip of this navigation item
 * @param link   the link location - this affects the location if the user 
 *               right-mouse clicks and opens the link in a new tab
 */
public NavItem(String id, String displayName, String title, String link) {
    setElement(Document.get().createDivElement());
    getElement().setId(id);
    setStyleName("main-menuItem");

    if (title != null) {
        setTitle(title);
    }

    /*
     The Anchor widget doesn't want to wrap an element unless it is a
     direct child of the body tag.  I'm not really sure why since it
     works fine but throws an assertion error in hosted mode.  We can
     add it to the body and then move it after the widget wraps it.
     */
    Element el = Document.get().getBody().appendChild(Document.get().createAnchorElement());
    m_anchor = Anchor.wrap(el);
    getElement().appendChild(el);
    m_anchor.setText(displayName);
    m_anchor.setHref(link);

}

From source file:org.spiffyui.client.nav.NavSection.java

License:Apache License

/**
 * Creates a new section in the navigation bar
 * //w ww  . ja v  a  2s. c  o  m
 * @param id     the id for the section
 * @param displayName
 *               the display name for that section
 */
public NavSection(String id, String displayName) {
    m_id = id;
    m_displayName = displayName;

    setElement(Document.get().createDivElement());
    getElement().setId(m_id);
    setStyleName("main-menuSect");

    /*
     The Anchor widget doesn't want to wrap an element unless it is a
     direct child of the body tag.  I'm not really sure why since it
     works fine but throws an assertion error in hosted mode.  We can
     add it to the body and then move it after the widget wraps it.
     */
    Element el = Document.get().getBody().appendChild(Document.get().createAnchorElement());
    m_anchor = Anchor.wrap(el);
    getElement().appendChild(el);
    m_anchor.setText(m_displayName);
    m_anchor.setHref("#");
    m_anchor.getElement().addClassName("main-menuSectItem");
    m_anchor.getElement().addClassName("main-menuSectItemExpanded");

    m_anchor.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            m_expanded = !m_expanded;
            JSUtil.toggleSlide(m_id + " .main-menuSectItems", "fast");
            event.preventDefault();

            if (m_expanded) {
                m_anchor.getElement().addClassName("main-menuSectItemExpanded");
            } else {
                m_anchor.getElement().removeClassName("main-menuSectItemExpanded");
            }
        }
    });

    getElement().appendChild(Document.get().createDivElement()).addClassName("main-menuSectItems");

}