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

Commit

Permalink
Browse files Browse the repository at this point in the history
Change behaviour of notification panel
Conflicts:

	zanata-war/src/main/java/org/zanata/webtrans/client/presenter/AppPresenter.java
  • Loading branch information
Alex Eng committed Jul 30, 2012
1 parent 1050fff commit 34491d0
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 68 deletions.
Expand Up @@ -93,6 +93,10 @@ public interface Display extends net.customware.gwt.presenter.client.widget.Widg
HasClickHandlers getNotificationBtn();

void setNotificationText(int count, Severity severity);

void startNotificationAlert(int periodMillis);

void cancelNotificationAlert();
}

private final KeyShortcutPresenter keyShortcutPresenter;
Expand Down Expand Up @@ -150,6 +154,18 @@ public void setNotificationLabel(int count, Severity severity)
display.setNotificationText(count, severity);
}

@Override
public void startNotificationAlert(int periodMillis)
{
display.startNotificationAlert(periodMillis);
}

@Override
public void cancelNotificationAlert()
{
display.cancelNotificationAlert();
}

@Override
protected void onBind()
{
Expand Down
Expand Up @@ -5,4 +5,8 @@
public interface HasNotificationLabel
{
void setNotificationLabel(int count, Severity severity);

void cancelNotificationAlert();

void startNotificationAlert(int periodMillis);
}
Expand Up @@ -28,18 +28,16 @@
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.ui.UndoLink;

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;
import com.google.inject.Provider;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*
*
*/
public class NotificationPresenter extends WidgetPresenter<NotificationPresenter.Display>
{
Expand All @@ -60,7 +58,7 @@ public interface Display extends WidgetDisplay
void setModal(boolean modal);

void setAutoHideEnabled(boolean autoHide);

void setAnimationEnabled(boolean enable);

void hide(boolean autoClosed);
Expand All @@ -75,9 +73,9 @@ public interface Display extends WidgetDisplay

void setPopupTopRightCorner();

void show(int delayMillisToClose);

void setMessageOrder(DisplayOrder displayOrder);

boolean isShowing();
}

private HasNotificationLabel listener;
Expand All @@ -86,12 +84,7 @@ public interface Display extends WidgetDisplay
* Message count to keep in notification area
*/
private static final int MESSAGE_TO_KEEP = 50;

/**
* Time where notification pop up stays visible
*/
private static final int DELAY_MILLIS_TO_CLOSE = 2500;


/**
*
* Display order for the notification, Default = ASCENDING
Expand All @@ -100,13 +93,13 @@ public enum DisplayOrder
{
DESCENDING, ASCENDING
}

@Override
protected void onBind()
{
display.setModal(false);
display.setAutoHideEnabled(true);
display.setAnimationEnabled(true);
display.setAnimationEnabled(false);
display.hide(true);
display.setMessagesToKeep(MESSAGE_TO_KEEP);
display.setMessageOrder(DisplayOrder.ASCENDING);
Expand Down Expand Up @@ -150,14 +143,10 @@ public void setNotificationListener(HasNotificationLabel listener)
listener.setNotificationLabel(0, Severity.Info);
}

private void showNotification()
{
display.show(DELAY_MILLIS_TO_CLOSE);
}

public void showNotificationWithNoTimer()
{
display.show();
listener.cancelNotificationAlert();
}

private void appendNotification(Severity severity, String msg, InlineLink inlineLink)
Expand All @@ -169,7 +158,10 @@ private void appendNotification(Severity severity, String msg, InlineLink inline
}
else
{
showNotification();
if (!display.isShowing())
{
listener.startNotificationAlert(500);
}
}
}

Expand Down
Expand Up @@ -227,8 +227,6 @@ public void onWorkspaceContextUpdated(WorkspaceContextUpdateEvent event)
}
}));

setSouthPanelReadOnly(userWorkspaceContext.hasReadOnlyAccess());

registerHandler(display.getOptionsToggle().addValueChangeHandler(new ValueChangeHandler<Boolean>()
{

Expand Down Expand Up @@ -259,6 +257,8 @@ public void onValueChange(ValueChangeEvent<Boolean> event)
}
}));

setSouthPanelReadOnly(userWorkspaceContext.hasReadOnlyAccess());

KeyShortcutEventHandler gotoPreRowHandler = new KeyShortcutEventHandler()
{
@Override
Expand Down
Expand Up @@ -43,6 +43,7 @@
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
Expand All @@ -68,8 +69,6 @@ interface Styles extends CssResource
{
String userName();

String hasError();

String hasWarning();

String image();
Expand Down Expand Up @@ -313,22 +312,50 @@ public void setNotificationText(int count, Severity severity)
notificationBtn.getUpDisabledFace().setText(String.valueOf(count));
notificationBtn.getUpFace().setText(String.valueOf(count));
notificationBtn.getUpHoveringFace().setText(String.valueOf(count));
}

if (severity == Severity.Error)
{
notificationBtn.removeStyleName(style.hasWarning());
notificationBtn.addStyleName(style.hasError());
}
else if(severity == Severity.Warning)
{
notificationBtn.addStyleName(style.hasWarning());
notificationBtn.removeStyleName(style.hasError());
}
else
private boolean isAlert = false;

private final Timer msgAlertTimer = new Timer()
{
@Override
public void run()
{
notificationBtn.removeStyleName(style.hasError());
notificationBtn.removeStyleName(style.hasWarning());
if (!isAlert)
{
setNotificationAlert();
isAlert = true;
}
else
{
removeNotificationAlert();
isAlert = false;
}
}
};

private void setNotificationAlert()
{
notificationBtn.addStyleName(style.hasWarning());
}

private void removeNotificationAlert()
{
notificationBtn.removeStyleName(style.hasWarning());
}

@Override
public void startNotificationAlert(int periodMillis)
{
msgAlertTimer.scheduleRepeating(periodMillis);
msgAlertTimer.run();
}

@Override
public void cancelNotificationAlert()
{
msgAlertTimer.cancel();
removeNotificationAlert();
}

}
Expand Up @@ -93,14 +93,9 @@
margin-left:2px;
}

.hasError
{
background:#FF6E6E;
}

.hasWarning
{
background:#FFFF00;
background:#FFC000;
}

.topMenuBar table
Expand Down
Expand Up @@ -28,13 +28,8 @@
import org.zanata.webtrans.client.resources.Resources;
import org.zanata.webtrans.client.ui.InlineLink;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
import com.google.gwt.resources.client.CssResource;
Expand All @@ -43,9 +38,7 @@
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
Expand Down Expand Up @@ -250,22 +243,6 @@ public void hide(boolean autoClosed)
super.hide(autoClosed);
}

@Override
public void show(int delayMillisToClose)
{
hidePopupTimer.cancel();
super.show();
if (displayOrder == DisplayOrder.ASCENDING)
{
scrollPanel.scrollToTop();
}
else
{
scrollPanel.scrollToBottom();
}
hidePopupTimer.schedule(delayMillisToClose);
}

@Override
public void setMessageOrder(DisplayOrder displayOrder)
{
Expand Down
Expand Up @@ -86,6 +86,9 @@ public void testErrorNotificationShows()
mockListener.setNotificationLabel(1, Severity.Error);
expectLastCall().once();

mockListener.cancelNotificationAlert();
expectLastCall().once();

replayAllMocks();
notificationPresenter.bind();
notificationPresenter.setNotificationListener(mockListener);
Expand Down Expand Up @@ -114,11 +117,14 @@ public void testErrorMessageCount()

mockListener.setNotificationLabel(count, Severity.Error);
expectLastCall().once();

mockListener.cancelNotificationAlert();
expectLastCall().once();
}

mockListener.setNotificationLabel(0, Severity.Info);
expectLastCall().once();

replayAllMocks();
notificationPresenter.bind();
notificationPresenter.setNotificationListener(mockListener);
Expand Down Expand Up @@ -147,6 +153,9 @@ public void testErrorMessageCountExceedMax()

mockListener.setNotificationLabel(count, Severity.Error);
expectLastCall().once();

mockListener.cancelNotificationAlert();
expectLastCall().once();
}

mockDisplay.show();
Expand Down Expand Up @@ -187,7 +196,7 @@ private void expectPresenterSetupActions()
{
mockDisplay.setModal(false);
mockDisplay.setAutoHideEnabled(true);
mockDisplay.setAnimationEnabled(true);
mockDisplay.setAnimationEnabled(false);
mockDisplay.hide(true);
mockDisplay.setMessagesToKeep(MSG_TO_KEEP);
mockDisplay.setPopupTopRightCorner();
Expand Down

0 comments on commit 34491d0

Please sign in to comment.