Example usage for com.google.gwt.dom.client NodeList getItem

List of usage examples for com.google.gwt.dom.client NodeList getItem

Introduction

In this page you can find the example usage for com.google.gwt.dom.client NodeList getItem.

Prototype

public T getItem(int index) 

Source Link

Usage

From source file:org.ednovo.gooru.client.mvp.profilepage.data.item.PartnerLessonUc.java

License:Open Source License

public void setCollectionData(final ProfileLibraryDo profileLibraryDo, boolean isLessonHighlighted,
        Integer lessonNumber) {//from  ww  w  .  j  av  a  2  s.co  m
    if (profileLibraryDo != null) {
        lessonTitle.setHTML(profileLibraryDo.getTitle());
        lessonList.add(lessonTitle);
        lessonId = lessonNumber;
        conceptId = profileLibraryDo.getGooruOid();
        if (AppClientFactory.getCurrentPlaceToken().equals(PlaceTokens.PROFILE_PAGE)) {
            lessonTitle.addStyleName(style.lessonTitle());
            lessonTitle.addStyleName(style.collection());
        } else {
            //lessonTitle.addStyleName(style.libraryTitle());
            lessonTitle.addStyleName(style.libraryConceptTitle());
        }
    }
    if (lessonNumber == 1 && isLessonHighlighted) {
        if (AppClientFactory.getCurrentPlaceToken().equals(PlaceTokens.PROFILE_PAGE)) {
            lessonTitle.addStyleName(style.conceptActive());
        } else {
            lessonTitle.addStyleName(style.libraryConceptActive());
            lessonTitle.addStyleName(style.marginTop5());
        }
        openCollection();
        isLessonHighlighted = false;
    }
    lessonTitle.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            openCollection();
            NodeList links = lessonList.getElement().getParentElement().getChildNodes();
            for (int i = 0; i < links.getLength(); i++) {
                com.google.gwt.user.client.Element link = (com.google.gwt.user.client.Element) links.getItem(i);
                link.getFirstChildElement().removeClassName(style.conceptActive());
                link.getFirstChildElement().removeClassName(style.libraryConceptActive());
            }
            lessonTitle.addStyleName(style.conceptActive());
        }
    });
}

From source file:org.eurekastreams.web.client.ui.common.form.elements.BasicDropDownFormElement.java

License:Apache License

/**
 * Finds an item in the drop-down by value.
 * //from  w w  w  . j  av a 2  s .com
 * @param value
 *            Value to search for.
 * @return The DOM element for the item.
 */
private Element findElementByValue(final String value) {
    NodeList<Element> options = dropDown.getElement().getElementsByTagName("option");
    for (int i = 0; i < options.getLength(); i++) {
        Element option = options.getItem(i);
        if (option.getAttribute("value").equals(value)) {
            return option;
        }
    }
    return null;
}

From source file:org.eurekastreams.web.client.ui.pages.profile.tabs.PersonalProfileAboutTabPanel.java

License:Apache License

/**
 * Constructor./*from  w w  w  .  j  ava 2  s.c  o  m*/
 * 
 * @param person
 *            Person whose data to display.
 */
public PersonalProfileAboutTabPanel(final PersonModelView person) {
    final HashMap<String, String> workHistoryTabURL = new HashMap<String, String>();
    workHistoryTabURL.put("tab", "Work History & Education");

    final HashMap<String, String> basicInfoTabURL = new HashMap<String, String>();
    basicInfoTabURL.put("tab", "Basic Info");

    final Panel biographyPanel = createTitledPanel("Biography");
    final Panel interestsPanel = createTitledPanel("Interests");
    final Panel workHistoryPanel = createTitledPanel("Work History");
    final Panel educationPanel = createTitledPanel("Education");

    final String currentViewerAccountId = Session.getInstance().getCurrentPerson().getAccountId();

    addLeft(biographyPanel);
    addRight(interestsPanel);
    addRight(workHistoryPanel);
    addRight(educationPanel);

    if (person.getBiography() == null || stripHTML(person.getBiography()).trim().length() < 1) {
        if (currentViewerAccountId == person.getAccountId()) {
            CreateUrlRequest target = new CreateUrlRequest(Page.PERSONAL_SETTINGS,
                    Session.getInstance().getCurrentPerson().getAccountId());
            target.setParameters(workHistoryTabURL);
            biographyPanel.add(new Hyperlink("Add a biography.", Session.getInstance().generateUrl(target)));
        } else {
            biographyPanel.add(new HTML("A biography has not been added."));
        }
    } else {
        HTML bio = new HTML(person.getBiography());
        bio.addStyleName(StaticResourceBundle.INSTANCE.coreCss().profileAboutBiography());
        biographyPanel.add(bio);

        // force URLs to absolute
        NodeList<Element> links = bio.getElement().getElementsByTagName("a");
        if (links.getLength() > 0) {
            for (int i = 0; i < links.getLength(); i++) {
                Element link = links.getItem(i);
                String href = link.getAttribute("href");
                if (!href.isEmpty() && isRelativeUrl(href)) {
                    link.setAttribute("href", "http://" + href);
                }
            }
        }
    }

    List<String> interests = person.getInterests();

    if (interests == null || interests.isEmpty()) {
        if (currentViewerAccountId == person.getAccountId()) {
            CreateUrlRequest target = new CreateUrlRequest(Page.PERSONAL_SETTINGS,
                    Session.getInstance().getCurrentPerson().getAccountId());
            target.setParameters(basicInfoTabURL);
            interestsPanel.add(
                    new Hyperlink("Add a list of your interests.", Session.getInstance().generateUrl(target)));
        } else {
            interestsPanel.add(new HTML("Interests have not been added."));
        }

    } else {
        // TODO: keep sending this as a list of background items - will be changed to a list of Strings

        List<BackgroundItem> bgitems = new ArrayList<BackgroundItem>();
        for (String interest : interests) {
            bgitems.add(new BackgroundItem(interest, BackgroundItemType.NOT_SET));
        }

        interestsPanel.add(new BackgroundItemLinksPanel("interests or hobbies", bgitems));
    }

    Session.getInstance().getEventBus().addObserver(GotPersonalEmploymentResponseEvent.class,
            new Observer<GotPersonalEmploymentResponseEvent>() {
                public void update(final GotPersonalEmploymentResponseEvent event) {
                    Session.getInstance().getEventBus().removeObserver(GotPersonalEmploymentResponseEvent.class,
                            this);

                    if (event.getResponse().isEmpty()) {
                        if (currentViewerAccountId == person.getAccountId()) {
                            CreateUrlRequest target = new CreateUrlRequest(Page.PERSONAL_SETTINGS,
                                    Session.getInstance().getCurrentPerson().getAccountId());
                            target.setParameters(workHistoryTabURL);
                            workHistoryPanel.add(new Hyperlink("Add your work history.",
                                    Session.getInstance().generateUrl(target)));
                        } else {
                            workHistoryPanel.add(new HTML("Work history has not been added."));
                        }

                    } else {
                        for (Job job : event.getResponse()) {
                            workHistoryPanel.add(new EmploymentPanel(job, true));
                        }
                    }
                }
            });

    Session.getInstance().getEventBus().addObserver(GotPersonalEducationResponseEvent.class,
            new Observer<GotPersonalEducationResponseEvent>() {
                public void update(final GotPersonalEducationResponseEvent event) {
                    Session.getInstance().getEventBus().removeObserver(GotPersonalEducationResponseEvent.class,
                            this);

                    if (event.getResponse().isEmpty()) {
                        if (currentViewerAccountId == person.getAccountId()) {
                            CreateUrlRequest target = new CreateUrlRequest(Page.PERSONAL_SETTINGS,
                                    Session.getInstance().getCurrentPerson().getAccountId());

                            target.setParameters(workHistoryTabURL);
                            educationPanel.add(new Hyperlink("Add your educational background.",
                                    Session.getInstance().generateUrl(target)));
                        } else {
                            educationPanel.add(new HTML("Education has not been added."));
                        }

                    } else {
                        for (Enrollment enrollment : event.getResponse()) {
                            educationPanel.add(new EducationPanel(enrollment, true));
                        }
                    }
                }
            });

    PersonalEmploymentModel.getInstance().fetch(person.getId(), false);
    PersonalEducationModel.getInstance().fetch(person.getId(), false);
}

From source file:org.freemedsoftware.gwt.client.Util.java

License:Open Source License

/**
 * Update the style sheets to reflect the current theme and direction.
 * // ww w . j  a  v  a2  s  .c  o  m
 * @param currentTheme
 * @param lastTheme
 */
public static void updateStyleSheets(String currentTheme, String lastTheme) {
    // Generate the names of the style sheets to include
    String gwtStyleSheet = "resources/themes/" + currentTheme + "/" + currentTheme + ".css";
    String showcaseStyleSheet = "resources/" + currentTheme + "-stylesheet.css";
    if (LocaleInfo.getCurrentLocale().isRTL()) {
        gwtStyleSheet = gwtStyleSheet.replace(".css", "_rtl.css");
        showcaseStyleSheet = showcaseStyleSheet.replace(".css", "_rtl.css");
    }
    // Find existing style sheets that need to be removed
    boolean styleSheetsFound = false;
    final HeadElement headElem = StyleSheetLoader.getHeadElement();
    final List<Element> toRemove = new ArrayList<Element>();
    NodeList<Node> children = headElem.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node node = children.getItem(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element elem = Element.as(node);
            if (elem.getTagName().equalsIgnoreCase("link")
                    && elem.getPropertyString("rel").equalsIgnoreCase("stylesheet")) {
                styleSheetsFound = true;
                String href = elem.getPropertyString("href");
                // If the correct style sheets are already loaded, then we
                // should have
                // nothing to remove.
                if (href.contains(lastTheme)) {
                    toRemove.add(elem);
                }
            }
        }
    }
    lastTheme = currentTheme;
    // Return if we already have the correct style sheets

    if (styleSheetsFound && toRemove.size() == 0) {
        return;
    }

    // Detach the app while we manipulate the styles to avoid rendering
    // issues
    RootPanel.get().remove(CurrentState.getMainScreen());

    // Remove the old style sheets
    for (Element elem : toRemove) {
        headElem.removeChild(elem);
    }

    // Load the GWT theme style sheet
    String modulePath = GWT.getHostPageBaseURL();
    Command callback = new Command() {
        /**
         * The number of style sheets that have been loaded and executed
         * this command.
         */
        private int numStyleSheetsLoaded = 0;

        public void execute() {
            /*
             * Wait until all style sheets have loaded before re-attaching
             * the app.
             */
            numStyleSheetsLoaded++;
            if (numStyleSheetsLoaded < 2) {
                return;
            }

            /*
             * Different themes use different background colors for the body
             * element, but IE only changes the background of the visible
             * content on the page instead of changing the background color
             * of the entire page. By changing the display style on the body
             * element, we force IE to redraw the background correctly.
             */
            RootPanel.getBodyElement().getStyle().setProperty("display", "none");
            RootPanel.getBodyElement().getStyle().setProperty("display", "");
            RootPanel.get().add(CurrentState.getMainScreen());
        }
    };
    StyleSheetLoader.loadStyleSheet(modulePath + gwtStyleSheet,
            getCurrentReferenceStyleName("gwt", currentTheme), callback);

    /*
     * Load the showcase specific style sheet after the GWT theme style
     * sheet so that custom styles supercede the theme styles.
     */
    StyleSheetLoader.loadStyleSheet(modulePath + showcaseStyleSheet,
            getCurrentReferenceStyleName("Application", currentTheme), callback);
    CurrentState.LAST_THEME = currentTheme;
}

From source file:org.geomajas.gwt.client.gfx.context.VmlStyleUtil.java

License:Open Source License

/**
 * When applying ShapeStyles, we create child elements for fill and stroke. According to Microsoft, this is the
 * proper way to go.//  w ww  .j  a  v a 2 s  . co  m
 */
private static void applyShapeStyle(Element element, ShapeStyle style) {
    // First check the presence of the fill and stroke elements:
    NodeList<Element> fills = element.getElementsByTagName("fill");
    if (fills.getLength() == 0) {
        Element stroke = Dom.createElementNS(Dom.NS_VML, "stroke");
        element.appendChild(stroke);
        Element fill = Dom.createElementNS(Dom.NS_VML, "fill");
        element.appendChild(fill);
        fills = element.getElementsByTagName("fill");
    }

    // Then if fill-color then filled=true:
    if (style.getFillColor() != null) {
        element.setAttribute("filled", "true");
        fills.getItem(0).setAttribute("color", style.getFillColor());
        fills.getItem(0).setAttribute("opacity", Float.toString(style.getFillOpacity()));
    } else {
        element.setAttribute("filled", "false");
    }

    // Then if stroke-color then stroke=true:
    if (style.getStrokeColor() != null) {
        element.setAttribute("stroked", "true");
        NodeList<Element> strokes = element.getElementsByTagName("stroke");
        strokes.getItem(0).setAttribute("color", style.getStrokeColor());
        strokes.getItem(0).setAttribute("opacity", Float.toString(style.getStrokeOpacity()));
        element.setAttribute("strokeweight", Float.toString(style.getStrokeWidth()));
    } else {
        element.setAttribute("stroked", "false");
    }
}

From source file:org.gk.engine.client.build.field.XField.java

License:Open Source License

/**
 * ??TextField(?)//  w  w w.  java2  s  .c om
 * 
 * @param field
 */
private void setTextFieldAttribute(final TextField field) {
    if (!regex.equals("")) {
        field.setRegex(regex);
    }
    field.setPassword(Boolean.parseBoolean(pwd));

    if (!allowBlank.equals("")) {
        field.setAllowBlank(Boolean.parseBoolean(allowBlank));
    }

    if (max.matches(IRegExpUtils.POSITIVE_INTEGER)) {
        field.setMaxLength(Integer.parseInt(max));
    }

    if (min.matches(IRegExpUtils.POSITIVE_INTEGER)) {
        field.setMinLength(Integer.parseInt(min));
    }

    // elementrender??Render
    if (!maxLength.equals("")) {
        field.addListener(Events.Render, new Listener() {

            @Override
            public void handleEvent(BaseEvent be) {
                NodeList<Element> inputTag = field.getElement().getElementsByTagName("input");
                if (inputTag.getLength() > 0) {
                    // maxLengthL?IE?
                    inputTag.getItem(0).setAttribute("maxLength", maxLength);
                }
            }
        });
    }
}

From source file:org.gk.ui.client.com.form.gkRadio.java

License:Open Source License

@Override
public void setValue(Boolean value) {
    if (rendered && value != null && value && group == null) {
        String select = "input[type='radio'][name='" + name + "']";
        NodeList list = DomQuery.select(select);
        for (int i = 0; i < list.getLength(); i++) {
            Element ele = ((Element) list.getItem(i)).getParentElement();
            if (ele.getId().equals(getId())) {
                continue;
            }/*from  ww w.  j av a2s. c o m*/
            Component com = ComponentManager.get().get(ele.getId());
            if (com instanceof Field) {
                Field fd = (Field) com;
                fd.setValue(false);
            }
        }
    }
    super.setValue(value);
}

From source file:org.gwtbootstrap3.extras.select.client.ui.SelectBase.java

License:Apache License

/**
 * Returns the item list./*from   w  w  w .j  a  v  a2s.c  om*/
 *
 * @return the item list
 */
public List<Option> getItems() {
    List<Option> selectedItems = new ArrayList<>(0);
    NodeList<OptionElement> items = selectElement.getOptions();
    for (int i = 0; i < items.getLength(); i++) {
        OptionElement item = items.getItem(i);
        Option option = itemMap.get(item);
        if (option != null)
            selectedItems.add(option);
    }
    return selectedItems;
}

From source file:org.gwtopenmaps.demo.openlayers.client.examples.format.xml.XMLFormatExample.java

License:Apache License

@Override
public void buildPanel() {
    contentPanel.add(new HTML("Shows the use of the OpenLayers XML format class<br/>"
            + "OpenLayers has a very simple XML format class (OpenLayers.Format.XML) "
            + "that can be used to read/write XML docs. The methods available on the "
            + "XML format (or parser if you like) allow for reading and writing of "
            + "the various XML flavors used by the library - in particular the vector "
            + "data formats. It is by no means intended to be a full-fledged XML toolset. "
            + "Additional methods will be added only as needed elsewhere in the library.<br/>"
            + "This page loads an XML document and demonstrates a few of the methods available in the parser."));

    final Label outputValue = new Label();

    HorizontalPanel panel = new HorizontalPanel();

    Label statusLabel = new Label("Status : ");
    final InlineHTML statusLabelValue = new InlineHTML();
    statusLabelValue.setHTML("<strong>XML document loaded</strong>.");
    panel.add(statusLabel);//www.  j av  a 2s.co m
    panel.add(statusLabelValue);

    contentPanel.add(panel);

    contentPanel.add(new HTML("<p>After the XML document loads, see the result "
            + "of a few of the methods below. Assume that you start with the " + "following code: <br/>"
            + "var format = new OpenLayers.Format.XML();</p>" + "Sample methods"));

    VerticalPanel vp = new VerticalPanel();

    GwtOpenLayersULComponent uLComponent = new GwtOpenLayersULComponent();

    HorizontalPanel wp = new HorizontalPanel();
    Anchor write = new Anchor();
    write.setHTML("format.write()");
    wp.add(write);
    wp.add(new Label(" - write the XML doc as text"));
    write.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            outputValue.setText(xmlFormat.write(baseEl));
        }
    });

    uLComponent.add(wp);

    HorizontalPanel ebyTagNames = new HorizontalPanel();
    Anchor tagNames = new Anchor();
    tagNames.setHTML("format.getElementsByTagNameNS()");
    ebyTagNames.add(tagNames);
    ebyTagNames.add(new Label(" - get all gml:MultiPolygon"));
    tagNames.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            NodeList elements = xmlFormat.getElementsByTagNameNS(baseEl.getDocumentElement(),
                    "http://www.opengis.net/gml", "MultiPolygon");
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < elements.getLength(); i++) {
                builder.append(xmlFormat.write(elements.getItem(i)));
            }
            outputValue.setText(builder.toString());
        }
    });

    uLComponent.add(ebyTagNames);

    HorizontalPanel hasAttributePanel = new HorizontalPanel();
    Anchor hasAttAnchor = new Anchor();
    hasAttAnchor.setHTML("format.hasAttributeNS()");
    hasAttributePanel.add(hasAttAnchor);
    hasAttributePanel.add(new Label(" - test to see schemaLocation "
            + "attribute exists in the http://www.w3.org/2001/XMLSchema-instance namespace"));
    hasAttAnchor.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            outputValue.setText(String.valueOf(xmlFormat.hasAttributeNS(baseEl.getDocumentElement(),
                    "http://www.w3.org/2001/XMLSchema-instance", "schemaLocation")));
        }
    });

    uLComponent.add(hasAttributePanel);

    vp.add(uLComponent);

    HorizontalPanel getAttrNodeNSPanel = new HorizontalPanel();
    Anchor getAttrNodeNSAnchor = new Anchor();
    getAttrNodeNSAnchor.setHTML("format.getAttributeNodeNS()");
    getAttrNodeNSPanel.add(getAttrNodeNSAnchor);
    getAttrNodeNSPanel.add(new Label(
            " - get schemaLocation attribute in " + "the http://www.w3.org/2001/XMLSchema-instance namespace"));
    getAttrNodeNSAnchor.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            Element e = xmlFormat.getAttributeNodeNS(baseEl.getDocumentElement(),
                    "http://www.w3.org/2001/XMLSchema-instance", "schemaLocation");
            outputValue.setText(e.getNodeName() + " = " + e.getNodeValue());
        }
    });

    uLComponent.add(getAttrNodeNSPanel);

    HorizontalPanel getAttrNSHorizontalPanel = new HorizontalPanel();
    Anchor getAttrNSAnchor = new Anchor();
    getAttrNSAnchor.setHTML("format.getAttributeNS()");
    getAttrNSHorizontalPanel.add(getAttrNSAnchor);
    getAttrNSHorizontalPanel.add(new Label(" - get schemaLocation "
            + "attribute value in the http://www.w3.org/2001/" + "XMLSchema-instance namespace"));
    getAttrNSAnchor.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            outputValue.setText(xmlFormat.getAttributeNS(baseEl.getDocumentElement(),
                    "http://www.w3.org/2001/XMLSchema-instance", "schemaLocation"));
        }
    });

    uLComponent.add(getAttrNSHorizontalPanel);

    HorizontalPanel createElNSPanel = new HorizontalPanel();
    Anchor createElNSAnchor = new Anchor();
    createElNSAnchor.setHTML("format.createElementNS()");
    createElNSPanel.add(createElNSAnchor);
    createElNSPanel.add(new Label(" - create a foo:TestNode element" + " (and append it to the doc)"));
    createElNSAnchor.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            Element e = xmlFormat.createElementNS("http://bar.com/foo", "foo:TestNode");
            baseEl.getDocumentElement().appendChild(e);
            outputValue.setText(xmlFormat.write(baseEl));
        }
    });

    uLComponent.add(createElNSPanel);

    HorizontalPanel createTextNodePanel = new HorizontalPanel();
    Anchor createTextNodeAnchor = new Anchor();
    createTextNodeAnchor.setHTML("format.createTextNode()");
    createTextNodePanel.add(createTextNodeAnchor);
    createTextNodePanel.add(new Label(" - create a text node" + " (and append it to the doc)"));
    createTextNodeAnchor.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            Element e = xmlFormat.createTextNode("test text ");
            baseEl.getDocumentElement().appendChild(e);
            outputValue.setText(xmlFormat.write(baseEl));
        }
    });

    uLComponent.add(createTextNodePanel);

    contentPanel.add(vp);
    contentPanel.add(new InlineHTML("<strong>Output</strong> :"));
    contentPanel.add(outputValue);

    initWidget(contentPanel);
}

From source file:org.gwtwidgets.client.stream.HtmlStreamReader.java

License:Apache License

private Message checkForEOF(Document document) {
    NodeList<Element> eSpans = document.getElementsByTagName("span");
    if (eSpans.getLength() == 0)
        return null;
    Element eSpan = eSpans.getItem(0);
    if ("EOF".equals(eSpan.getInnerText())) {
        Message message = new Message();
        message.setEOF(true);/*from   w  w w. j  a  v a2s  . c om*/
        return message;
    }
    return null;
}