Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed PopupPresenter setCloseHandler #544

Merged
merged 2 commits into from
Aug 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,16 @@ protected void doCenter() {
int top = (Window.getClientHeight() - popup.getOffsetHeight()) >> 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the bit shift is too complex / 2 would be more readable.


if (!isShowing) {
popup.hide();
hidePopup(asPopupPanel());
popup.setVisible(true);
}

popup.setPopupPosition(Math.max(Window.getScrollLeft() + left, 0), Math.max(
Window.getScrollTop() + top, 0));
}

private native void hidePopup(PopupPanel popupPanel) /*-{
var resizeAnimation = popupPanel.@com.google.gwt.user.client.ui.PopupPanel::resizeAnimation;
resizeAnimation.@com.google.gwt.user.client.ui.PopupPanel.ResizeAnimation::setState(ZZ)(false, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize you could access private variables this way. Very cool trick.

}-*/;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ protected void configure() {
bindPresenter(AdminPresenterTestUtilGwt.class, AdminPresenterTestUtilGwt.MyView.class,
AdminViewTestUtilGwt.class, AdminPresenterTestUtilGwt.MyProxy.class);

bindSingletonPresenterWidget(PopupPresenterTestUtilGwt.class, PopupPresenterTestUtilGwt.MyView.class,
PopupViewTestUtilGwt.class);

// For testing
bind(InstantiationCounterTestUtilGwt.class).asEagerSingleton();
bindConstant().annotatedWith(Names.named("notice")).to("Hello");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface GinjectorTestUtilGwt extends Ginjector {

Provider<AdminPresenterTestUtilGwt> getAdminPresenter();

Provider<PopupPresenterTestUtilGwt> getPopupPresenter();

EventBus getEventBus();

PlaceManager getPlaceManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package com.gwtplatform.mvp.client.gwt.mvp;

import javax.inject.Inject;
import javax.inject.Provider;

import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.PopupViewCloseHandler;
import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.NameToken;
Expand All @@ -28,26 +30,33 @@
/**
* A test presenter meant to be run in a GWTTestCase.
*/
public class MainPresenterTestUtilGwt extends Presenter<MainPresenterTestUtilGwt.MyView,
MainPresenterTestUtilGwt.MyProxy> {
public class MainPresenterTestUtilGwt
extends Presenter<MainPresenterTestUtilGwt.MyView, MainPresenterTestUtilGwt.MyProxy> {

/**
* Presenter's view.
*/
public interface MyView extends View {
interface MyView extends View {
}

/**
* Presenter's proxy.
*/
@ProxyStandard
@NameToken("home")
public interface MyProxy extends ProxyPlace<MainPresenterTestUtilGwt> {
interface MyProxy extends ProxyPlace<MainPresenterTestUtilGwt> {
}

private final Provider<PopupPresenterTestUtilGwt> popupPresenterProvider;

@Inject
public MainPresenterTestUtilGwt(final EventBus eventBus, final MyView view, final MyProxy proxy) {
MainPresenterTestUtilGwt(EventBus eventBus,
MyView view,
MyProxy proxy,
Provider<PopupPresenterTestUtilGwt> popupPresenterProvider) {
super(eventBus, view, proxy, RevealType.Root);

this.popupPresenterProvider = popupPresenterProvider;
}

public void showPopup(PopupViewCloseHandler closeHandler) {
PopupPresenterTestUtilGwt popup = popupPresenterProvider.get();
popup.setCloseHandler(closeHandler);
addToPopupSlot(popup);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.logical.shared.AttachEvent;
import com.google.gwt.junit.client.GWTTestCase;
import com.gwtplatform.mvp.client.DelayedBindRegistry;
import com.gwtplatform.mvp.client.PopupViewCloseHandler;
import com.gwtplatform.mvp.shared.proxy.PlaceRequest;
import com.gwtplatform.mvp.shared.proxy.PlaceRequest.Builder;

Expand All @@ -43,6 +45,7 @@ protected void gwtSetUp() throws Exception {
InstantiationCounterTestUtilGwt.resetCounter();
ginjector = GWT.create(GinjectorTestUtilGwt.class);
DelayedBindRegistry.bind(ginjector);
presenter = ginjector.getMainPresenter().get();
}

/**
Expand All @@ -54,6 +57,42 @@ public void testShouldCreateOnlyOneGinjector() {
assertEquals(1, InstantiationCounterTestUtilGwt.getCounter());
}

public void testPopupViewCloseHandlerNotCalledWhenShown() {
delayTestFinish(1000);
runTest(new ScheduledCommand() {
@Override
public void execute() {
PopupPresenterTestUtilGwt popupPresenter = ginjector.getPopupPresenter().get();
popupPresenter.asWidget().addAttachHandler(new AttachEvent.Handler() {
@Override
public void onAttachOrDetach(AttachEvent event) {
if (event.isAttached()) {
finishTest();
} else {
fail();
}
}
});

ginjector.getPlaceManager().revealDefaultPlace();

final PopupViewCloseHandler closeHandler = new PopupViewCloseHandler() {
@Override
public void onClose() {
fail();
}
};

Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
presenter.showPopup(closeHandler);
}
});
}
});
}

/**
* Verify multiple name tokens.
*/
Expand Down Expand Up @@ -116,4 +155,8 @@ public void execute() {
}
});
}

private void runTest(ScheduledCommand test) {
Scheduler.get().scheduleDeferred(test);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright 2014 ArcBees Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.gwtplatform.mvp.client.gwt.mvp;

import javax.inject.Inject;

import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.PopupView;
import com.gwtplatform.mvp.client.PopupViewCloseHandler;
import com.gwtplatform.mvp.client.PresenterWidget;

public class PopupPresenterTestUtilGwt extends PresenterWidget<PopupPresenterTestUtilGwt.MyView> {
public interface MyView extends PopupView {
}

@Inject
PopupPresenterTestUtilGwt(EventBus eventBus, MyView view) {
super(eventBus, view);
}

public void setCloseHandler(PopupViewCloseHandler closeHandler) {
getView().setCloseHandler(closeHandler);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright 2014 ArcBees Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.gwtplatform.mvp.client.gwt.mvp;

import javax.inject.Inject;

import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.PopupViewImpl;

public class PopupViewTestUtilGwt extends PopupViewImpl implements PopupPresenterTestUtilGwt.MyView {
public interface Binder extends UiBinder<Widget, PopupViewTestUtilGwt> {
}

@UiField
DialogBox mainSlot;

@Inject
PopupViewTestUtilGwt(EventBus eventBus, Binder uiBinder) {
super(eventBus);

initWidget(uiBinder.createAndBindUi(this));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:DialogBox ui:field="mainSlot" modal="true" glassEnabled="true" animationEnabled="true"/>
</ui:UiBinder>