Skip to content

Commit

Permalink
* encapsulated widget bindings into separate module class;
Browse files Browse the repository at this point in the history
* added loading banner;
  • Loading branch information
domax committed Sep 15, 2014
1 parent dd974e2 commit 1b0f2ff
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,22 @@
*/
package org.gwt.dynamic.module.gwtp.client.application;

import org.gwt.dynamic.module.gwtp.client.application.content.ContentPresenter;
import org.gwt.dynamic.module.gwtp.client.application.content.ContentView;
import org.gwt.dynamic.module.gwtp.client.application.roles.RolesPresenter;
import org.gwt.dynamic.module.gwtp.client.application.roles.RolesView;
import org.gwt.dynamic.module.gwtp.client.application.content.ContentModule;

import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.SimpleEventBus;
import com.gwtplatform.common.client.CommonGinModule;
import com.gwtplatform.mvp.client.gin.AbstractPresenterModule;
import com.gwtplatform.mvp.client.proxy.PlaceManager;

public class ClientModule extends AbstractPresenterModule {

@Override
protected void configure() {
install(new CommonGinModule());
bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
bind(PlaceManager.class).to(SilentPlaceManager.class).in(Singleton.class);
bind(FeatureController.class).asEagerSingleton();

bindSingletonPresenterWidget(
ContentPresenter.class,
ContentPresenter.MyView.class,
ContentView.class);
bindSingletonPresenterWidget(
RolesPresenter.class,
RolesPresenter.MyView.class,
RolesView.class);
install(new ContentModule());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2014 Maxim Dominichenko
*
* Licensed under The MIT License (MIT) (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* https://github.com/domax/gwt-dynamic-plugins/blob/master/LICENSE
*
* 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 org.gwt.dynamic.module.gwtp.client.application.content;

import org.gwt.dynamic.module.gwtp.client.application.roles.RolesPresenter;
import org.gwt.dynamic.module.gwtp.client.application.roles.RolesView;

import com.gwtplatform.mvp.client.gin.AbstractPresenterModule;

public class ContentModule extends AbstractPresenterModule {

@Override
protected void configure() {
bindSingletonPresenterWidget(
ContentPresenter.class,
ContentPresenter.MyView.class,
ContentView.class);
bindSingletonPresenterWidget(
RolesPresenter.class,
RolesPresenter.MyView.class,
RolesView.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public class ContentPresenter extends ModulePresenter<ContentPresenter.MyView> i
public static final Object SLOT_NESTED = new Object();

public interface MyView extends View, HasUiHandlers<ContentUiHandlers> {

void setError(String error);

void setBanner(String banner);
}

private final RolesPresenter nestedPresenter;
Expand All @@ -60,12 +63,14 @@ protected void onBind() {
protected void onReveal() {
super.onReveal();
LOG.info("ContentPresenter.onReveal");
getView().setBanner("Loading role data...");
RoleServiceConsumer.get().getRoles(new AsyncCallback<Set<RoleBean>>() {

@Override
public void onSuccess(Set<RoleBean> result) {
LOG.info("ContentPresenter#getRoles#onFailure");
LOG.fine("ContentPresenter#getRoles#onFailure: result=" + result);
getView().setBanner(null);
RolesLoadedEvent.fire(ContentPresenter.this, result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.gwt.dynamic.module.gwtp.client.application.content;

import static org.gwt.dynamic.common.shared.Utils.isEmpty;

import java.util.logging.Logger;

import com.google.gwt.resources.client.CssResource;
Expand All @@ -36,7 +38,10 @@ public class ContentView extends ViewWithUiHandlers<ContentUiHandlers>
interface Binder extends UiBinder<Widget, ContentView> {}

public interface InnerCss extends CssResource {

String error();

String banner();
}

@UiField public static InnerCss style;
Expand All @@ -62,6 +67,16 @@ public void setInSlot(Object slot, IsWidget content) {
public void setError(String error) {
LOG.info("HomeView.setError: error=" + error);
message.setText(error);
main.removeStyleName(style.banner());
main.addStyleName(style.error());
}

@Override
public void setBanner(String banner) {
LOG.info("HomeView.setBanner: banner=" + banner);
message.setText(banner);
main.removeStyleName(style.error());
if (isEmpty(banner)) main.removeStyleName(style.banner());
else main.addStyleName(style.banner());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
display: block;
color: red;
}
.banner .message {
display: block;
color: grey;
}

.content {
position: absolute;
Expand All @@ -42,7 +46,8 @@
width: 100%;
height: 100%;
}
.error .content {
.error .content,
.banner .content {
display: none;
}
</ui:style>
Expand Down

1 comment on commit 1b0f2ff

@domax
Copy link
Owner Author

@domax domax commented on 1b0f2ff Sep 15, 2014

Choose a reason for hiding this comment

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

#2

Please sign in to comment.