package com.marcozanon.macaco.web.ui;
-import com.marcozanon.macaco.filtering.MConstraintFilteringException;
-import com.marcozanon.macaco.filtering.MDateFilter;
-import com.marcozanon.macaco.filtering.MFormatFilteringException;
+import com.marcozanon.macaco.conversion.MDateConverter;
+import com.marcozanon.macaco.conversion.MFormatConversionException;
public class MWebDateBox extends MWebTextBox {
- protected MDateFilter dateFilter = null;
+ protected MDateConverter dateConverter = null;
/* */
- public MWebDateBox(MWebApplicationContext applicationContext, MDateFilter dateFilter) {
+ public MWebDateBox(MWebApplicationContext applicationContext, MDateConverter dateConverter) {
super(applicationContext);
//
- if (null == dateFilter) {
- throw new IllegalArgumentException("Invalid 'dateFilter': null.");
+ if (null == dateConverter) {
+ throw new IllegalArgumentException("Invalid 'dateConverter': null.");
}
//
- this.dateFilter = dateFilter;
+ this.dateConverter = dateConverter;
}
- public MWebDateBox(MWebApplicationContext applicationContext, MDateFilter dateFilter, String text) {
- this(applicationContext, dateFilter);
+ public MWebDateBox(MWebApplicationContext applicationContext, MDateConverter dateConverter, String text) {
+ this(applicationContext, dateConverter);
//
this.setText(text);
}
- /* Date filter */
+ /* Date converter */
- protected MDateFilter getDateFilterReference() {
- return this.dateFilter;
+ protected MDateConverter getDateConverterReference() {
+ return this.dateConverter;
}
- public MDateFilter getDateFilter() {
- return this.getDateFilterReference().clone();
+ public MDateConverter getDateConverter() {
+ return this.getDateConverterReference().clone();
}
/* Validation */
public void validate() throws MValidationWebException {
String text = this.getText();
- try {
- this.setText(this.getDateFilterReference().getValidatedUserDate(text, null));
- }
- catch (MConstraintFilteringException exception) {
- throw new MValidationWebException(String.format("Invalid date: %s.", text), exception);
- }
- catch (MFormatFilteringException exception) {
- throw new MValidationWebException(String.format("Invalid date: %s.", text), exception);
+ if (!"".equals(text)) {
+ try {
+ MDateConverter dateConverter = this.getDateConverterReference();
+ this.setText(dateConverter.getStringFromDate(dateConverter.getDateFromString(text)));
+ }
+ catch (MFormatConversionException exception) {
+ throw new MValidationWebException(String.format("Invalid date: %s.", text), exception);
+ }
}
}
+++ /dev/null
-/**
- * Macaco
- * Copyright (c) 2009-2012 Marco Zanon <info@marcozanon.com>.
- * Released under MIT license (see LICENSE for details).
- */
-
-package com.marcozanon.macaco.web.ui;
-
-import com.marcozanon.macaco.filtering.MConstraintFilteringException;
-import com.marcozanon.macaco.filtering.MDatetimeFilter;
-import com.marcozanon.macaco.filtering.MFormatFilteringException;
-
-public class MWebDatetimeBox extends MWebTextBox {
-
- protected MDatetimeFilter datetimeFilter = null;
-
- /* */
-
- public MWebDatetimeBox(MWebApplicationContext applicationContext, MDatetimeFilter datetimeFilter) {
- super(applicationContext);
- //
- if (null == datetimeFilter) {
- throw new IllegalArgumentException("Invalid 'datetimeFilter': null.");
- }
- //
- this.datetimeFilter = datetimeFilter;
- }
-
- public MWebDatetimeBox(MWebApplicationContext applicationContext, MDatetimeFilter datetimeFilter, String text) {
- this(applicationContext, datetimeFilter);
- //
- this.setText(text);
- }
-
- /* Datetime filter */
-
- protected MDatetimeFilter getDatetimeFilterReference() {
- return this.datetimeFilter;
- }
-
- public MDatetimeFilter getDatetimeFilter() {
- return this.getDatetimeFilterReference().clone();
- }
-
- /* Validation */
-
- public void validate() throws MValidationWebException {
- String text = this.getText();
- try {
- this.setText(this.getDatetimeFilterReference().getValidatedUserDatetime(text, null));
- }
- catch (MConstraintFilteringException exception) {
- throw new MValidationWebException(String.format("Invalid datetime: %s.", text), exception);
- }
- catch (MFormatFilteringException exception) {
- throw new MValidationWebException(String.format("Invalid datetime: %s.", text), exception);
- }
- }
-
- /* Refresh */
-
- protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
- this.checkPresence();
- //
- String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
- if (null == customClasses) {
- customClasses = "";
- }
- String onBlurFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onBlur', {'text': this.value});", this.getId());
- this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<input type=\"text\" class=\"MWebDatetimeBox %s\" style=\"display: inline-block;\" onblur=\"%s\" id=\"%s\" />'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), this.getId()));
- //
- super.refresh();
- //
- this.refreshText();
- this.refreshTextAlignment(true);
- this.refreshEnabledMode();
- }
-
-}
package com.marcozanon.macaco.web.ui;
-import com.marcozanon.macaco.filtering.MConstraintFilteringException;
-import com.marcozanon.macaco.filtering.MFormatFilteringException;
-import com.marcozanon.macaco.filtering.MNumberFilter;
+import com.marcozanon.macaco.conversion.MFormatConversionException;
+import com.marcozanon.macaco.conversion.MNumberConverter;
public class MWebNumberBox extends MWebTextBox {
- protected MNumberFilter numberFilter = null;
+ protected MNumberConverter numberConverter = null;
/* */
- public MWebNumberBox(MWebApplicationContext applicationContext, MNumberFilter numberFilter) {
+ public MWebNumberBox(MWebApplicationContext applicationContext, MNumberConverter numberConverter) {
super(applicationContext);
//
- if (null == numberFilter) {
- throw new IllegalArgumentException("Invalid 'numberFilter': null.");
+ if (null == numberConverter) {
+ throw new IllegalArgumentException("Invalid 'numberConverter': null.");
}
//
- this.numberFilter = numberFilter;
+ this.numberConverter = numberConverter;
}
- public MWebNumberBox(MWebApplicationContext applicationContext, MNumberFilter numberFilter, String text) {
- this(applicationContext, numberFilter);
+ public MWebNumberBox(MWebApplicationContext applicationContext, MNumberConverter numberConverter, String text) {
+ this(applicationContext, numberConverter);
//
this.setText(text);
}
- /* Number filter */
+ /* Number converter */
- protected MNumberFilter getNumberFilterReference() {
- return this.numberFilter;
+ protected MNumberConverter getNumberConverterReference() {
+ return this.numberConverter;
}
- public MNumberFilter getNumberFilter() {
- return this.getNumberFilterReference().clone();
+ public MNumberConverter getNumberConverter() {
+ return this.getNumberConverterReference().clone();
}
/* Validation */
public void validate() throws MValidationWebException {
String text = this.getText();
- try {
- this.setText(this.getNumberFilterReference().getValidatedUserNumber(text, null));
- }
- catch (MConstraintFilteringException exception) {
- throw new MValidationWebException(String.format("Invalid number: %s.", text), exception);
- }
- catch (MFormatFilteringException exception) {
- throw new MValidationWebException(String.format("Invalid number: %s.", text), exception);
+ if (!"".equals(text)) {
+ try {
+ MNumberConverter numberConverter = this.getNumberConverterReference();
+ this.setText(numberConverter.getStringFromNumber(numberConverter.getNumberFromString(text)));
+ }
+ catch (MFormatConversionException exception) {
+ throw new MValidationWebException(String.format("Invalid number: %s.", text), exception);
+ }
}
}
+++ /dev/null
-/**
- * Macaco
- * Copyright (c) 2009-2012 Marco Zanon <info@marcozanon.com>.
- * Released under MIT license (see LICENSE for details).
- */
-
-package com.marcozanon.macaco.web.ui;
-
-import com.marcozanon.macaco.filtering.MConstraintFilteringException;
-import com.marcozanon.macaco.filtering.MFormatFilteringException;
-import com.marcozanon.macaco.filtering.MTimeFilter;
-
-public class MWebTimeBox extends MWebTextBox {
-
- protected MTimeFilter timeFilter = null;
-
- /* */
-
- public MWebTimeBox(MWebApplicationContext applicationContext, MTimeFilter timeFilter) {
- super(applicationContext);
- //
- if (null == timeFilter) {
- throw new IllegalArgumentException("Invalid 'timeFilter': null.");
- }
- //
- this.timeFilter = timeFilter;
- }
-
- public MWebTimeBox(MWebApplicationContext applicationContext, MTimeFilter timeFilter, String text) {
- this(applicationContext, timeFilter);
- //
- this.setText(text);
- }
-
- /* Time filter */
-
- protected MTimeFilter getTimeFilterReference() {
- return this.timeFilter;
- }
-
- public MTimeFilter getTimeFilter() {
- return this.getTimeFilterReference().clone();
- }
-
- /* Validation */
-
- public void validate() throws MValidationWebException {
- String text = this.getText();
- try {
- this.setText(this.getTimeFilterReference().getValidatedUserTime(text, null));
- }
- catch (MConstraintFilteringException exception) {
- throw new MValidationWebException(String.format("Invalid time: %s.", text), exception);
- }
- catch (MFormatFilteringException exception) {
- throw new MValidationWebException(String.format("Invalid time: %s.", text), exception);
- }
- }
-
- /* Refresh */
-
- protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
- this.checkPresence();
- //
- String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
- if (null == customClasses) {
- customClasses = "";
- }
- String onBlurFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onBlur', {'text': this.value});", this.getId());
- this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<input type=\"text\" class=\"MWebTimeBox %s\" style=\"display: inline-block;\" onblur=\"%s\" id=\"%s\" />'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), this.getId()));
- //
- super.refresh();
- //
- this.refreshText();
- this.refreshTextAlignment(true);
- this.refreshEnabledMode();
- }
-
-}