From 1db823f6cb23956c709f839acebb423a980d9625 Mon Sep 17 00:00:00 2001 From: Marco Zanon Date: Sun, 11 Mar 2012 11:44:25 +0000 Subject: [PATCH] Switched MWebDateBox and MWebNumberBox from filters to converters, and removed useless MWebDatetimeBox and MWebTimeBox. --- .../marcozanon/macaco/web/ui/MWebDateBox.java | 45 ++++++----- .../macaco/web/ui/MWebDatetimeBox.java | 79 ------------------- .../macaco/web/ui/MWebNumberBox.java | 45 ++++++----- .../marcozanon/macaco/web/ui/MWebTimeBox.java | 79 ------------------- 4 files changed, 44 insertions(+), 204 deletions(-) delete mode 100644 src/java/com/marcozanon/macaco/web/ui/MWebDatetimeBox.java delete mode 100644 src/java/com/marcozanon/macaco/web/ui/MWebTimeBox.java diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java index d9c49a3..8031434 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java @@ -6,54 +6,53 @@ 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); + } } } diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebDatetimeBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebDatetimeBox.java deleted file mode 100644 index 2e2c244..0000000 --- a/src/java/com/marcozanon/macaco/web/ui/MWebDatetimeBox.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Macaco - * Copyright (c) 2009-2012 Marco Zanon . - * 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 = ''; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), this.getId())); - // - super.refresh(); - // - this.refreshText(); - this.refreshTextAlignment(true); - this.refreshEnabledMode(); - } - -} diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java index c986ad0..55062e9 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java @@ -6,54 +6,53 @@ 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); + } } } diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebTimeBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebTimeBox.java deleted file mode 100644 index 77eae1d..0000000 --- a/src/java/com/marcozanon/macaco/web/ui/MWebTimeBox.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Macaco - * Copyright (c) 2009-2012 Marco Zanon . - * 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 = ''; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), this.getId())); - // - super.refresh(); - // - this.refreshText(); - this.refreshTextAlignment(true); - this.refreshEnabledMode(); - } - -} -- 2.30.2