com.gargoylesoftware.htmlunit.javascript.host.html.HTMLTableElement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vaadin-client-compiler-deps Show documentation
Show all versions of vaadin-client-compiler-deps Show documentation
Vaadin is a web application framework for Rich Internet Applications (RIA).
Vaadin enables easy development and maintenance of fast and
secure rich web
applications with a stunning look and feel and a wide browser support.
It features a server-side architecture with the majority of the logic
running
on the server. Ajax technology is used at the browser-side to ensure a
rich
and interactive user experience.
/*
* Copyright (c) 2002-2011 Gargoyle Software Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gargoylesoftware.htmlunit.javascript.host.html;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import com.gargoylesoftware.htmlunit.BrowserVersionFeatures;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
import com.gargoylesoftware.htmlunit.javascript.host.RowContainer;
/**
* A JavaScript object representing a Table.
*
* @version $Revision: 6220 $
* @author David D. Kilzer
* @author Mike Bowler
* @author Daniel Gredler
* @author Chris Erskine
* @author Marc Guillemot
* @author Ahmed Ashour
*/
public class HTMLTableElement extends RowContainer {
private HTMLCollection tBodies_; // has to be a member to have equality (==) working
/**
* Creates an instance.
*/
public HTMLTableElement() {
}
/**
* Returns the table's caption element, or null if none exists. If more than one
* caption is declared in the table, this method returns the first one.
* @return the table's caption element
*/
public Object jsxGet_caption() {
final List captions = getDomNodeOrDie().getHtmlElementsByTagName("caption");
if (captions.isEmpty()) {
return null;
}
return getScriptableFor(captions.get(0));
}
/**
* Sets the caption.
* @param o the caption
*/
public void jsxSet_caption(final Object o) {
if (getBrowserVersion().hasFeature(BrowserVersionFeatures.GENERATED_105)) {
throw Context.reportRuntimeError("Can't set caption");
}
else if (!(o instanceof HTMLTableCaptionElement)) {
throw Context.reportRuntimeError("Not a caption");
}
// remove old caption (if any)
jsxFunction_deleteCaption();
final HTMLTableCaptionElement caption = (HTMLTableCaptionElement) o;
getDomNodeOrDie().appendChild(caption.getDomNodeOrDie());
}
/**
* Returns the table's tfoot element, or null if none exists. If more than one
* tfoot is declared in the table, this method returns the first one.
* @return the table's tfoot element
*/
public Object jsxGet_tFoot() {
final List tfoots = getDomNodeOrDie().getHtmlElementsByTagName("tfoot");
if (tfoots.isEmpty()) {
return null;
}
return getScriptableFor(tfoots.get(0));
}
/**
* Sets the tFoot.
* @param o the tFoot
*/
public void jsxSet_tFoot(final Object o) {
if (getBrowserVersion().hasFeature(BrowserVersionFeatures.GENERATED_106)) {
throw Context.reportRuntimeError("Can't set tFoot");
}
else if (!(o instanceof HTMLTableSectionElement
&& "TFOOT".equals(((HTMLTableSectionElement) o).jsxGet_tagName()))) {
throw Context.reportRuntimeError("Not a tFoot");
}
// remove old caption (if any)
jsxFunction_deleteTFoot();
final HTMLTableSectionElement tfoot = (HTMLTableSectionElement) o;
getDomNodeOrDie().appendChild(tfoot.getDomNodeOrDie());
}
/**
* Returns the table's thead element, or null if none exists. If more than one
* thead is declared in the table, this method returns the first one.
* @return the table's thead element
*/
public Object jsxGet_tHead() {
final List theads = getDomNodeOrDie().getHtmlElementsByTagName("thead");
if (theads.isEmpty()) {
return null;
}
return getScriptableFor(theads.get(0));
}
/**
* Sets the tHead.
* @param o the tHead
*/
public void jsxSet_tHead(final Object o) {
if (getBrowserVersion().hasFeature(BrowserVersionFeatures.GENERATED_107)) {
throw Context.reportRuntimeError("Can't set tHead");
}
else if (!(o instanceof HTMLTableSectionElement
&& "THEAD".equals(((HTMLTableSectionElement) o).jsxGet_tagName()))) {
throw Context.reportRuntimeError("Not a tHead");
}
// remove old caption (if any)
jsxFunction_deleteTHead();
final HTMLTableSectionElement thead = (HTMLTableSectionElement) o;
getDomNodeOrDie().appendChild(thead.getDomNodeOrDie());
}
/**
* Returns the tbody's in the table.
* @return the tbody's in the table
*/
public Object jsxGet_tBodies() {
if (tBodies_ == null) {
final HtmlTable table = (HtmlTable) getDomNodeOrDie();
tBodies_ = new HTMLCollection(table, false, "HTMLTableElement.tBodies") {
@Override
protected List