You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2010/03/28 14:26:03 UTC
svn commit: r928386 - in
/click/trunk/click/framework/src/org/apache/click/control: Form.java
Table.java
Author: sabob
Date: Sun Mar 28 12:26:03 2010
New Revision: 928386
URL: http://svn.apache.org/viewvc?rev=928386&view=rev
Log:
migrated html imports to head elements
Modified:
click/trunk/click/framework/src/org/apache/click/control/Form.java
click/trunk/click/framework/src/org/apache/click/control/Table.java
Modified: click/trunk/click/framework/src/org/apache/click/control/Form.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Form.java?rev=928386&r1=928385&r2=928386&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Form.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Form.java Sun Mar 28 12:26:03 2010
@@ -30,6 +30,8 @@ import javax.servlet.http.HttpServletRes
import org.apache.click.Context;
import org.apache.click.Control;
import org.apache.click.Page;
+import org.apache.click.element.CssImport;
+import org.apache.click.element.JsImport;
import org.apache.click.service.FileUploadService;
import org.apache.click.service.LogService;
import org.apache.click.util.ClickUtils;
@@ -569,11 +571,6 @@ public class Form extends AbstractContai
+ "if (field && field.focus && field.type != 'hidden' && field.disabled != true) { field.focus(); };\n"
+ "//--></script>\n";
- /** The HTML imports statements. */
- protected static final String HTML_IMPORTS =
- "<link type=\"text/css\" rel=\"stylesheet\" href=\"{0}/click/control{1}.css\"/>\n"
- + "<script type=\"text/javascript\" src=\"{0}/click/control{1}.js\"></script>\n";
-
// Instance Variables -----------------------------------------------------
/** The form action URL. */
@@ -1122,35 +1119,29 @@ public class Form extends AbstractContai
}
/**
- * Return the Form HTML head imports statements for the following resources:
- * <p/>
+ * Return the Form HTML HEAD elements for the following resources:
+ *
* <ul>
* <li><tt>click/control.css</tt></li>
* <li><tt>click/control.js</tt></li>
* </ul>
- * <p/>
- * Additionally all {@link #getControls() controls} import statements are
- * also returned.
*
- * @see org.apache.click.Control#getHtmlImports()
+ * @see org.apache.click.Control#getHeadElements()
*
- * @return the HTML head import statements for the control stylesheet and
- * JavaScript files
+ * @return the form list of HEAD elements to be included in the page
*/
@Override
- public String getHtmlImports() {
- HtmlStringBuffer buffer = new HtmlStringBuffer(512);
+ public List getHeadElements() {
+ if (headElements == null) {
+ headElements = super.getHeadElements();
- buffer.append(ClickUtils.createHtmlImport(HTML_IMPORTS, getContext()));
+ Context context = getContext();
+ String versionIndicator = ClickUtils.getResourceVersionIndicator(context);
- for (Control control : getControls()) {
- String htmlImports = control.getHtmlImports();
- if (htmlImports != null) {
- buffer.append(htmlImports);
- }
+ headElements.add(new CssImport("/click/control.css", versionIndicator));
+ headElements.add(new JsImport("/click/control.js", versionIndicator));
}
-
- return buffer.toString();
+ return headElements;
}
/**
Modified: click/trunk/click/framework/src/org/apache/click/control/Table.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Table.java?rev=928386&r1=928385&r2=928386&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Table.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Table.java Sun Mar 28 12:26:03 2010
@@ -26,8 +26,11 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
+import org.apache.click.Context;
import org.apache.click.Control;
+import org.apache.click.element.CssImport;
+import org.apache.click.element.CssStyle;
import org.apache.click.element.Element;
import org.apache.click.util.ClickUtils;
import org.apache.click.util.DataProvider;
@@ -276,20 +279,6 @@ public class Table extends AbstractContr
DARK_STYLES.add("report");
}
- /**
- * The table.css style sheet import link with a light contract sortable icon.
- */
- public static final String TABLE_IMPORTS_LIGHT =
- "<link type=\"text/css\" rel=\"stylesheet\" href=\"{0}/click/table{1}.css\"/>\n"
- + "<style type=\"text/css\"> th.sortable a '{'background: url({0}/click/column-sortable-light{1}.gif) center right no-repeat;'}' th.ascending a '{'background: url({0}/click/column-ascending-light{1}.gif) center right no-repeat;'}' th.descending a '{'background: url({0}/click/column-descending-light{1}.gif) center right no-repeat;'}' </style>\n";
-
- /**
- * The table.css style sheet import link with a dark contract sortable icon.
- */
- public static final String TABLE_IMPORTS_DARK =
- "<link type=\"text/css\" rel=\"stylesheet\" href=\"{0}/click/table{1}.css\"/>\n"
- + "<style type=\"text/css\"> th.sortable a '{'background: url({0}/click/column-sortable-dark{1}.gif) center right no-repeat;'}' th.ascending a '{'background: url({0}/click/column-ascending-dark{1}.gif) center right no-repeat;'}' th.descending a '{'background: url({0}/click/column-descending-dark{1}.gif) center right no-repeat;'}' </style>\n";
-
/** The attached style pagination banner position. */
public static final int PAGINATOR_ATTACHED = 1;
@@ -818,77 +807,83 @@ public class Table extends AbstractContr
* <pre class="codeHtml">
* hover:hover { color: navy } </pre>
*
- * @param hoverRows specify whether class 'hover' rows attribute is rendered (default false).
+ * @param hoverRows specify whether class 'hover' rows attribute is rendered
+ * (default false).
*/
public void setHoverRows(boolean hoverRows) {
this.hoverRows = hoverRows;
}
/**
- * Return the Table HTML head import statements for the following resources:
- * <p/>
+ * Return the Table HTML HEAD elements for the following resource:
+ *
* <ul>
* <li><tt>click/table.css</tt></li>
* </ul>
- * <p/>
- * Additionally all {@link #getControls() controls} import statements are
- * also returned.
*
- * @return the HTML head import statements for the control stylesheet
+ * Additionally, the HEAD elements of the {@link #getControlLink()} will
+ * also be returned.
+ *
+ * @return the list of HEAD elements for the Table
*/
@Override
- @SuppressWarnings("deprecation")
- public String getHtmlImports() {
- HtmlStringBuffer buffer = new HtmlStringBuffer(512);
+ public List<Element> getHeadElements() {
+ if (headElements == null) {
+ headElements = super.getHeadElements();
- // Flag indicating which import style to return
- boolean useDarkStyle = false;
- if (hasAttribute("class")) {
+ boolean isDarkStyle = isDarkStyle();
- String styleClasses = getAttribute("class");
-
- StringTokenizer tokens = new StringTokenizer(styleClasses, " ");
- while (tokens.hasMoreTokens()) {
- String token = tokens.nextToken();
- if (DARK_STYLES.contains(token)) {
- useDarkStyle = true;
- break;
+ Context context = getContext();
+ String versionIndicator = ClickUtils.getResourceVersionIndicator(context);
+ headElements.add(new CssImport("/click/table.css", versionIndicator));
+
+ String tableId = getId();
+ CssStyle cssStyle = new CssStyle();
+ cssStyle.setId(tableId + "_css_setup");
+
+ if (!headElements.contains(cssStyle)) {
+ String contextPath = context.getRequest().getContextPath();
+ HtmlStringBuffer buffer = new HtmlStringBuffer(100);
+ buffer.append("th.sortable a {\n");
+ buffer.append("background: url(");
+ buffer.append(contextPath);
+ buffer.append("/click/column-sortable-");
+ if (isDarkStyle) {
+ buffer.append("dark");
+ } else {
+ buffer.append("light");
}
- }
- }
-
- if (useDarkStyle) {
- buffer.append(ClickUtils.createHtmlImport(TABLE_IMPORTS_DARK, getContext()));
-
- } else {
- buffer.append(ClickUtils.createHtmlImport(TABLE_IMPORTS_LIGHT, getContext()));
- }
-
- if (hasControls()) {
- for (int i = 0, size = getControls().size(); i < size; i++) {
- Control control = (Control) getControls().get(i);
- String htmlImports = control.getHtmlImports();
- if (htmlImports != null) {
- buffer.append(htmlImports);
+ buffer.append(versionIndicator);
+ buffer.append(".gif)");
+ buffer.append(" center right no-repeat;}\n");
+ buffer.append("th.ascending a {\n");
+ buffer.append("background: url(");
+ buffer.append(contextPath);
+ buffer.append("/click/column-ascending-");
+ if (isDarkStyle) {
+ buffer.append("dark");
+ } else {
+ buffer.append("light");
}
+ buffer.append(versionIndicator);
+ buffer.append(".gif)");
+ buffer.append(" center right no-repeat;}\n");
+ buffer.append("th.descending a {\n");
+ buffer.append("background: url(");
+ buffer.append(contextPath);
+ buffer.append("/click/column-descending-");
+ if (isDarkStyle) {
+ buffer.append("dark");
+ } else {
+ buffer.append("light");
+ }
+ buffer.append(versionIndicator);
+ buffer.append(".gif)");
+ buffer.append(" center right no-repeat;}");
+ cssStyle.setContent(buffer.toString());
+ headElements.add(cssStyle);
}
- }
-
- return buffer.toString();
- }
- /**
- * Return the HEAD elements for the Table. The HEAD elements of the
- * {@link #getControlLink()} will also be included.
- *
- * @see org.apache.click.Control#getHtmlImports()
- *
- * @return the list of HEAD elements for the Table
- */
- @Override
- public List<Element> getHeadElements() {
- if (headElements == null) {
- headElements = super.getHeadElements();
headElements.addAll(getControlLink().getHeadElements());
}
return headElements;
@@ -1916,4 +1911,30 @@ public class Table extends AbstractContr
}
}
+ // Private Methods --------------------------------------------------------
+
+ /**
+ * Return true if a dark table style is selected, false otherwise.
+ *
+ * @return true if a dark table style is selectd, false otherwise
+ */
+ private boolean isDarkStyle() {
+
+ // Flag indicating which import style to return
+ boolean isDarkStyle = false;
+ if (hasAttribute("class")) {
+
+ String styleClasses = getAttribute("class");
+
+ StringTokenizer tokens = new StringTokenizer(styleClasses, " ");
+ while (tokens.hasMoreTokens()) {
+ String token = tokens.nextToken();
+ if (DARK_STYLES.contains(token)) {
+ isDarkStyle = true;
+ break;
+ }
+ }
+ }
+ return isDarkStyle;
+ }
}