Skip to content

Instantly share code, notes, and snippets.

@confile
Created February 2, 2016 20:16
Show Gist options
  • Save confile/814cee5a94ad5251b535 to your computer and use it in GitHub Desktop.
Save confile/814cee5a94ad5251b535 to your computer and use it in GitHub Desktop.
.java
package test.dashboard.client.app.start;
import javax.inject.Inject;
import test.dashboard.client.app.triggerList.TriggerListPagePresenter;
import test.dashboard.client.app.visitorList.VisitorListPagePresenter;
import test.dashboard.client.messages.Messages;
import test.dashboard.client.theme.base.AppGss;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.resources.client.ClientBundle;
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.HTMLPanel;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;
import com.gwtplatform.mvp.client.ViewWithUiHandlers;
import com.vaadin.polymer.paper.widget.PaperBadge;
import com.vaadin.polymer.paper.widget.PaperDialog;
import com.vaadin.polymer.paper.widget.PaperDrawerPanel;
import com.vaadin.polymer.paper.widget.PaperIconItem;
import com.vaadin.polymer.paper.widget.PaperInput;
import com.vaadin.polymer.paper.widget.PaperTextarea;
public class StartPageView extends ViewWithUiHandlers<StartPageViewUiHandlers> implements StartPagePresenter.MyView {
public interface Resources extends ClientBundle {
@Source({Css.APP_CSS, Css.DEFAULT_CSS})
Css css();
}
public interface Css extends CssResource, AppGss {
String DEFAULT_CSS = "test/dashboard/client/app/start/StartPageView.gss";
String mainPanel();
String headerPanel();
String contentPanel();
}
@UiField(provided = true)
Resources resources;
@UiField(provided = true)
Messages messages;
@UiField
PaperDrawerPanel drawerPanel;
@UiField
PaperIconItem visitorListButton;
@UiField
PaperIconItem triggerButton;
@UiField
// PaperBadge onlineState;
Element onlineState;
@UiField
Element titleLabel;
// @UiField
// Anchor visitorListButton;
//
// @UiField
// Anchor triggerButton;
//
// @UiField
// Element onlineState;
//
// @UiField
// FlowPanel contentSlot;
@UiField
HTMLPanel contentPanel;
@UiField PaperDialog addItemDialog;
@UiField PaperInput titleInput;
@UiField PaperTextarea descriptionInput;
public interface Binder extends UiBinder<Widget, StartPageView> {
}
@Inject
public StartPageView(final Binder binder, Resources resources, Messages messages) {
this.resources = resources;
resources.css().ensureInjected();
this.messages = messages;
initWidget(binder.createAndBindUi(this));
// addStyleNames="on"
// onlineState.addClassName("on");
// onlineState.setVisible(false);
// onlineState.setLabel("on");
// resources.css().ensureInjected();
// GWT.log("frame: "+frame);
// HTMLPanel panel = new HTMLPanel("Hello World! 1324444");
// frame = Frame.wrap(panel.getElement());
// frame.wrap(panel.getElement());
// outerPanel.add(panel);
// createView();
//
// registerMainEvent();
//
// new Timer() {
//
// @Override
// public void run() {
// // TODO Auto-generated method stub
//// otherWindow.postMessage(message, targetOrigin, [transfer]);
//
// post(iframe, "test");
// }
// }.schedule(3000);
}
@Override
public void setInSlot(Object slot, IsWidget content) {
contentPanel.clear();
if (slot == StartPagePresenter.SLOT_CONTENT) {
if (content.getClass().getSimpleName() == VisitorListPagePresenter.class.getSimpleName()) {
titleLabel.setInnerText("Visitor List");
visitorListButton.setActive(true);
}
else if (content.getClass().getSimpleName() == TriggerListPagePresenter.class.getSimpleName()) {
titleLabel.setInnerText("Triggers");
}
contentPanel.add(content);
}
else {
super.setInSlot(slot, content);
}
}
@Override
public void setOnlineState(boolean value) {
GWT.log("setOnlineState: "+value);
if (value) {
onlineState.setInnerText("on");
// onlineState.removeClassName("off");
onlineState.addClassName("on");
// onlineState.setLabel("on");
// onlineState.addStyleName("on");
// onlineState.removeStyleName("off");
// onlineState.setInnerText("Online");
// $(onlineState).css("background-color", "green")
// .css("color", "#fff");
}
else {
onlineState.setInnerText("off");
onlineState.removeClassName("on");
// onlineState.addClassName("off");
// onlineState.setLabel("off");
// onlineState.removeStyleName("on");
// onlineState.addStyleName("off");
// onlineState.setInnerText("Offline");
// $(onlineState).css("background-color", "red")
// .css("color", "#fff");
}
}
private void closeMenu() {
if (drawerPanel.getNarrow()) {
drawerPanel.closeDrawer();
}
}
// ---------------------------------------------
// Events
// ---------------------------------------------
// @UiHandler({"visitorListButton", "triggerButton"})
// void onButtonClick(ClickEvent event) {
// if (event.getSource().equals(visitorListButton)) {
// getUiHandlers().visitorListButtonTapped();
// }
// else if (event.getSource().equals(triggerButton)) {
// getUiHandlers().triggerListButtonTapped();
// }
// }
@UiHandler({"visitorListButton", "triggerButton"})
void onButtonClick(ClickEvent e) {
closeMenu();
if (e.getSource().equals(visitorListButton)) {
getUiHandlers().visitorListButtonTapped();
titleLabel.setInnerText("Visitor List");
}
else if (e.getSource().equals(triggerButton)) {
getUiHandlers().triggerListButtonTapped();
titleLabel.setInnerText("Triggers");
}
}
// old
// @UiHandler("addButton")
// protected void onAddButtonClick(ClickEvent e) {
// addItemDialog.open();
// }
@UiHandler("confirmAddButton")
protected void onConfirmAddButtonClick(ClickEvent e) {
if (!titleInput.getValue().isEmpty()) {
addItem(titleInput.getValue(), descriptionInput.getValue());
// clear text fields
titleInput.setValue("");
descriptionInput.setValue("");
}
}
private void addItem(String title, String description) {
Item item = new Item();
item.setTitle(title);
item.setDescription(description);
contentPanel.add(item);
}
@UiHandler("menuClearAll")
protected void menuClearAll(ClickEvent e) {
closeMenu();
contentPanel.clear();
}
@UiHandler("menuClearDone")
protected void menuClearDone(ClickEvent e) {
closeMenu();
for (int i = contentPanel.getWidgetCount() - 1; i > -1; i--) {
Item item = (Item)contentPanel.getWidget(i);
if (item.isDone()) {
contentPanel.remove(item);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment