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.opencms.ade.containerpage.client.ui.CmsContainerPageElementPanel.java

License:Open Source License

/**
 * Returns if the option bar position collides with any iframe child elements.<p>
 * //from   w ww . j  ava 2 s . co  m
 * @return <code>true</code> if there are iframe child elements located no less than 25px below the upper edge of the element
 */
private boolean isOptionbarIFrameCollision() {

    if (RootPanel.getBodyElement().isOrHasChild(getElement())) {
        int elementTop = getElement().getAbsoluteTop();
        NodeList<Element> frames = getElement().getElementsByTagName(CmsDomUtil.Tag.iframe.name());
        for (int i = 0; i < frames.getLength(); i++) {

            if ((frames.getItem(i).getAbsoluteTop() - elementTop) < 25) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.opencms.ade.contenteditor.client.CmsContentEditor.java

License:Open Source License

/**
 * Replaces the id's within about attributes of the given element and all it's children.<p>
 *
 * @param element the element/*from w w w .ja  v  a 2 s  .  c  o m*/
 * @param oldId the old id
 * @param newId the new id
 */
public static void replaceResourceIds(Element element, String oldId, String newId) {

    NodeList<Element> children = CmsDomUtil
            .querySelectorAll("[property^=\"opencms://\"][about*=\"" + oldId + "\"]", element);
    if (children.getLength() > 0) {
        for (int i = 0; i < children.getLength(); i++) {
            Element child = children.getItem(i);
            String about = child.getAttribute("about");
            about = about.replace(oldId, newId);
            child.setAttribute("about", about);
        }
    }
}

From source file:org.opencms.ade.contenteditor.client.CmsContentEditor.java

License:Open Source License

/**
 * Sets all annotated child elements editable.<p>
 *
 * @param element the element//from  ww  w  .  ja va  2  s  .c  om
 * @param serverId the editable resource structure id
 * @param editable <code>true</code> to enable editing
 *
 * @return <code>true</code> if the element had editable elements
 */
public static boolean setEditable(Element element, String serverId, boolean editable) {

    I_CmsLayoutBundle.INSTANCE.editorCss().ensureInjected();
    NodeList<Element> children = CmsDomUtil
            .querySelectorAll("[property^=\"opencms://\"][about*=\"" + serverId + "\"]", element);
    if (children.getLength() > 0) {
        for (int i = 0; i < children.getLength(); i++) {
            Element child = children.getItem(i);
            if (editable) {
                child.addClassName(I_CmsLayoutBundle.INSTANCE.editorCss().inlineEditable());
            } else {
                child.removeClassName(I_CmsLayoutBundle.INSTANCE.editorCss().inlineEditable());
            }
        }
        return true;
    }
    return false;
}

From source file:org.opencms.ade.contenteditor.client.CmsContentEditor.java

License:Open Source License

/**
 * Initializes the editor.<p>/*from  w w w  .  j a v  a2 s  .  c  om*/
 *
 * @param context the editor context
 * @param contentDefinition the content definition
 * @param formParent the inline form parent panel, used for inline editing only
 * @param inline <code>true</code> to render the editor for inline editing
 * @param mainLocale the main language to copy in case the element language node does not exist yet
 */
void initEditor(CmsEditorContext context, CmsContentDefinition contentDefinition,
        I_CmsInlineFormParent formParent, boolean inline, String mainLocale) {

    m_context = context;
    m_locale = contentDefinition.getLocale();
    m_entityId = contentDefinition.getEntityId();
    m_deleteOnCancel = contentDefinition.isDeleteOnCancel();
    m_autoUnlock = contentDefinition.isAutoUnlock();
    m_isDirectEdit = contentDefinition.isDirectEdit();

    initClosingHandler();
    setContentDefinition(contentDefinition);
    initToolbar();
    if (inline && (formParent != null)) {
        if ((mainLocale != null) && (CmsDomUtil.querySelector("[about^='" + m_entityId + "']",
                formParent.getElement()) == null)) {
            // in case a main locale is given and there are not any HTML elements attributed to the current entity id,
            // check if the content was rendered for the main locale
            CmsUUID structureId = CmsContentDefinition.entityIdToUuid(m_entityId);
            String mainLocaleEntityId = CmsContentDefinition.uuidToEntityId(structureId, mainLocale);
            NodeList<Element> elements = CmsDomUtil.querySelectorAll("[about^='" + mainLocaleEntityId + "']",
                    formParent.getElement());
            if (elements.getLength() > 0) {
                for (int i = 0; i < elements.getLength(); i++) {
                    Element element = elements.getItem(i);
                    element.setAttribute("about",
                            element.getAttribute("about").replace(mainLocaleEntityId, m_entityId));
                }
            }

        }
        initEditOverlay(formParent.getElement());
        addOverlayClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {

                exitWithSaving();
            }
        });
        m_hideHelpBubblesButton.setVisible(false);
        setNativeResourceInfo(m_sitePath, m_locale);
        initEntityObserver();
        if (m_definitions.get(m_locale).hasEditorChangeHandlers()) {
            initEditorChangeHandlers(m_definitions.get(m_locale).getEditorChangeScopes());
        }
        renderInlineEntity(m_entityId, formParent);
    } else {
        initFormPanel();
        renderFormContent();
        fixFocus();
    }
    if (contentDefinition.isPerformedAutocorrection()) {
        CmsNotification.get().send(CmsNotification.Type.NORMAL,
                Messages.get().key(Messages.GUI_WARN_INVALID_XML_STRUCTURE_0));
        setChanged();
    }
}

From source file:org.opencms.ugc.client.CmsUgcWrapper.java

License:Open Source License

/**
 * Gets all form fields.<p>//from w  w w . jav a  2 s .  com
 *
 * @return the list of form fields
 */
List<InputElement> getAllFields() {

    NodeList<Element> fields = getElement().getElementsByTagName(InputElement.TAG);
    List<InputElement> result = Lists.newArrayList();
    for (int i = 0; i < fields.getLength(); i++) {
        InputElement field = InputElement.as(fields.getItem(i));
        result.add(field);
    }
    return result;
}

From source file:org.opencms.ui.client.CmsBreadCrumbConnector.java

License:Open Source License

/**
 * Updates the entry max-width according to the available space.<p>
 *///from  w  w  w. j a va2s . co  m
void updateMaxWidth() {

    Element base = getWidget().getElement();
    int availableWidth = base.getOffsetWidth();
    int requiredWidth = 0;
    NodeList<Element> children = CmsDomUtil.querySelectorAll("div > a, div > span", base);
    for (int i = 0; i < children.getLength(); i++) {
        Element child = children.getItem(i);
        Style style = child.getFirstChildElement().getStyle();
        style.setProperty("maxWidth", "none");
        requiredWidth += child.getOffsetWidth();
        style.clearProperty("maxWidth");
    }
    if (requiredWidth > availableWidth) {
        int padding = 30 + ((children.getLength() - 1) * 35);
        int maxWidth = (availableWidth - padding) / children.getLength();
        setMaxWidth(maxWidth + "px");
    } else {
        setMaxWidth("none");
    }
}

From source file:org.opennms.features.gwt.combobox.client.NodeSuggestionCombobox.java

License:Open Source License

/**
 * This is the entry point method.//w w  w.j  ava  2  s  . c  o m
 */
@Override
public void onModuleLoad() {

    if (Window.Navigator.getUserAgent().contains("MSIE")) {
        NodeList<Element> divs = RootPanel.getBodyElement().getElementsByTagName("div");
        for (int j = 0; j < divs.getLength(); j++) {
            Element element = divs.getItem(j);
            if (element.hasAttribute("name")
                    && element.getAttribute("name").contains("opennms-nodeSuggestionCombobox")) {
                createView(element);
            }
        }

    } else {
        NodeList<Element> nodes = RootPanel.getBodyElement()
                .getElementsByTagName("opennms:nodeSuggestionCombobox");
        if (nodes.getLength() > 0) {
            for (int i = 0; i < nodes.getLength(); i++) {
                createView(nodes.getItem(i));
            }

        }
    }

}

From source file:org.opennms.features.gwt.graph.resource.list.client.GraphResourceList.java

License:Open Source License

/**
 * This is the entry point method./*  w w w . jav a2s  .  c om*/
 */
@Override
public void onModuleLoad() {

    if (Navigator.getUserAgent().contains("MSIE")) {

        NodeList<Element> divs = RootPanel.getBodyElement().getElementsByTagName("div");
        for (int k = 0; k < divs.getLength(); k++) {
            Element element = divs.getItem(k);
            if (element.hasAttribute("name")) {
                if (element.getAttribute("name").equals("opennms-kscChooseResourceList")) {
                    createKscChooseResourceView(element);
                } else if (element.getAttribute("name").equals("opennms-graphResourceList")) {
                    createGraphResourceView(element);
                } else if (element.getAttribute("name").equals("opennms-nodeSnmpReportList")) {
                    createKscReportListView(element);
                } else if (element.getAttribute("name").equals("opennms-kscCustomReportList")) {
                    createKscCustomReportView(element);
                } else if (element.getAttribute("name").equals("opennms-reportSelectionList")) {
                    createReportSelectView(element);
                }
            }
        }

    } else {
        NodeList<Element> kscChooseResourceList = RootPanel.getBodyElement()
                .getElementsByTagName("opennms:kscChooseResourceList");
        if (kscChooseResourceList.getLength() > 0) {
            for (int i = 0; i < kscChooseResourceList.getLength(); i++) {
                Element elem = kscChooseResourceList.getItem(i);
                createKscChooseResourceView(elem);
            }
        }

        NodeList<Element> graphResourceListNodes = RootPanel.getBodyElement()
                .getElementsByTagName("opennms:graphResourceList");
        if (graphResourceListNodes.getLength() > 0) {
            for (int i = 0; i < graphResourceListNodes.getLength(); i++) {
                Element elem = graphResourceListNodes.getItem(i);
                createGraphResourceView(elem);
            }
        }

        NodeList<Element> nodeSnmpReportNodes = RootPanel.getBodyElement()
                .getElementsByTagName("opennms:nodeSnmpReportList");
        if (nodeSnmpReportNodes.getLength() > 0) {
            for (int i = 0; i < nodeSnmpReportNodes.getLength(); i++) {
                Element elem = nodeSnmpReportNodes.getItem(i);
                createKscReportListView(elem);
            }
        }

        NodeList<Element> kscCustomReportNodes = RootPanel.getBodyElement()
                .getElementsByTagName("opennms:kscCustomReportList");
        if (kscCustomReportNodes.getLength() > 0) {
            for (int i = 0; i < kscCustomReportNodes.getLength(); i++) {
                Element elem = kscCustomReportNodes.getItem(i);
                createKscCustomReportView(elem);
            }
        }

        NodeList<Element> reportSelectListNodes = RootPanel.getBodyElement()
                .getElementsByTagName("opennms:reportSelectionList");
        if (reportSelectListNodes.getLength() > 0) {
            for (int i = 0; i < reportSelectListNodes.getLength(); i++) {
                Element elem = reportSelectListNodes.getItem(i);
                createReportSelectView(elem);
            }
        }
    }
}

From source file:org.opennms.features.gwt.ksc.add.client.KSCResourceAddGraph.java

License:Open Source License

@Override
public void onModuleLoad() {
    final KscReportService service = new DefaultKscReportService();
    final NodeList<Element> nodes = RootPanel.getBodyElement().getElementsByTagName("opennms-addKscReport");

    if (nodes.getLength() > 0) {
        service.getAllReports(new RequestCallback() {
            @Override/* www  .ja  v  a2s.c o m*/
            public void onResponseReceived(final Request request, final Response response) {
                final String responseText;
                if (response.getStatusCode() == 200) {
                    responseText = response.getText();
                } else {
                    if (DEBUG) {
                        responseText = m_debugResponse;
                    } else {
                        Window.alert("Error occurred retrieving list of KSC reports (response was "
                                + response.getStatusCode() + ".");
                        responseText = null;
                    }
                }

                if (responseText != null) {
                    handleResponseText(nodes, responseText);
                }
            }

            @Override
            public void onError(final Request request, final Throwable exception) {
                if (DEBUG) {
                    handleResponseText(nodes, m_debugResponse);
                } else {
                    Window.alert("Error occurred retrieving list of KSC reports: "
                            + exception.getLocalizedMessage());
                }
            }

            public void handleResponseText(final NodeList<Element> nodes, final String responseText) {
                final List<KscReport> reports = KscReportRestResponseMapper.translate(responseText);
                for (int i = 0; i < nodes.getLength(); i++) {
                    createView(nodes.getItem(i), reports);
                }
            }
        });
    }

}

From source file:org.opennms.features.gwt.ksc.combobox.client.KSCResourceCombobox.java

License:Open Source License

/**
 * This is the entry point method./*from w  w  w  .  j a  v  a2 s  .  c  om*/
 */
@Override
public void onModuleLoad() {

    if (Window.Navigator.getUserAgent().contains("MSIE")) {
        NodeList<Element> divs = RootPanel.getBodyElement().getElementsByTagName("div");
        for (int j = 0; j < divs.getLength(); j++) {
            Element element = divs.getItem(j);
            if (element.hasAttribute("name")
                    && element.getAttribute("name").contains("opennms-kscReportCombobox")) {
                createView(element);
            }
        }

    } else {
        NodeList<Element> nodes = RootPanel.getBodyElement().getElementsByTagName("opennms:kscReportCombobox");
        if (nodes.getLength() > 0) {
            for (int i = 0; i < nodes.getLength(); i++) {
                createView(nodes.getItem(i));
            }
        }
    }
}