Skip to content

Commit

Permalink
Merge pull request #347 from zhedar/refactorings
Browse files Browse the repository at this point in the history
Refactor AddResourcesListener and Tooltips
  • Loading branch information
stephanrauh committed Apr 28, 2016
2 parents cc35075 + 44f5e7e commit 3427ac7
Show file tree
Hide file tree
Showing 82 changed files with 422 additions and 684 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/bootsfaces/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public final class C {

//Font Awesome
//public static final String P_USEFONTAWESOME ="BootsFaces_USE_FA";
public static final String FA_VERSION="4.5.0";
public static final String FA_VERSION="4.6.1";
public static final String FONTAWESOME_CDN_URL="//maxcdn.bootstrapcdn.com/font-awesome/"+FA_VERSION+"/css/font-awesome.min.css";

//Meta tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void encodeEnd(FacesContext context) throws IOException {
}
context.getResponseWriter()
.endElement("div");
Tooltip.activateTooltips(context, getAttributes(), this);
Tooltip.activateTooltips(context, this);

}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/bootsfaces/component/alert/Alert.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ public class Alert extends UIComponentBase implements net.bootsfaces.render.IHas
public static final String DEFAULT_RENDERER = "net.bootsfaces.component.alert.Alert";

public Alert() {
Tooltip.addResourceFile();
Tooltip.addResourceFiles();
AddResourcesListener.addThemedCSSResource("core.css");
AddResourcesListener.addThemedCSSResource("alerts.css");
AddResourcesListener.addThemedCSSResource("tooltip.css");

setRendererType(DEFAULT_RENDERER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void encodeBegin(FacesContext context, UIComponent component) throws IOEx

rw.startElement("div", alert);
rw.writeAttribute("id", clientId, "id");
Tooltip.generateTooltip(context, attrs, rw);
Tooltip.generateTooltip(context, component, rw);

String style = alert.getStyle();
if (null != style)
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/bootsfaces/component/badge/Badge.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class Badge extends UIOutput {
public Badge() {
AddResourcesListener.addThemedCSSResource("core.css");
AddResourcesListener.addThemedCSSResource("badges.css");
AddResourcesListener.addThemedCSSResource("tooltip.css");
setRendererType(DEFAULT_RENDERER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ protected void generateBadge(FacesContext context, UIComponent component, Respon
styleClass = "badge";
else
styleClass += " badge";
Tooltip.generateTooltip(context, component.getAttributes(), rw);
Tooltip.generateTooltip(context, component, rw);
rw.writeAttribute("class", styleClass, "class");
if (null != style)
rw.writeAttribute("style", style, "style");
if (val!=null) {
rw.writeText(val, null);
}
rw.endElement("span");
Tooltip.activateTooltips(context, component.getAttributes(), component);
Tooltip.activateTooltips(context, component);
}


Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/bootsfaces/component/button/Button.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public Button() {
setRendererType(DEFAULT_RENDERER);

AddResourcesListener.addThemedCSSResource("core.css");
AddResourcesListener.addThemedCSSResource("tooltip.css");
Tooltip.addResourceFile();
Tooltip.addResourceFiles();
}

public String getFamily() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void encodeHTML(FacesContext context, Button button)
rw.writeAttribute("id", clientId, "id");
rw.writeAttribute("name", clientId, "name");
rw.writeAttribute("type", "button", null);
if(BsfUtils.StringIsValued(button.getDir())) {
if(BsfUtils.isStringValued(button.getDir())) {
rw.writeAttribute("dir", button.getDir(), "dir");
}
if (style != null) {
Expand All @@ -98,7 +98,7 @@ public void encodeHTML(FacesContext context, Button button)
if (null != clickHandler && clickHandler.length() > 0) {
rw.writeAttribute("onclick", clickHandler, null);
}
if (BsfUtils.StringIsValued(button.getDismiss())) {
if (BsfUtils.isStringValued(button.getDismiss())) {
rw.writeAttribute("data-dismiss", button.getDismiss(), null);
}
if (button.isDisabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class ButtonGroup extends UIComponentBase implements net.bootsfaces.rende

public ButtonGroup() {
AddResourcesListener.addThemedCSSResource("core.css");
AddResourcesListener.addThemedCSSResource("tooltip.css");
Tooltip.addResourceFile();
Tooltip.addResourceFiles();
setRendererType(DEFAULT_RENDERER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ public class ButtonToolbar extends UIComponentBase implements net.bootsfaces.ren
public static final String DEFAULT_RENDERER = "net.bootsfaces.component.buttonToolbar.ButtonToolbar";

public ButtonToolbar() {
Tooltip.addResourceFile();
Tooltip.addResourceFiles();
AddResourcesListener.addThemedCSSResource("core.css");
AddResourcesListener.addThemedCSSResource("tooltip.css");
setRendererType(DEFAULT_RENDERER);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/bootsfaces/component/canvas/Canvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Canvas extends UIOutput implements net.bootsfaces.render.IHasToolti
public static final String DEFAULT_RENDERER = "net.bootsfaces.component.canvas.Canvas";

public Canvas() {
Tooltip.addResourceFile();
Tooltip.addResourceFiles();
setRendererType(DEFAULT_RENDERER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,10 @@ public class Carousel extends UICommand
public static final String DEFAULT_RENDERER = "net.bootsfaces.component.carousel.Carousel";

public Carousel() {
Tooltip.addResourceFile();
// AddResourcesListener.addBasicJSResource("javax.faces", "jsf.js");
// AddResourcesListener.addBasicJSResource("bsf", "js/bsf.js");
Tooltip.addResourceFiles();
AddResourcesListener.addThemedCSSResource("bsf.css");
AddResourcesListener.addThemedCSSResource("carousel.css");
AddResourcesListener.addThemedCSSResource("core.css");
AddResourcesListener.addThemedCSSResource("tooltip.css");
// AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY,
// "jq/jquery.js");
AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY, "jq/ui/core.js");
setRendererType(DEFAULT_RENDERER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class CarouselCaption extends UICommand
public static final String DEFAULT_RENDERER = "net.bootsfaces.component.carouselCaption.CarouselCaption";

public CarouselCaption() {
Tooltip.addResourceFile();
Tooltip.addResourceFiles();
setRendererType(DEFAULT_RENDERER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import net.bootsfaces.component.ajax.AJAXRenderer;
import net.bootsfaces.render.CoreRenderer;
import net.bootsfaces.render.IHasTooltip;
import net.bootsfaces.render.Tooltip;

/** This class generates the HTML code of <b:carouselCaption />. */
Expand All @@ -49,10 +48,7 @@ public class CarouselCaptionRenderer extends CoreRenderer {
*/
@Override
public void decode(FacesContext context, UIComponent component) {
CarouselCaption carouselCaption = (CarouselCaption) component;

new AJAXRenderer().decode(context, component);

}

/**
Expand Down Expand Up @@ -122,7 +118,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
ResponseWriter rw = context.getResponseWriter();
rw.endElement("div");
if (component instanceof CarouselCaption) {
Tooltip.activateTooltips(context, (IHasTooltip) component);
Tooltip.activateTooltips(context, component);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class CarouselControl extends UICommand
public static final String DEFAULT_RENDERER = "net.bootsfaces.component.carouselControl.CarouselControl";

public CarouselControl() {
Tooltip.addResourceFile();
Tooltip.addResourceFiles();
setRendererType(DEFAULT_RENDERER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class CarouselItem extends UICommand
public static final String DEFAULT_RENDERER = "net.bootsfaces.component.carouselItem.CarouselItem";

public CarouselItem() {
Tooltip.addResourceFile();
Tooltip.addResourceFiles();
setRendererType(DEFAULT_RENDERER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,10 @@ public class ColorPicker extends HtmlInputText implements IHasTooltip, IAJAXComp

public ColorPicker() {
setRendererType("net.bootsfaces.component.colorPicker.ColorPicker");
Tooltip.addResourceFile();
// AddResourcesListener.addBasicJSResource("javax.faces", "jsf.js");
// AddResourcesListener.addBasicJSResource("bsf", "js/bsf.js");
Tooltip.addResourceFiles();
AddResourcesListener.addThemedCSSResource("bsf.css");
AddResourcesListener.addThemedCSSResource("jquery.minicolors.css");
AddResourcesListener.addThemedCSSResource("core.css");
AddResourcesListener.addThemedCSSResource("tooltip.css");
// AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY,
// "jq/jquery.js");
AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY, "js/jquery.minicolors.min.js");

renderLabel = FacesContext.getCurrentInstance().getExternalContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
// build color picker init script
rw.startElement("script", colorPicker);
rw.writeText("$(function() {" +
"$('#input_" + BsfUtils.EscapeJQuerySpecialCharsInSelector(clientId) + "').minicolors({" +
"$('#input_" + BsfUtils.escapeJQuerySpecialCharsInSelector(clientId) + "').minicolors({" +
(colorPicker.getAttributes().get("control") != null ? " control: '" + colorPicker.getAttributes().get("control") + "'," : "") +
(colorPicker.getAttributes().get("format") != null ? " format: '" + colorPicker.getAttributes().get("format") + "'," : "") +
(colorPicker.getAttributes().get("opacity") != null ? " opacity: " + colorPicker.getAttributes().get("opacity") + "," : "") +
Expand All @@ -224,7 +224,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
" theme: 'bootstrap' " +
"});" +
"});", null);
rw.writeText("document.getElementById('input_" + BsfUtils.EscapeJQuerySpecialCharsInSelector(clientId) + "').addEventListener('touchmove', function(event) {\r\n"+
rw.writeText("document.getElementById('input_" + BsfUtils.escapeJQuerySpecialCharsInSelector(clientId) + "').addEventListener('touchmove', function(event) {\r\n"+
"event.preventDefault();\r\n"+
"}, false);", null);
rw.endElement("script");
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/bootsfaces/component/column/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ public class Column extends UIOutput implements net.bootsfaces.render.IHasToolti
public static final String DEFAULT_RENDERER = "net.bootsfaces.component.column.Column";

public Column() {
Tooltip.addResourceFile();
Tooltip.addResourceFiles();
AddResourcesListener.addThemedCSSResource("core.css");
AddResourcesListener.addThemedCSSResource("tooltip.css");
setRendererType(DEFAULT_RENDERER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,8 @@ public class CommandButton extends UICommand implements ClientBehaviorHolder, IH

public CommandButton() {
setRendererType(DEFAULT_RENDERER); // this component renders itself
// AddResourcesListener.addBasicJSResource("javax.faces", "jsf.js");
// AddResourcesListener.addBasicJSResource("bsf", "js/bsf.js");
AddResourcesListener.addThemedCSSResource("core.css");
AddResourcesListener.addThemedCSSResource("tooltip.css");
// AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY,
// "jq/jquery.js");
Tooltip.addResourceFile();
Tooltip.addResourceFiles();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce

rw.endElement("button");

Tooltip.activateTooltips(context, attrs, component);
Tooltip.activateTooltips(context, component);
}

private String getStyleClasses(CommandButton component) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ public class Container extends UIOutput implements net.bootsfaces.render.IHasToo
public static final String DEFAULT_RENDERER = "net.bootsfaces.component.container.Container";

public Container() {
Tooltip.addResourceFile();
// AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY,
// "jq/jquery.js");
Tooltip.addResourceFiles();
AddResourcesListener.addThemedCSSResource("core.css");
AddResourcesListener.addThemedCSSResource("tooltip.css");
setRendererType(DEFAULT_RENDERER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ public enum DataTablePropertyType {
}

public DataTable() {
Tooltip.addResourceFile();
setRendererType(DEFAULT_RENDERER);
Tooltip.addResourceFiles();
AddResourcesListener.addThemedCSSResource("core.css");
AddResourcesListener.addThemedCSSResource("bsf.css");
AddResourcesListener.addThemedCSSResource("tooltip.css");
}

public void setValueExpression(String name, ValueExpression binding) {
Expand Down Expand Up @@ -524,6 +523,7 @@ public void setUpdate(String _update) {
* Activates Multi-column search inputs. The default value is false (no multi-column searching). A java.util.Map&lt;net.bootsfaces.component.dataTable.DataTable.DataTablePropertyType, Object&gt; map on the backing bean where the state of the DataTable can be saved, and retrieved after re-rendering. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
@SuppressWarnings("unchecked")
public Map<DataTablePropertyType, Object> getDataTableProperties() {
return (Map<DataTablePropertyType, Object>)getStateHelper().eval(PropertyKeys.dataTableProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
" pageLength: " + pageLength + ", " +
" lengthMenu: " + dataTable.getPageLengthMenu() + ", " +
" order: " + orderString + ", " +
(BsfUtils.StringIsValued(lang) ? " language: { url: '" + lang + "' } " : "") +
(BsfUtils.isStringValued(lang) ? " language: { url: '" + lang + "' } " : "") +
"});" +
// "var table = " + widgetVar +".DataTable({fixedHeader: true, responsive: true});" +
"var workInProgressErrorMessage = 'Multiple DataTables on the same page are not yet supported when using " +
Expand Down Expand Up @@ -382,9 +382,9 @@ private String determineLanguage(FacesContext fc, DataTable dataTable) {
final Set<String> availableLanguages = new HashSet<String>(Arrays.asList(
new String[] {"de", "en", "es", "fr", "hu", "it", "pl", "ru"}
));
if(BsfUtils.StringIsValued(dataTable.getCustomLangUrl())) {
if(BsfUtils.isStringValued(dataTable.getCustomLangUrl())) {
return dataTable.getCustomLangUrl();
} else if(BsfUtils.StringIsValued(dataTable.getLang())) {
} else if(BsfUtils.isStringValued(dataTable.getLang())) {
String lang = dataTable.getLang();
if(availableLanguages.contains(lang)) return determineLanguageUrl(fc, lang);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public DatePicker() {
AddResourcesListener.addThemedCSSResource("jq.ui.theme.css");
AddResourcesListener.addThemedCSSResource("jq.ui.datepicker.css");
AddResourcesListener.addThemedCSSResource("bsf.css");
AddResourcesListener.addThemedCSSResource("tooltip.css");

AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY, "jq/ui/core.js");
AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY, "jq/ui/datepicker.js");
Expand All @@ -117,7 +116,7 @@ public DatePicker() {
}

}
Tooltip.addResourceFile();
Tooltip.addResourceFiles();
}

public void setValueExpression(String name, ValueExpression binding) {
Expand Down Expand Up @@ -189,7 +188,7 @@ public void encodeBegin(FacesContext fc) throws IOException {

encodeHTML(fc);
encodeDefaultLanguageJS(fc);
Tooltip.activateTooltips(fc, getAttributes(), this);
Tooltip.activateTooltips(fc, this);
}

/**
Expand Down Expand Up @@ -258,7 +257,7 @@ private void encodeHTML(FacesContext fc) throws IOException {
if (mode.equals("icon-popup") || mode.equals("icon-toggle")) {
rw.startElement("span", this);
rw.writeAttribute("id", clientId + "_" + ADDON, "id");
rw.writeAttribute("class", "input-group-addon", "class");
rw.writeAttribute("class", ADDON, "class");
IconRenderer.encodeIcon(rw, this, "calendar", false, null, null, null, false, null, null,
isDisabled, true, true, true);
rw.endElement("span");
Expand All @@ -270,7 +269,7 @@ private void encodeHTML(FacesContext fc) throws IOException {
rw.startElement("input", null);
rw.writeAttribute("id", clientId, null);
rw.writeAttribute("name", clientId, null);
Tooltip.generateTooltip(fc, attrs, rw);
Tooltip.generateTooltip(fc, this, rw);
rw.writeAttribute("type", type, null);
String styleClass = new CoreRenderer().getErrorAndRequiredClass(this, clientId);
rw.writeAttribute("class", "form-control " + styleClass, "class");
Expand All @@ -295,7 +294,7 @@ private void encodeHTML(FacesContext fc) throws IOException {
if (mode.equals("popup-icon") || mode.equals("toggle-icon")) {
rw.startElement("span", this);
rw.writeAttribute("id", clientId + "_" + ADDON, "id");
rw.writeAttribute("class", "input-group-addon", "class");
rw.writeAttribute("class", ADDON, "class");

IconRenderer.encodeIcon(rw, this, "calendar", false, null, null, null, false, null, null, isDisabled, true,
true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ public void encodeEnd(FacesContext context) throws IOException {
if (form == null) {
throw new FacesException("The default command component must be inside a form", null);
} else {
String target = (String) attrs.get("target");
if (BsfUtils.StringIsValued(target)) {
String target = (String)attrs.get("target");
if(BsfUtils.isStringValued(target)) {
ResponseWriter rw = context.getResponseWriter();
String formId = form.getClientId();
String actionCommandId = BsfUtils.getComponentClientId(target);

rw.startElement("script", this);

rw.writeText("" + "$(function() { " + " $('form#"
+ BsfUtils.EscapeJQuerySpecialCharsInSelector(formId) + " :input').keypress(function (e) { "
+ BsfUtils.escapeJQuerySpecialCharsInSelector(formId) + " :input').keypress(function (e) { "
+ " if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { "
+ " document.getElementById('" + actionCommandId + "').click();return false; "
+ " } else { " + " console.log('keycode not 13'); " + " return true; "
Expand Down
Loading

0 comments on commit 3427ac7

Please sign in to comment.