New Component: Reveal Element and a DataTable Stack #162

Merged
merged 11 commits into from Mar 29, 2012
@@ -402,12 +402,20 @@ public Object getCellValue() {
rowIndex = index;
Object obj = getSource().getRowValue(index);
+
+ if (obj == null) { //rows can be null, as stated in getRowValue docs
+ return "";
+ }
PropertyConduit conduit = getDataModel().get(cellModel).getConduit();
Class type = conduit.getPropertyType();
Object val = conduit.get(obj);
+
+ if (val == null) { //cells should be able to have null values
+ return "";
+ }
if (!String.class.equals(getDataModel().get(cellModel).getClass())
&& !Number.class.isAssignableFrom(getDataModel().get(cellModel).getClass()))
@@ -34,6 +34,7 @@
import org.got5.tapestry5.jquery.JQueryEventConstants;
import org.got5.tapestry5.jquery.internal.DataTableModel;
import org.got5.tapestry5.jquery.internal.DefaultDataTableModel;
+import org.got5.tapestry5.jquery.services.javascript.DataTableStack;
import org.got5.tapestry5.jquery.utils.JQueryUtils;
/**
@@ -42,12 +43,9 @@
* @tapestrydoc
*/
@Events(JQueryEventConstants.DATA)
-@Import(library = {
- "${assets.path}/components/datatables/jquery.dataTables.min.js",
- "${assets.path}/components/datatables/dataTables.js" },
- stylesheet = { "${assets.path}/components/datatables/tango/skin.css" })
+@Import(stack = DataTableStack.STACK_ID)
public class DataTable extends AbstractJQueryTable {
-
+
@Inject
private ComponentResources resources;
@@ -56,15 +54,16 @@
@Inject
private TranslatorSource ts;
-
+
@Environmental
private JavaScriptSupport support;
@Inject
private Request request;
-
+
@Inject
private Messages messages;
+
/**
* The default Implementation of the DataTableModel Interface
*/
@@ -79,10 +78,11 @@ JSONObject onData() {
getSortModel(), getOverrides());
}
-
- public DataTableModel getDefaultDataTableModel(){return reponse;}
-
-
+
+ @Override
+ public DataTableModel getDefaultDataTableModel(){return reponse;}
+
+
/**
* This method will construct the JSON options and call the DataTable contructor
@@ -91,7 +91,7 @@ JSONObject onData() {
void setJS() {
JSONObject setup = new JSONObject();
-
+
setup.put("id", getClientId());
JSONObject dataTableParams = new JSONObject();
@@ -103,26 +103,26 @@ void setJS() {
}
dataTableParams.put("sPaginationType", "full_numbers");
-
+
dataTableParams.put("iDisplayLength", getRowsPerPage());
-
+
dataTableParams.put("aLengthMenu", new JSONLiteral("[[" + getRowsPerPage()
+ "," + (getRowsPerPage() * 2) + "," + (getRowsPerPage() * 4) + "],["
+ getRowsPerPage() + "," + (getRowsPerPage() * 2) + ","
+ (getRowsPerPage() * 4) + "]]"));
-
+
JQueryUtils.merge(dataTableParams, getOptions());
-
+
//We set the bSortable parameters for each column. Cf : http://www.datatables.net/usage/columns
JSONArray sortableConfs = new JSONArray();
for(String propertyName : getPropertyNames()){
sortableConfs.put(new JSONObject(String.format("{'bSortable': %s}", getModel().get(propertyName).isSortable())));
}
-
+
dataTableParams.put("aoColumns", sortableConfs);
-
-
-
+
+
+
JSONObject language = new JSONObject();
language.put("sProcessing", messages.get("datatable.sProcessing"));
language.put("sLengthMenu", messages.get("datatable.sLengthMenu"));
@@ -136,7 +136,7 @@ void setJS() {
language.put("sSearch", messages.get("datatable.sSearch"));
language.put("sUrl", messages.get("datatable.sUrl"));
dataTableParams.put("oLanguage", language);
-
+
setup.put("params", dataTableParams);
support.addInitializerCall("dataTable", setup);
@@ -0,0 +1,62 @@
+package org.got5.tapestry5.jquery.components;
+
+import org.apache.tapestry5.BindingConstants;
+import org.apache.tapestry5.ClientElement;
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.annotations.Mixin;
+import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.annotations.SupportsInformalParameters;
+import org.apache.tapestry5.corelib.mixins.RenderInformals;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.javascript.JavaScriptSupport;
+import org.got5.tapestry5.jquery.mixins.Reveal;
+
+/**
+ * This component should be used together with the {@link Reveal} mixin.
+ *
+ * @author criedel
+ */
+@SupportsInformalParameters
+public class RevealElement implements ClientElement {
+
+ @Inject
+ private ComponentResources componentResources;
+
+ @Inject
+ private JavaScriptSupport javaScriptSupport;
+
+ @Mixin
+ private RenderInformals renderInformals;
+
+ /**
+ * The element name to render for the reveal element; this defaults to the
+ * element actually used in the template, or "div" if no specific element
+ * was specified.
+ */
+ @Parameter(required = true, allowNull = false, defaultPrefix = BindingConstants.LITERAL)
+ private String elementName;
+
+ private String clientId;
+
+ String defaultElementName() {
+
+ return componentResources.getElementName("div");
+ }
+
+ void beginRender(MarkupWriter writer) {
+
+ this.clientId = javaScriptSupport.allocateClientId(componentResources);
+ writer.element(elementName, "id", clientId);
+ }
+
+ void afterRender(MarkupWriter writer) {
+
+ writer.end();
+ }
+
+ public String getClientId() {
+
+ return this.clientId;
+ }
+}
@@ -4,6 +4,7 @@
import org.apache.tapestry5.ClientElement;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.AfterRender;
+import org.apache.tapestry5.annotations.HeartbeatDeferred;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.InjectContainer;
import org.apache.tapestry5.annotations.Parameter;
@@ -14,91 +15,110 @@
/**
* This mixin allows you to display a modal window.
- *
+ *
* @since 2.1.1
* @see <a href="http://www.zurb.com/playground/reveal-modal-plugin">http://www.zurb.com/playground/reveal-modal-plugin</a>
- *
+ *
* @tapestrydoc
*/
@Import(library = {"${assets.path}/mixins/reveal/jquery.reveal.js","${assets.path}/mixins/reveal/reveal.js"},
stylesheet={"${assets.path}/mixins/reveal/reveal.css"})
public class Reveal{
-
+
/**
* The id of the div you want to display.
*/
@Parameter(defaultPrefix=BindingConstants.LITERAL)
private String div;
-
+
+ @Parameter(name = "for", allowNull = false, defaultPrefix = BindingConstants.COMPONENT)
+ private ClientElement revealElement;
+
/**
* The effect you want to use. Possible parameter values : fade, fadeAndPop, none
*/
@Parameter(defaultPrefix=BindingConstants.LITERAL,
value="fadeAndPop")
private String animation;
-
+
/**
* How fast your animation has to be.
*/
@Parameter(defaultPrefix=BindingConstants.LITERAL,
value="300")
private Integer animationspeed;
-
+
/**
* Can we close the model window by clicking the background?
*/
@Parameter(defaultPrefix=BindingConstants.LITERAL,
value="true")
private boolean closeonbackgroundclick;
-
+
/**
* The CSS class for the element that will close the modal.
*/
@Parameter(defaultPrefix=BindingConstants.LITERAL,
value="close-reveal-modal")
private String dismissmodalclass;
-
+
/**
* The jQuery Selector for the element used to display the modal window (a link most of the time)
* By default, the #id of the element.
- *
+ *
* @since 3.2.0
*/
@Parameter(defaultPrefix=BindingConstants.LITERAL, value="prop:clientId")
private String selector;
-
- @InjectContainer
+
+ @InjectContainer
private ClientElement element;
-
+
@Inject
private JavaScriptSupport javaScriptSupport;
-
+
+ private JSONObject parameters;
+
@AfterRender
public void finish(MarkupWriter w){
-
- JSONObject jso = new JSONObject();
- jso.put("id", selector);
- jso.put("div", div);
-
- jso.put("animation", animation);
- jso.put("animationspeed", animationspeed);
- jso.put("closeonbackgroundclick", closeonbackgroundclick);
- jso.put("dismissmodalclass", dismissmodalclass);
-
- javaScriptSupport.addInitializerCall("reveal", jso);
-
+
+ parameters = new JSONObject();
+ parameters.put("id", selector);
+
+ if (revealElement == null) {
+
+ parameters.put("div", div);
+
+ } else {
+
+ updateParameters();
+ }
+
+ parameters.put("animation", animation);
+ parameters.put("animationspeed", animationspeed);
+ parameters.put("closeonbackgroundclick", closeonbackgroundclick);
+ parameters.put("dismissmodalclass", dismissmodalclass);
+
+ javaScriptSupport.addInitializerCall("reveal", parameters);
+
}
-
+
+ @HeartbeatDeferred
+ private void updateParameters() {
+
+ parameters.put("div", revealElement.getClientId());
+ }
+
public String getDiv() {
return div;
}
public void setDiv(String div) {
this.div = div;
}
-
+
public String getClientId(){
return "#"+element.getClientId();
}
-
+
}
@@ -27,7 +27,6 @@
import org.apache.tapestry5.ioc.annotations.Advise;
import org.apache.tapestry5.ioc.annotations.Contribute;
import org.apache.tapestry5.ioc.annotations.InjectService;
-import org.apache.tapestry5.ioc.annotations.Match;
import org.apache.tapestry5.ioc.annotations.Primary;
import org.apache.tapestry5.ioc.annotations.SubModule;
import org.apache.tapestry5.ioc.annotations.Symbol;
@@ -48,6 +47,7 @@
import org.got5.tapestry5.jquery.services.impl.RenderTrackerImpl;
import org.got5.tapestry5.jquery.services.impl.WidgetParamsImpl;
import org.got5.tapestry5.jquery.services.javascript.AjaxUploadStack;
+import org.got5.tapestry5.jquery.services.javascript.DataTableStack;
import org.got5.tapestry5.jquery.services.javascript.FormFragmentSupportStack;
import org.got5.tapestry5.jquery.services.javascript.FormSupportStack;
import org.got5.tapestry5.jquery.services.javascript.GalleryStack;
@@ -73,7 +73,8 @@ public static void contributeJavaScriptStackSource(MappedConfiguration<String, J
}
configuration.addInstance(AjaxUploadStack.STACK_ID, AjaxUploadStack.class);
configuration.addInstance(GalleryStack.STACK_ID, GalleryStack.class);
-
+ configuration.addInstance(DataTableStack.STACK_ID, DataTableStack.class);
+
configuration.addInstance("slider", Slider.class);
}
@@ -162,7 +163,7 @@ public static void contributeHttpServletRequestHandler(final OrderedConfiguratio
@Advise
@ClasspathProvider
- public static void modifyJsfile(MethodAdviceReceiver receiver, final AssetSource source,
+ public static void modifyJsfile(MethodAdviceReceiver receiver, final AssetSource source,
@Symbol(JQuerySymbolConstants.SUPPRESS_PROTOTYPE) boolean prototype)
throws SecurityException, NoSuchMethodException{
@@ -176,11 +177,11 @@ public void advise(MethodInvocation invocation) {
}
else if(res.getPath().contains("exceptiondisplay.js")){
invocation.setParameter(0, source.getExpandedAsset("${tapestry.jquery.path}/exceptiondisplay-jquery.js").getResource());
- }
+ }
invocation.proceed();
}
};
-
+
if(prototype)
receiver.adviseMethod(receiver.getInterface().getMethod("createAsset", Resource.class),advise);
}
Oops, something went wrong.