Search in sources :

Example 51 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project cuba by cuba-platform.

the class MultiSelectionBodyClickHandler method handleCtrlClick.

protected void handleCtrlClick(SelectionModel.Multi<JsonObject> model, CellReference<JsonObject> cell, GridClickEvent event) {
    NativeEvent e = event.getNativeEvent();
    JsonObject row = cell.getRow();
    if (!e.getCtrlKey() && !e.getMetaKey()) {
        model.deselectAll();
    }
    if (model.isSelected(row)) {
        model.deselect(row);
    } else {
        model.select(row);
    }
}
Also used : JsonObject(elemental.json.JsonObject) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 52 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project cuba by cuba-platform.

the class CubaFileUploadProgressWindow method constructDOM.

protected void constructDOM() {
    setStyleName(CLASSNAME);
    topTabStop = DOM.createDiv();
    topTabStop.setTabIndex(0);
    header = DOM.createDiv();
    header.setClassName(CLASSNAME + "-outerheader");
    headerText = DOM.createDiv();
    headerText.setClassName(CLASSNAME + "-header");
    contents = DOM.createDiv();
    contents.setClassName(CLASSNAME + "-contents");
    footer = DOM.createDiv();
    footer.setClassName(CLASSNAME + "-footer");
    resizeBox = DOM.createDiv();
    resizeBox.setClassName(CLASSNAME + "-resizebox");
    closeBox = DOM.createDiv();
    closeBox.setClassName(CLASSNAME + "-closebox");
    closeBox.setTabIndex(0);
    DOM.appendChild(footer, resizeBox);
    bottomTabStop = DOM.createDiv();
    bottomTabStop.setTabIndex(0);
    wrapper = DOM.createDiv();
    wrapper.setClassName(CLASSNAME + "-wrap");
    DOM.appendChild(wrapper, topTabStop);
    DOM.appendChild(wrapper, header);
    DOM.appendChild(header, closeBox);
    DOM.appendChild(header, headerText);
    DOM.appendChild(wrapper, contents);
    DOM.appendChild(wrapper, footer);
    DOM.appendChild(wrapper, bottomTabStop);
    DOM.appendChild(super.getContainerElement(), wrapper);
    sinkEvents(Event.ONDBLCLICK | Event.MOUSEEVENTS | Event.TOUCHEVENTS | Event.ONCLICK | Event.ONLOSECAPTURE);
    currentFileLabel = new VLabel();
    currentFileLabel.addStyleName("upload-file-label");
    currentFileLabel.setWidth("100%");
    progressBar = new VProgressBar();
    progressBar.addStyleName("upload-progressbar");
    progressBar.setIndeterminate(false);
    progressBar.setState(0);
    progressBar.setWidth("100%");
    cancelButton = new VButton();
    cancelButton.addStyleName("upload-cancel-button");
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            closeWindow();
        }
    });
    contentPanel = new SimpleFocusablePanel();
    contentPanel.setStyleName("content-pane");
    contentPanel.addKeyDownHandler(this);
    contentPanel.addKeyUpHandler(this);
    setWidget(contentPanel);
    final FlowPanel verticalPanel = new FlowPanel();
    verticalPanel.setStyleName("vertical-panel");
    verticalPanel.addStyleName("v-widget");
    verticalPanel.addStyleName("v-has-width");
    verticalPanel.addStyleName("v-has-height");
    verticalPanel.add(currentFileLabel);
    verticalPanel.add(progressBar);
    verticalPanel.add(cancelButton);
    contentPanel.setWidget(verticalPanel);
    // do some calculations for window layout
    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

        @Override
        public void execute() {
            Style contentStyle = contents.getStyle();
            ComputedStyle headerCs = new ComputedStyle(header);
            String headerHeight = headerCs.getProperty("height");
            contentStyle.setProperty("paddingTop", headerHeight);
            contentStyle.setProperty("marginTop", "-" + headerHeight);
            ComputedStyle footerCs = new ComputedStyle(footer);
            String footerHeight = footerCs.getProperty("height");
            contentStyle.setProperty("paddingBottom", footerHeight);
            contentStyle.setProperty("marginBottom", "-" + footerHeight);
        }
    });
    // Make the closebox accessible for assistive devices
    Roles.getButtonRole().set(closeBox);
    Roles.getButtonRole().setAriaLabelProperty(closeBox, "close button");
    // Provide the title to assistive devices
    AriaHelper.ensureHasId(headerText);
    Roles.getDialogRole().setAriaLabelledbyProperty(getElement(), Id.of(headerText));
    // Handlers to Prevent tab to leave the window
    // and backspace to cause browser navigation
    topEventBlocker = new Event.NativePreviewHandler() {

        @Override
        public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
            NativeEvent nativeEvent = event.getNativeEvent();
            if (nativeEvent.getEventTarget().cast() == topTabStop && nativeEvent.getKeyCode() == KeyCodes.KEY_TAB && nativeEvent.getShiftKey()) {
                nativeEvent.preventDefault();
            }
            if (nativeEvent.getEventTarget().cast() == topTabStop && nativeEvent.getKeyCode() == KeyCodes.KEY_BACKSPACE) {
                nativeEvent.preventDefault();
            }
        }
    };
    bottomEventBlocker = new Event.NativePreviewHandler() {

        @Override
        public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
            NativeEvent nativeEvent = event.getNativeEvent();
            if (nativeEvent.getEventTarget().cast() == bottomTabStop && nativeEvent.getKeyCode() == KeyCodes.KEY_TAB && !nativeEvent.getShiftKey()) {
                nativeEvent.preventDefault();
            }
            if (nativeEvent.getEventTarget().cast() == bottomTabStop && nativeEvent.getKeyCode() == KeyCodes.KEY_BACKSPACE) {
                nativeEvent.preventDefault();
            }
        }
    };
}
Also used : ComputedStyle(com.vaadin.client.ComputedStyle) Scheduler(com.google.gwt.core.client.Scheduler) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) ComputedStyle(com.vaadin.client.ComputedStyle) Style(com.google.gwt.dom.client.Style) Event(com.google.gwt.user.client.Event) NativeEvent(com.google.gwt.dom.client.NativeEvent) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 53 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project cuba by cuba-platform.

the class CubaPopupButtonConnector method onPreviewNativeEvent.

@Override
public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    NativeEvent nativeEvent = event.getNativeEvent();
    if (getWidget().getPopup().isVisible()) {
        Element target = Element.as(nativeEvent.getEventTarget());
        if (getWidget().popupHasChild(target)) {
            if (event.getTypeInt() == Event.ONKEYDOWN && (nativeEvent.getKeyCode() == KeyCodes.KEY_ESCAPE || nativeEvent.getKeyCode() == KeyCodes.KEY_TAB && isLastChild(target)) && !nativeEvent.getAltKey() && !nativeEvent.getCtrlKey() && !nativeEvent.getShiftKey() && !nativeEvent.getMetaKey()) {
                event.cancel();
                event.getNativeEvent().stopPropagation();
                event.getNativeEvent().preventDefault();
                Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

                    @Override
                    public void execute() {
                        getWidget().hidePopup();
                        rpc.setPopupVisible(false);
                        getWidget().setFocus(true);
                    }
                });
                return;
            }
        }
    }
    super.onPreviewNativeEvent(event);
    if (isEnabled()) {
        Element target = Element.as(nativeEvent.getEventTarget());
        switch(event.getTypeInt()) {
            case Event.ONCLICK:
                if (getState().autoClose && getWidget().popupHasChild(target)) {
                    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

                        @Override
                        public void execute() {
                            getWidget().hidePopup();
                            // update state on server
                            rpc.setPopupVisible(false);
                        }
                    });
                }
                break;
            case Event.ONKEYDOWN:
                if (!getState().customLayout && getWidget().popupHasChild(target)) {
                    Widget widget = WidgetUtil.findWidget(target, null);
                    if (widget instanceof VButton || widget instanceof VUpload || widget instanceof CubaFileUploadWidget) {
                        Widget widgetParent = widget.getParent();
                        if (widgetParent.getParent() instanceof VUpload) {
                            VUpload upload = (VUpload) widgetParent.getParent();
                            // upload parent is Slot
                            widgetParent = upload.getParent();
                        } else if (widgetParent.getParent() instanceof CubaFileUploadWidget) {
                            CubaFileUploadWidget upload = (CubaFileUploadWidget) widgetParent.getParent();
                            // upload parent is Slot
                            widgetParent = upload.getParent();
                        }
                        VAbstractOrderedLayout layout = (VAbstractOrderedLayout) widgetParent.getParent();
                        Widget focusWidget = null;
                        int widgetIndex = layout.getWidgetIndex(widgetParent);
                        if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_DOWN) {
                            focusWidget = Tools.findNextWidget(layout, widgetIndex);
                        } else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_UP) {
                            focusWidget = Tools.findPrevWidget(layout, widgetIndex);
                        }
                        if (focusWidget instanceof VButton || focusWidget instanceof CubaFileUploadWidget || focusWidget instanceof VUpload) {
                            VButton button;
                            if (focusWidget instanceof VButton) {
                                button = (VButton) focusWidget;
                            } else if (focusWidget instanceof CubaFileUploadWidget) {
                                button = ((CubaFileUploadWidget) focusWidget).getSubmitButton();
                            } else {
                                button = ((VUpload) focusWidget).submitButton;
                            }
                            getWidget().childWidgetFocused(button);
                            button.setFocus(true);
                        }
                    }
                }
                break;
            case Event.ONMOUSEOVER:
                if (!getState().customLayout && getWidget().popupHasChild(target)) {
                    Widget widget = WidgetUtil.findWidget(target, null);
                    if ((widget instanceof VButton || widget instanceof VUpload || widget instanceof CubaFileUploadWidget)) {
                        VButton button;
                        if (widget instanceof VButton) {
                            button = (VButton) widget;
                        } else if (widget instanceof CubaFileUploadWidget) {
                            button = ((CubaFileUploadWidget) widget).getSubmitButton();
                        } else {
                            button = ((VUpload) widget).submitButton;
                        }
                        if (!button.getStyleName().contains(SELECTED_ITEM_STYLE)) {
                            getWidget().childWidgetFocused(button);
                            button.setFocus(true);
                        }
                    }
                }
                break;
        }
    }
}
Also used : CubaFileUploadWidget(com.haulmont.cuba.web.toolkit.ui.client.jqueryfileupload.CubaFileUploadWidget) Scheduler(com.google.gwt.core.client.Scheduler) VButton(com.vaadin.client.ui.VButton) Element(com.google.gwt.dom.client.Element) VUpload(com.vaadin.client.ui.VUpload) VAbstractOrderedLayout(com.vaadin.client.ui.orderedlayout.VAbstractOrderedLayout) CubaFileUploadWidget(com.haulmont.cuba.web.toolkit.ui.client.jqueryfileupload.CubaFileUploadWidget) Widget(com.google.gwt.user.client.ui.Widget) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 54 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project kie-wb-common by kiegroup.

the class DMNGridPanelContextMenuHandler method getRelativeX.

private int getRelativeX(final ContextMenuEvent event) {
    final NativeEvent e = event.getNativeEvent();
    final Element target = event.getRelativeElement();
    return e.getClientX() - target.getAbsoluteLeft() + target.getScrollLeft() + target.getOwnerDocument().getScrollLeft();
}
Also used : Element(com.google.gwt.dom.client.Element) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 55 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project kie-wb-common by kiegroup.

the class DMNGridPanelContextMenuHandler method getRelativeY.

private int getRelativeY(final ContextMenuEvent event) {
    final NativeEvent e = event.getNativeEvent();
    final Element target = event.getRelativeElement();
    return e.getClientY() - target.getAbsoluteTop() + target.getScrollTop() + target.getOwnerDocument().getScrollTop();
}
Also used : Element(com.google.gwt.dom.client.Element) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Aggregations

NativeEvent (com.google.gwt.dom.client.NativeEvent)72 Element (com.google.gwt.dom.client.Element)20 Test (org.junit.Test)12 Column (com.google.gwt.user.cellview.client.Column)8 ValueUpdater (com.google.gwt.cell.client.ValueUpdater)6 EventTarget (com.google.gwt.dom.client.EventTarget)6 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)5 MonacoStandaloneCodeEditor (org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor)5 AbstractCell (com.google.gwt.cell.client.AbstractCell)4 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)4 Context (com.google.gwt.cell.client.Cell.Context)3 JsArrayString (com.google.gwt.core.client.JsArrayString)3 Scheduler (com.google.gwt.core.client.Scheduler)3 Style (com.google.gwt.dom.client.Style)3 TableRowElement (com.google.gwt.dom.client.TableRowElement)3 BlurEvent (com.google.gwt.event.dom.client.BlurEvent)3 Widget (com.google.gwt.user.client.ui.Widget)3 HTMLButtonElement (elemental2.dom.HTMLButtonElement)3 Button (org.gwtbootstrap3.client.ui.Button)3 Icon (org.gwtbootstrap3.client.ui.Icon)3