Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Refactor notification presenter and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Sep 26, 2012
1 parent 99084af commit 0a2db05
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 191 deletions.
Expand Up @@ -29,11 +29,6 @@

import org.zanata.webtrans.client.Application;
import org.zanata.webtrans.client.EventProcessor;
import org.zanata.webtrans.client.presenter.TransFilterPresenter;
import org.zanata.webtrans.client.resources.ValidationMessages;
import org.zanata.webtrans.client.view.SideMenuDisplay;
import org.zanata.webtrans.client.view.SourceContentsDisplay;
import org.zanata.webtrans.client.view.SourceContentsView;
import org.zanata.webtrans.client.events.NativeEvent;
import org.zanata.webtrans.client.events.NativeEventImpl;
import org.zanata.webtrans.client.history.History;
Expand All @@ -53,6 +48,7 @@
import org.zanata.webtrans.client.presenter.SearchResultsPresenter;
import org.zanata.webtrans.client.presenter.SideMenuPresenter;
import org.zanata.webtrans.client.presenter.SourceContentsPresenter;
import org.zanata.webtrans.client.presenter.TransFilterPresenter;
import org.zanata.webtrans.client.presenter.TransMemoryDetailsPresenter;
import org.zanata.webtrans.client.presenter.TransMemoryMergePresenter;
import org.zanata.webtrans.client.presenter.TransMemoryPresenter;
Expand All @@ -63,6 +59,7 @@
import org.zanata.webtrans.client.presenter.ValidationOptionsPresenter;
import org.zanata.webtrans.client.presenter.WorkspaceUsersPresenter;
import org.zanata.webtrans.client.resources.Resources;
import org.zanata.webtrans.client.resources.ValidationMessages;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.rpc.DelegatingDispatchAsync;
Expand All @@ -80,9 +77,13 @@
import org.zanata.webtrans.client.view.GlossaryDisplay;
import org.zanata.webtrans.client.view.GlossaryView;
import org.zanata.webtrans.client.view.KeyShortcutView;
import org.zanata.webtrans.client.view.NotificationDisplay;
import org.zanata.webtrans.client.view.NotificationView;
import org.zanata.webtrans.client.view.SearchResultsView;
import org.zanata.webtrans.client.view.SideMenuDisplay;
import org.zanata.webtrans.client.view.SideMenuView;
import org.zanata.webtrans.client.view.SourceContentsDisplay;
import org.zanata.webtrans.client.view.SourceContentsView;
import org.zanata.webtrans.client.view.TargetContentsDisplay;
import org.zanata.webtrans.client.view.TargetContentsView;
import org.zanata.webtrans.client.view.TransFilterDisplay;
Expand Down Expand Up @@ -145,7 +146,7 @@ protected void configure()
bindPresenter(EditorOptionsPresenter.class, EditorOptionsDisplay.class, EditorOptionsView.class);
bindPresenter(TranslationEditorPresenter.class, TranslationEditorPresenter.Display.class, TranslationEditorView.class);
bindPresenter(ValidationOptionsPresenter.class, ValidationOptionsPresenter.Display.class, ValidationOptionsView.class);
bindPresenter(NotificationPresenter.class, NotificationPresenter.Display.class, NotificationView.class);
bindPresenter(NotificationPresenter.class, NotificationDisplay.class, NotificationView.class);
bindPresenter(TransUnitsTablePresenter.class, TransUnitsTableDisplay.class, TransUnitsTableView.class);
bindPresenter(SideMenuPresenter.class, SideMenuDisplay.class, SideMenuView.class);

Expand Down
Expand Up @@ -2,7 +2,7 @@

import org.zanata.webtrans.client.events.NotificationEvent.Severity;

public interface HasNotificationLabel
public interface NotificationLabelListener
{
void setNotificationLabel(int count, Severity severity);

Expand Down
Expand Up @@ -21,48 +21,30 @@
package org.zanata.webtrans.client.presenter;

import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.widget.WidgetDisplay;
import net.customware.gwt.presenter.client.widget.WidgetPresenter;

import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.events.NotificationEvent.Severity;
import org.zanata.webtrans.client.events.NotificationEventHandler;
import org.zanata.webtrans.client.ui.InlineLink;
import org.zanata.webtrans.client.view.NotificationDisplay;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.inject.Inject;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*
*/
public class NotificationPresenter extends WidgetPresenter<NotificationPresenter.Display>
public class NotificationPresenter extends WidgetPresenter<NotificationDisplay> implements NotificationEventHandler, NotificationDisplay.Listener
{
@Inject
public NotificationPresenter(Display display, EventBus eventBus)
public NotificationPresenter(NotificationDisplay display, EventBus eventBus)
{
super(display, eventBus);
}

public interface Display extends WidgetDisplay
{
HasClickHandlers getClearButton();

void clearMessages();

void appendMessage(Severity severity, String message, InlineLink inlineLink);

void setMessagesToKeep(int count);

int getMessageCount();

void setMessageOrder(DisplayOrder displayOrder);
}

private HasNotificationLabel listener;
private NotificationLabelListener listener;

/**
* Message count to keep in notification area
Expand All @@ -83,30 +65,19 @@ protected void onBind()
{
display.setMessagesToKeep(MESSAGE_TO_KEEP);
display.setMessageOrder(DisplayOrder.ASCENDING);
display.setListener(this);

registerHandler(display.getClearButton().addClickHandler(new ClickHandler()
{
@Override
public void onClick(ClickEvent event)
{
display.clearMessages();
listener.setNotificationLabel(display.getMessageCount(), Severity.Info);
}
}));

registerHandler(eventBus.addHandler(NotificationEvent.getType(), new NotificationEventHandler()
{
@Override
public void onNotification(NotificationEvent event)
{
appendNotification(event.getSeverity(), event.getMessage(), event.getInlineLink());
Log.info("Notification:" + event.getMessage());
listener.setNotificationLabel(display.getMessageCount(), event.getSeverity());
}
}));
registerHandler(eventBus.addHandler(NotificationEvent.getType(), this));
}

@Override
public void onClearClick()
{
display.clearMessages();
listener.setNotificationLabel(display.getMessageCount(), Severity.Info);
}

public void setNotificationListener(HasNotificationLabel listener)
public void setNotificationListener(NotificationLabelListener listener)
{
this.listener = listener;
listener.setNotificationLabel(0, Severity.Info);
Expand All @@ -133,4 +104,12 @@ protected void onRevealDisplay()
{
// TODO Auto-generated method stub
}

@Override
public void onNotification(NotificationEvent event)
{
appendNotification(event.getSeverity(), event.getMessage(), event.getInlineLink());
Log.info("Notification:" + event.getMessage());
listener.setNotificationLabel(display.getMessageCount(), event.getSeverity());
}
}
Expand Up @@ -50,7 +50,7 @@
* @author aeng
*
*/
public class SideMenuPresenter extends WidgetPresenter<SideMenuDisplay> implements HasNotificationLabel,
public class SideMenuPresenter extends WidgetPresenter<SideMenuDisplay> implements NotificationLabelListener,
SideMenuDisplay.Listener, ExitWorkspaceEventHandler, EnterWorkspaceEventHandler, PublishWorkspaceChatEventHandler
{
private final EditorOptionsPresenter editorOptionsPresenter;
Expand Down
@@ -0,0 +1,52 @@
/*
* Copyright 2012, Red Hat, Inc. and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.zanata.webtrans.client.view;

import net.customware.gwt.presenter.client.widget.WidgetDisplay;

import org.zanata.webtrans.client.events.NotificationEvent.Severity;
import org.zanata.webtrans.client.presenter.NotificationPresenter.DisplayOrder;
import org.zanata.webtrans.client.ui.InlineLink;

/**
*
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*
*/
public interface NotificationDisplay extends WidgetDisplay
{
void clearMessages();

void appendMessage(Severity severity, String message, InlineLink inlineLink);

void setMessagesToKeep(int count);

int getMessageCount();

void setMessageOrder(DisplayOrder displayOrder);

void setListener(Listener listener);

interface Listener
{
void onClearClick();
}
}
Expand Up @@ -23,18 +23,18 @@
import java.util.Date;

import org.zanata.webtrans.client.events.NotificationEvent.Severity;
import org.zanata.webtrans.client.presenter.NotificationPresenter;
import org.zanata.webtrans.client.presenter.NotificationPresenter.DisplayOrder;
import org.zanata.webtrans.client.resources.Resources;
import org.zanata.webtrans.client.ui.InlineLink;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
Expand All @@ -52,7 +52,7 @@
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*
**/
public class NotificationView extends Composite implements NotificationPresenter.Display
public class NotificationView extends Composite implements NotificationDisplay
{

private static NotificationPanelUiBinder uiBinder = GWT.create(NotificationPanelUiBinder.class);
Expand Down Expand Up @@ -104,6 +104,7 @@ interface Styles extends CssResource
ScrollPanel scrollPanel;

private int messagesToKeep;
private Listener listener;

private DisplayOrder displayOrder = DisplayOrder.ASCENDING;

Expand All @@ -113,9 +114,11 @@ public NotificationView()
initWidget(uiBinder.createAndBindUi(this));
}

public HasClickHandlers getClearButton()
@UiHandler("clearLink")
public void onClearButtonClick(ClickEvent event)
{
return clearLink;
listener.onClearClick();

}

@Override
Expand Down Expand Up @@ -222,4 +225,10 @@ public void setMessageOrder(DisplayOrder displayOrder)
{
this.displayOrder = displayOrder;
}

@Override
public void setListener(Listener listener)
{
this.listener = listener;
}
}
@@ -1,7 +1,6 @@
package org.zanata.webtrans.client.view;

import org.zanata.webtrans.client.events.NotificationEvent.Severity;
import org.zanata.webtrans.client.presenter.NotificationPresenter;
import org.zanata.webtrans.client.presenter.ValidationOptionsPresenter;
import org.zanata.webtrans.client.presenter.WorkspaceUsersPresenter;
import org.zanata.webtrans.client.resources.WebTransMessages;
Expand Down Expand Up @@ -50,7 +49,7 @@ interface Styles extends CssResource
TabLayoutPanel container;

@Inject
public SideMenuView(final WebTransMessages messages, final EditorOptionsDisplay editorOptionView, final ValidationOptionsPresenter.Display validationOptionView, final WorkspaceUsersPresenter.Display workspaceUsersView, final NotificationPresenter.Display notificationView)
public SideMenuView(final WebTransMessages messages, final EditorOptionsDisplay editorOptionView, final ValidationOptionsPresenter.Display validationOptionView, final WorkspaceUsersPresenter.Display workspaceUsersView, final NotificationDisplay notificationView)
{
initWidget(uiBinder.createAndBindUi(this));
notificationTab.setTitle(messages.notification());
Expand Down

0 comments on commit 0a2db05

Please sign in to comment.