Skip to content

Instantly share code, notes, and snippets.

@kevzlou7979
Last active June 8, 2017 02:03
Show Gist options
  • Save kevzlou7979/911c9ef57c82026f252c3322b4bbfd12 to your computer and use it in GitHub Desktop.
Save kevzlou7979/911c9ef57c82026f252c3322b4bbfd12 to your computer and use it in GitHub Desktop.
test
/*
* #%L
* Errai Prototype
* %%
* Copyright (C) 2015 - 2017 Doltech
* %%
* 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.
* #L%
*/
package insclix.core.ui.client.base.components.modal;
import com.insclix.errai.mvc.client.controller.AbstractController;
import com.insclix.errai.mvc.client.view.View;
import insclix.core.ui.client.page.base.HasAppLoadingState;
public abstract class AbstractModalController extends AbstractController<AbstractModalController.Display<AbstractModalControls>> implements AbstractModalControls {
public interface Display<C extends AbstractModalControls> extends View<C>, HasAppLoadingState {
}
@Override
public abstract void confirm();
@Override
public abstract void cancel();
}
package insclix.core.ui.client.base.components.modal;
import com.insclix.errai.mvc.client.controller.Controls;
public interface AbstractModalControls extends Controls {
void confirm();
void cancel();
}
/*
* #%L
* Errai Prototype
* %%
* Copyright (C) 2015 - 2016 Doltech
* %%
* 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.
* #L%
*/
package insclix.core.ui.client.base.components.modal;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
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.RootPanel;
import com.insclix.errai.mvc.client.controller.Controller;
import com.insclix.errai.mvc.client.view.ViewComposite;
import gwt.material.design.client.ui.*;
import insclix.core.ui.client.base.components.BaseView;
import insclix.core.ui.client.base.components.modal.constants.LoadingType;
import insclix.core.ui.client.page.base.HasAppLoadingState;
import javax.inject.Inject;
import static gwt.material.design.jquery.client.api.JQuery.$;
public abstract class AbstractModalView<T extends MaterialModal, C extends AbstractModalController> extends BaseView<T, C> implements HasAppLoadingState {
interface ViewBinder extends UiBinder<MaterialModal, AbstractModalView> {}
@UiField
MaterialRow header;
@UiField
MaterialModalContent content;
@UiField
MaterialPanel iconPanel;
private LoadingType loadingType;
public AbstractModalView() {
super(GWT.<UiBinder<T, ViewComposite>>create(ViewBinder.class));
}
@Inject
public AbstractModalView(C controller) {
super(GWT.<UiBinder<T, ViewComposite>>create(ViewBinder.class), controller);
}
@Override
protected void build() {
super.build();
RootPanel.get().add(asWidget());
setScrollHeaderToShadow(true);
setLoadingType(LoadingType.SPINNER);
}
@UiHandler("confirm")
void confirm(ClickEvent e) {
getControls().confirm();
}
public void setScrollHeaderToShadow(boolean scrollHeaderToShadow) {
if (scrollHeaderToShadow) {
// Enable Header shadow when Scroll
$(content.getElement()).on("scroll", event -> {
int scrollTop = $(content.getElement()).scrollTop();
if (scrollTop == 0) {
header.setShadow(0);
} else {
header.setShadow(1);
}
return true;
});
} else {
$(content.getElement()).off("scroll");
}
}
public LoadingType getLoadingType() {
return loadingType;
}
public void setLoadingType(LoadingType loadingType) {
this.loadingType = loadingType;
}
@Override
public void loading(String title, String message) {
if (getLoadingType() == LoadingType.SPINNER) {
MaterialLoader.showLoading(true, iconPanel);
} else if (getLoadingType() == LoadingType.PROGRESS) {
MaterialLoader.showProgress(true, header);
}
}
@Override
public void success(String title, String message) {
hideLoader();
}
@Override
public void error(String title, String message) {
hideLoader();
}
protected void hideLoader() {
if (getLoadingType() == LoadingType.SPINNER) {
MaterialLoader.showLoading(false);
} else if (getLoadingType() == LoadingType.PROGRESS) {
MaterialLoader.showProgress(false);
}
}
}
/*
* #%L
* Errai Prototype
* %%
* Copyright (C) 2015 - 2017 Doltech
* %%
* 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.
* #L%
*/
package insclix.core.ui.client.base.components;
import com.google.gwt.uibinder.client.UiBinder;
import com.insclix.errai.mvc.client.controller.Controller;
import com.insclix.errai.mvc.client.view.AbstractView;
import com.insclix.errai.mvc.client.view.ViewComposite;
import gwt.material.design.client.base.MaterialWidget;
import static gwt.material.design.jquery.client.api.JQuery.$;
public class BaseView<T extends MaterialWidget, C extends Controller> extends AbstractView<T, C> {
public BaseView() {
}
public BaseView(C controls) {
super(controls);
}
public BaseView(T widget, C controls) {
super(widget, controls);
}
public BaseView(T widget) {
super(widget);
}
public BaseView(UiBinder<T, ViewComposite> uiBinder) {
super(uiBinder);
}
public BaseView(UiBinder<T, ViewComposite> uiBinder, C controls) {
super(uiBinder, controls);
}
public BaseView(UiBinder<T, ViewComposite> uiBinder, boolean autoBind) {
super(uiBinder, autoBind);
}
public BaseView(UiBinder<T, ViewComposite> uiBinder, C controls, boolean autoBind) {
super(uiBinder, controls, autoBind);
}
@Override
protected void onPostConstruct() {
super.onPostConstruct();
build();
}
protected void build() {}
}
package com.insclix.budget.client.budget.query.create;
import insclix.core.ui.client.base.components.modal.AbstractModalController;
import javax.enterprise.context.Dependent;
@Dependent
public class BudgetCreateController extends AbstractModalController {
@Override
public void confirm() {
getDisplay().loading("Loading", "Please wait while loading the content");
}
@Override
public void cancel() {
}
}
package com.insclix.budget.client.budget.query.create;
import gwt.material.design.client.ui.MaterialModal;
import insclix.core.ui.client.base.components.modal.AbstractModalView;
import javax.enterprise.context.Dependent;
import javax.inject.Inject;
@Dependent
public class BudgetCreateModal extends AbstractModalView<MaterialModal, BudgetCreateController> {
@Inject
public BudgetCreateModal(BudgetCreateController controller) {
super(controller);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment