Refactor HawkbitNotificationMessage

Signed-off-by: Melanie Retter <melanie.retter@bosch-si.com>
This commit is contained in:
Melanie Retter
2016-08-01 10:13:45 +02:00
parent 27019b9e4c
commit 26c376e22e
3 changed files with 11 additions and 34 deletions

View File

@@ -16,7 +16,7 @@ import com.vaadin.ui.Notification;
/** /**
* Notification message component. * Notification message component.
*/ */
public class HawkbitNotificationMessage extends Notification { public class HawkbitErrorNotificationMessage extends Notification {
/** /**
* ID. * ID.
@@ -26,34 +26,18 @@ public class HawkbitNotificationMessage extends Notification {
/** /**
* Constructor. * Constructor.
*/ */
public HawkbitNotificationMessage() { public HawkbitErrorNotificationMessage(final String style, final String caption, final String description,
super(""); final boolean autoClose) {
} super(caption);
setStyleName(style);
/**
* Decorate.
*
* @param styleName
* style name of message
* @param caption
* message caption
* @param description
* message description
* @param autoClose
* flag to indicate enable close option
*/
public void decorateWith(final String styleName, final String caption, final String description,
final Boolean autoClose) {
setCaption(caption);
setDescription(description);
setStyleName(styleName);
setHtmlContentAllowed(true);
setPosition(Position.BOTTOM_RIGHT);
if (autoClose) { if (autoClose) {
setDelayMsec(SPUILabelDefinitions.SP_DELAY); setDelayMsec(SPUILabelDefinitions.SP_DELAY);
} else { } else {
setDelayMsec(-1); setDelayMsec(-1);
} }
setHtmlContentAllowed(true);
setPosition(Position.BOTTOM_RIGHT);
setDescription(description);
} }
} }

View File

@@ -41,7 +41,7 @@ public class HawkbitUIErrorHandler extends DefaultErrorHandler {
final Optional<Page> originError = getPageOriginError(event); final Optional<Page> originError = getPageOriginError(event);
if (originError.isPresent()) { if (originError.isPresent()) {
final HawkbitNotificationMessage message = buildNotification(getRootExceptionFrom(event)); final HawkbitErrorNotificationMessage message = buildNotification(getRootExceptionFrom(event));
message.show(originError.get()); message.show(originError.get());
} }
} }
@@ -71,14 +71,11 @@ public class HawkbitUIErrorHandler extends DefaultErrorHandler {
return Optional.absent(); return Optional.absent();
} }
protected HawkbitNotificationMessage buildNotification(final Throwable exception) { protected HawkbitErrorNotificationMessage buildNotification(final Throwable exception) {
final HawkbitNotificationMessage notification = new HawkbitNotificationMessage();
final I18N i18n = SpringContextHelper.getBean(I18N.class); final I18N i18n = SpringContextHelper.getBean(I18N.class);
notification.decorateWith(STYLE, i18n.get("caption.error"), return new HawkbitErrorNotificationMessage(STYLE, i18n.get("caption.error"),
i18n.get("message.error.temp", exception.getClass().getSimpleName()), false); i18n.get("message.error.temp", exception.getClass().getSimpleName()), false);
return notification;
} }
} }

View File

@@ -16,8 +16,6 @@ import com.vaadin.ui.Notification;
/** /**
* Show notification messages. * Show notification messages.
*
*
*/ */
@UIScope @UIScope
@SpringComponent @SpringComponent
@@ -27,8 +25,6 @@ public class NotificationMessage extends Notification {
/** /**
* Default constructor of notification message. * Default constructor of notification message.
*
* @param caption
*/ */
public NotificationMessage() { public NotificationMessage() {
super(""); super("");