Example usage for com.google.gwt.user.client.ui ScrollListener ScrollListener

List of usage examples for com.google.gwt.user.client.ui ScrollListener ScrollListener

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui ScrollListener ScrollListener.

Prototype

ScrollListener

Source Link

Usage

From source file:cc.alcina.framework.gwt.client.gwittir.widget.BoundTableExt.java

License:Open Source License

private void init(int masksValue) {
    renderContext = RenderContext.get().snapshot();
    // GWT.log( "Init "+ +masksValue + " :: "+((masksValue &
    // BoundTable.MULTI_REQUIRES_SHIFT) > 0), null);
    final BoundTableExt instance = this;
    this.topBinding = new Binding();
    this.masks = masksValue;
    this.factory = (this.factory == null) ? new BoundWidgetTypeFactory(true) : this.factory;
    if (((this.masks & BoundTableExt.SORT_MASK) > 0) && (this.columns != null)) {
        this.ascending = new boolean[this.columns.length];
    }// w w  w.jav a  2  s.c  o  m
    if ((this.masks & BoundTableExt.MULTIROWSELECT_MASK) > 0) {
        this.selectedRowStyles = new HashMap();
    }
    if (((this.masks & BoundTableExt.ROW_HANDLE_MASK) > 0)
            && ((this.masks & BoundTableExt.MULTIROWSELECT_MASK) > 0)) {
        this.allRowsHandle = new Button("  ", new ClickListener() {
            public void onClick(Widget sender) {
                if ((getSelected() != null) && (getSelected().size() == 0)) {
                    setSelected(new ArrayList((Collection) getValue()));
                } else {
                    setSelected(new ArrayList());
                }
            }
        });
        this.allRowsHandle.setStyleName("rowHandle");
        this.allRowsHandle.setHeight("100%");
        this.allRowsHandle.setWidth("100%");
        if ((this.masks & BoundTableExt.MULTIROWSELECT_MASK) == 0) {
            this.allRowsHandle.setEnabled(false);
        }
    }
    if ((this.masks & BoundTableExt.ROW_HANDLE_MASK) > 0) {
        this.rowHandles = new ArrayList();
    }
    esp = new EventingSimplePanel();
    createTable();
    if ((masks & BoundTableExt.SCROLL_MASK) > 0) {
        if ("".isEmpty()) {
            throw new UnsupportedOperationException();
        }
        this.scroll = new ScrollPanel();
        this.scroll.setWidget(table);
        super.initWidget(esp);
        scroll.addScrollListener(new ScrollListener() {
            public void onScroll(Widget widget, int scrollLeft, int scrollTop) {
                // GWT.log("HasProvider: " + (provider != null), null);
                if ((provider != null) && (inChunk == false)
                        && (scrollTop >= (table.getOffsetHeight() - scroll.getOffsetHeight()))) {
                    // GWT.log("Scroll Event fired. ", null);
                    lastScrollPosition = scrollTop - 1;
                    next();
                }
            }
        });
    } else {
        super.initWidget(esp);
    }
    this.value = (this.value == null) ? new ArrayList() : this.value;
    this.columns = (this.columns == null) ? new Field[0] : this.columns;
    this.setStyleName("gwittir-BoundTable");
    if ((masks & BoundTableExt.HANDLES_AS_CHECKBOXES) > 0) {
        this.addStyleName("handles-as-checkboxes");
    }
    if ((this.provider != null) && (this.getCurrentChunk() == -1)) {
        this.inChunk = true;
        this.provider.init(this);
    }
    this.addPropertyChangeListener("selected", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            if (getAction() != null) {
                getAction().execute(instance);
            }
        }
    });
    this.addPropertyChangeListener("active", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            boolean newActive = ((Boolean) propertyChangeEvent.getNewValue()).booleanValue();
            if ((masks & BoundTableExt.ROW_HANDLE_MASK) > 0
                    && (masks & BoundTableExt.HANDLES_AS_CHECKBOXES) == 0) {
                for (int i = 0; i < rowHandles.size(); i++) {
                    ((Button) rowHandles.get(i))
                            .setText((newActive && (i <= 8)) ? Integer.toString(i + 1) : " ");
                }
            }
            for (Iterator it = keyBindings.entrySet().iterator(); it.hasNext();) {
                Entry entry = (Entry) it.next();
                handleBinding(newActive, entry);
            }
            for (Iterator it = externalKeyBindings.entrySet().iterator(); it.hasNext();) {
                Entry entry = (Entry) it.next();
                handleBinding(newActive, entry);
            }
        }

        private void handleBinding(boolean newActive, Entry entry) {
            KeyBinding kb = (KeyBinding) entry.getKey();
            Object execute = entry.getValue();
            if (newActive) {
                BoundTableExt.LOG.log(Level.SPAM, "Registering " + kb, null);
                try {
                    if (execute instanceof Task) {
                        KeyboardController.INSTANCE.register(kb, (Task) execute);
                    } else if (execute instanceof Action) {
                        KeyboardController.INSTANCE.register(kb, (Action) execute);
                    } else if (execute instanceof BoundWidget) {
                        KeyboardController.INSTANCE.register(kb, (BoundWidget) execute);
                    }
                } catch (KeyBindingException kbe) {
                    BoundTableExt.LOG.log(Level.DEBUG, "Unable to register" + kb, kbe);
                }
            } else {
                boolean result = KeyboardController.INSTANCE.unregister(kb);
                BoundTableExt.LOG.log(Level.SPAM, "Unregistering " + kb + " " + result, null);
            }
        }
    });
}

From source file:com.totsp.gwittir.client.ui.table.BoundTable.java

License:Open Source License

private void init(int masksValue) {
    //GWT.log( "Init "+ +masksValue + " :: "+((masksValue & BoundTable.MULTI_REQUIRES_SHIFT) > 0), null);
    final BoundTable instance = this;
    this.topBinding = new Binding();
    this.masks = masksValue;
    this.factory = (this.factory == null) ? new BoundWidgetTypeFactory(true) : this.factory;

    if (((this.masks & BoundTable.SORT_MASK) > 0) && (this.columns != null)) {
        this.ascending = new boolean[this.columns.length];
    }/*from  w w w  . j  ava  2s  .c  o m*/

    if ((this.masks & BoundTable.MULTIROWSELECT_MASK) > 0) {
        this.selectedRowStyles = new HashMap();
    }

    if (((this.masks & BoundTable.ROW_HANDLE_MASK) > 0)
            && ((this.masks & BoundTable.MULTIROWSELECT_MASK) > 0)) {
        this.allRowsHandle = new Button("  ", new ClickListener() {

            public void onClick(Widget sender) {
                if ((getSelected() != null) && (getSelected().size() == 0)) {
                    setSelected(new ArrayList((Collection) getValue()));
                } else {
                    setSelected(new ArrayList());
                }
            }
        });
        this.allRowsHandle.setStyleName("rowHandle");
        this.allRowsHandle.setHeight("100%");
        this.allRowsHandle.setWidth("100%");

        if ((this.masks & BoundTable.MULTIROWSELECT_MASK) == 0) {
            this.allRowsHandle.setEnabled(false);
        }
    }

    if ((this.masks & BoundTable.ROW_HANDLE_MASK) > 0) {
        this.rowHandles = new ArrayList();
    }

    this.table = createTableImpl();
    this.table.setCellPadding(0);
    this.table.setCellSpacing(0);

    EventingSimplePanel esp = new EventingSimplePanel();
    esp.setWidget(table);

    if ((masks & BoundTable.SCROLL_MASK) > 0) {
        this.scroll = new ScrollPanel();
        this.scroll.setWidget(table);
        super.initWidget(esp);

        scroll.addScrollListener(new ScrollListener() {

            public void onScroll(Widget widget, int scrollLeft, int scrollTop) {
                //GWT.log("HasProvider: " + (provider != null), null);
                if ((provider != null) && (inChunk == false)
                        && (scrollTop >= (table.getOffsetHeight() - scroll.getOffsetHeight()))) {
                    //GWT.log("Scroll Event fired. ", null);
                    lastScrollPosition = scrollTop - 1;
                    next();
                }
            }
        });
    } else {
        super.initWidget(esp);
    }

    this.table.setCellSpacing(0);
    table.addTableListener(new TableListener() {

        public void onCellClicked(SourcesTableEvents sender, int row, int cell) {
            setActive(true);

            int startColumn = ((masks & BoundTable.ROW_HANDLE_MASK) > 0) ? 1 : 0;

            if (startColumn == 0) {
                handleSelect(true, row, cell);
            }

            if (((masks & BoundTable.SORT_MASK) > 0) && ((masks & BoundTable.HEADER_MASK) > 0) && (row == 0)) {
                sortColumn(cell - startColumn);
            }
        }
    });
    this.base = ((this.scroll == null) ? (Widget) this.table : (Widget) this.scroll);
    this.value = (this.value == null) ? new ArrayList() : this.value;
    this.columns = (this.columns == null) ? new Field[0] : this.columns;
    this.setStyleName("gwittir-BoundTable");

    if ((this.provider != null) && (this.getCurrentChunk() == -1)) {
        this.provider.init(this);
        this.inChunk = true;
    }

    this.addPropertyChangeListener("selected", new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            if (getAction() != null) {
                getAction().execute(instance);
            }
        }
    });
    this.addPropertyChangeListener("active", new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            boolean newActive = ((Boolean) propertyChangeEvent.getNewValue()).booleanValue();

            if ((masks & BoundTable.ROW_HANDLE_MASK) > 0) {
                for (int i = 0; i < rowHandles.size(); i++) {
                    ((Button) rowHandles.get(i))
                            .setText((newActive && (i <= 8)) ? Integer.toString(i + 1) : " ");
                }
            }

            for (Iterator it = keyBindings.entrySet().iterator(); it.hasNext();) {
                Entry entry = (Entry) it.next();
                handleBinding(newActive, entry);
            }

            for (Iterator it = externalKeyBindings.entrySet().iterator(); it.hasNext();) {
                Entry entry = (Entry) it.next();
                handleBinding(newActive, entry);
            }
        }

        private void handleBinding(boolean newActive, Entry entry) {
            KeyBinding kb = (KeyBinding) entry.getKey();
            Object execute = entry.getValue();

            if (newActive) {
                BoundTable.LOG.log(Level.SPAM, "Registering " + kb, null);

                try {
                    if (execute instanceof Task) {
                        KeyboardController.INSTANCE.register(kb, (Task) execute);
                    } else if (execute instanceof Action) {
                        KeyboardController.INSTANCE.register(kb, (Action) execute);
                    } else if (execute instanceof BoundWidget) {
                        KeyboardController.INSTANCE.register(kb, (BoundWidget) execute);
                    }
                } catch (KeyBindingException kbe) {
                    BoundTable.LOG.log(Level.DEBUG, "Unable to register" + kb, kbe);
                }
            } else {
                boolean result = KeyboardController.INSTANCE.unregister(kb);
                BoundTable.LOG.log(Level.SPAM, "Unregistering " + kb + " " + result, null);
            }
        }
    });
}