Search in sources :

Example 1 with EventTarget

use of com.google.gwt.dom.client.EventTarget in project rstudio by rstudio.

the class ShortcutViewer method onPreviewNativeEvent.

@Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
    if (event.isCanceled())
        return;
    if (event.getTypeInt() == Event.ONKEYDOWN || event.getTypeInt() == Event.ONMOUSEDOWN) {
        if (event.getTypeInt() == Event.ONMOUSEDOWN && event.getNativeEvent().getButton() == NativeEvent.BUTTON_RIGHT)
            return;
        // Don't dismiss the dialog if the click is targeted for a child
        // of the shortcut info panel's root element
        EventTarget et = event.getNativeEvent().getEventTarget();
        if (Element.is(et) && event.getTypeInt() == Event.ONMOUSEDOWN) {
            Element e = Element.as(et);
            while (e != null) {
                if (e == shortcutInfo_.getRootElement())
                    return;
                e = e.getParentElement();
            }
        }
        // This is a keystroke or a click outside the panel; dismiss the panel
        if (shortcutInfo_ != null)
            RootLayoutPanel.get().remove(shortcutInfo_);
        shortcutInfo_ = null;
        if (preview_ != null)
            preview_.removeHandler();
        preview_ = null;
        event.cancel();
    }
}
Also used : Element(com.google.gwt.dom.client.Element) EventTarget(com.google.gwt.dom.client.EventTarget)

Example 2 with EventTarget

use of com.google.gwt.dom.client.EventTarget in project rstudio by rstudio.

the class ShinyGadgetDialog method addCaptionWithCloseButton.

private void addCaptionWithCloseButton(String caption) {
    final Image closeIcon = new Image(new ImageResource2x(ThemeResources.INSTANCE.closeDialog2x()));
    Style closeIconStyle = closeIcon.getElement().getStyle();
    closeIconStyle.setCursor(Style.Cursor.POINTER);
    closeIconStyle.setMarginTop(2, Unit.PX);
    FlexTable captionLayoutTable = new FlexTable();
    captionLayoutTable.setWidth("100%");
    captionLayoutTable.setText(0, 0, caption);
    captionLayoutTable.setWidget(0, 1, closeIcon);
    captionLayoutTable.getCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.HorizontalAlignmentConstant.endOf(Direction.LTR));
    HTML captionWidget = (HTML) getCaption();
    captionWidget.getElement().appendChild(captionLayoutTable.getElement());
    captionWidget.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            EventTarget target = event.getNativeEvent().getEventTarget();
            Element targetElement = (Element) target.cast();
            if (targetElement == closeIcon.getElement()) {
                closeIcon.fireEvent(event);
            }
        }
    });
    closeIcon.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            performClose();
        }
    });
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Element(com.google.gwt.dom.client.Element) FlexTable(com.google.gwt.user.client.ui.FlexTable) ImageResource2x(org.rstudio.core.client.resources.ImageResource2x) Style(com.google.gwt.dom.client.Style) HTML(com.google.gwt.user.client.ui.HTML) Image(com.google.gwt.user.client.ui.Image) EventTarget(com.google.gwt.dom.client.EventTarget)

Example 3 with EventTarget

use of com.google.gwt.dom.client.EventTarget in project rstudio by rstudio.

the class MultiSelectCellTable method handleContextMenu.

// handle context-menu clicks. this implementation (specifically the 
// detection of table rows from dom events) is based on the code in
// AbstractCellTable.onBrowserEvent2. we first determine if the click
// applies to a row in the table -- if it does then we squelch the 
// standard handling of the event and update the selection and then 
// forward the event on to any external listeners
private void handleContextMenu(ContextMenuEvent cmEvent) {
    // bail if there are no context menu handlers
    if (handlerManager_.getHandlerCount(ContextMenuEvent.getType()) == 0)
        return;
    // Get the event target.
    NativeEvent event = cmEvent.getNativeEvent();
    EventTarget eventTarget = event.getEventTarget();
    if (!Element.is(eventTarget))
        return;
    final Element target = event.getEventTarget().cast();
    // always squelch default handling (when there is a handler)
    event.stopPropagation();
    event.preventDefault();
    // find the table cell element then get its parent and cast to row
    TableCellElement tableCell = findNearestParentCell(target);
    if (tableCell == null)
        return;
    Element trElem = tableCell.getParentElement();
    if (trElem == null)
        return;
    TableRowElement tr = TableRowElement.as(trElem);
    // get the section of the row and confirm it is a tbody (as opposed
    // to a thead or tfoot)
    Element sectionElem = tr.getParentElement();
    if (sectionElem == null)
        return;
    TableSectionElement section = TableSectionElement.as(sectionElem);
    if (section != getTableBodyElement())
        return;
    // determine the row/item target
    int row = tr.getSectionRowIndex();
    T item = getVisibleItem(row);
    // if this row isn't already selected then clear the existing selection
    if (!getSelectionModel().isSelected(item))
        clearSelection();
    // select the clicked on item
    getSelectionModel().setSelected(item, true);
    // forward the event
    DomEvent.fireNativeEvent(event, handlerManager_);
}
Also used : TableSectionElement(com.google.gwt.dom.client.TableSectionElement) TableRowElement(com.google.gwt.dom.client.TableRowElement) TableCellElement(com.google.gwt.dom.client.TableCellElement) TableSectionElement(com.google.gwt.dom.client.TableSectionElement) TableRowElement(com.google.gwt.dom.client.TableRowElement) TableElement(com.google.gwt.dom.client.TableElement) Element(com.google.gwt.dom.client.Element) EventTarget(com.google.gwt.dom.client.EventTarget) TableCellElement(com.google.gwt.dom.client.TableCellElement) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 4 with EventTarget

use of com.google.gwt.dom.client.EventTarget in project opennms by OpenNMS.

the class VTopologyComponent method initialize.

private void initialize() {
    super.onLoad();
    consoleLog("onLoad");
    ServiceRegistry serviceRegistry = new DefaultServiceRegistry();
    serviceRegistry.register(vertexClickHandler(), new HashMap<String, String>() {

        {
            put("handlerType", "vertexClick");
        }
    }, Handler.class);
    serviceRegistry.register(vertexDblClickHandler(), new HashMap<String, String>() {

        {
            put("handlerType", "vertexDblClick");
        }
    }, Handler.class);
    serviceRegistry.register(vertexContextMenuHandler(), new HashMap<String, String>() {

        {
            put("handlerType", "vertexContextMenu");
        }
    }, Handler.class);
    serviceRegistry.register(edgeContextHandler(), new HashMap<String, String>() {

        {
            put("handlerType", "edgeContextMenu");
        }
    }, Handler.class);
    serviceRegistry.register(edgeClickHandler(), new HashMap<String, String>() {

        {
            put("handlerType", "edgeClick");
        }
    }, Handler.class);
    m_topologyView = new TopologyViewImpl();
    m_topologyView.setPresenter(this);
    m_componentHolder.setSize("100%", "100%");
    m_componentHolder.add(m_topologyView.asWidget());
    m_svgDragHandlerManager = new DragHandlerManager();
    m_svgDragHandlerManager.addDragBehaviorHandler(PanHandler.DRAG_BEHAVIOR_KEY, new PanHandler(this));
    m_svgDragHandlerManager.addDragBehaviorHandler(MarqueeSelectHandler.DRAG_BEHAVIOR_KEY, new MarqueeSelectHandler(this, m_topologyView));
    m_svgDragHandlerManager.setCurrentDragHandler(PanHandler.DRAG_BEHAVIOR_KEY);
    setupDragBehavior(m_topologyView.getSVGElement(), m_svgDragHandlerManager);
    D3 svgElement = D3.d3().select(m_topologyView.getSVGElement());
    // svgElement.on("dblclick", new Handler<Void>() {
    // 
    // @Override
    // public void call(Void t, int index) {
    // JsArrayInteger pos = D3.getMouse(m_topologyView.getSVGElement());
    // onBackgroundDoubleClick(m_topologyView.getPoint(pos.get(0), pos.get(1)));
    // }
    // 
    // })
    svgElement.on(D3Events.CONTEXT_MENU.event(), new Handler<Void>() {

        @Override
        public void call(Void aVoid, int index) {
            NativeEvent event = D3.getEvent();
            if (D3.eventDefaultPrevented()) {
                return;
            }
            if (!isMarqueeSelected()) {
                EventTarget target = event.getEventTarget();
                if (target.equals(m_topologyView.getSVGElement())) {
                    onContextMenu(null, event.getClientX(), event.getClientY(), "map");
                }
            }
            event.preventDefault();
            event.stopPropagation();
        }
    });
    svgElement.on(D3Events.CLICK.event(), new Handler<Void>() {

        @Override
        public void call(Void aVoid, int index) {
            NativeEvent event = D3.getEvent();
            if (D3.eventDefaultPrevented()) {
                return;
            }
            if (!isMarqueeSelected() && event.getButton() == NativeEvent.BUTTON_LEFT && event.getEventTarget().equals(m_topologyView.getSVGElement())) {
                onBackgroundClick();
            }
            event.preventDefault();
            event.stopPropagation();
        }
    });
    svgElement.on(D3Events.MOUSE_WHEEL.event(), new Handler<Void>() {

        @Override
        public void call(Void t, int index) {
            double scrollVal = (double) D3.getEvent().getMouseWheelVelocityY() / 30.0;
            SVGPoint centerPos = m_topologyView.getCenterPos(m_graph.getBoundingBox());
            onMouseWheel(scrollVal, (int) centerPos.getX(), (int) centerPos.getY());
        }
    });
    D3Behavior dragBehavior = new D3Behavior() {

        @Override
        public D3 run(D3 selection) {
            D3Drag drag = D3.getDragBehavior();
            drag.on(D3Events.DRAG_START.event(), vertexDragStartHandler());
            drag.on(D3Events.DRAG.event(), vertexDragHandler());
            drag.on(D3Events.DRAG_END.event(), vertexDragEndHandler());
            selection.call(drag);
            return selection;
        }
    };
    m_graphDrawer = new SVGGraphDrawer(dragBehavior, serviceRegistry);
    m_graphDrawerNoTransition = new SVGGraphDrawerNoTransition(dragBehavior, serviceRegistry);
    setTopologyViewRenderer(m_graphDrawer);
    m_updatePhysicalDimensionTimer.scheduleRepeating(UPDATE_PHYSICAL_DIMENSIONS_TIMER_PERIOD_MILLIS);
}
Also used : PanHandler(org.opennms.features.topology.app.internal.gwt.client.handler.PanHandler) D3Behavior(org.opennms.features.topology.app.internal.gwt.client.d3.D3Behavior) SVGPoint(org.opennms.features.topology.app.internal.gwt.client.svg.SVGPoint) Point(com.google.gwt.touch.client.Point) D3(org.opennms.features.topology.app.internal.gwt.client.d3.D3) SVGPoint(org.opennms.features.topology.app.internal.gwt.client.svg.SVGPoint) DefaultServiceRegistry(org.opennms.features.topology.app.internal.gwt.client.service.support.DefaultServiceRegistry) DragHandlerManager(org.opennms.features.topology.app.internal.gwt.client.handler.DragHandlerManager) DefaultServiceRegistry(org.opennms.features.topology.app.internal.gwt.client.service.support.DefaultServiceRegistry) ServiceRegistry(org.opennms.features.topology.app.internal.gwt.client.service.ServiceRegistry) D3Drag(org.opennms.features.topology.app.internal.gwt.client.d3.D3Drag) EventTarget(com.google.gwt.dom.client.EventTarget) MarqueeSelectHandler(org.opennms.features.topology.app.internal.gwt.client.handler.MarqueeSelectHandler) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 5 with EventTarget

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

the class AbstractVerticalMergableGridWidget method onBrowserEvent.

@Override
public void onBrowserEvent(Event event) {
    String eventType = event.getType();
    // Get the event target
    EventTarget eventTarget = event.getEventTarget();
    if (!Element.is(eventTarget)) {
        return;
    }
    Element target = event.getEventTarget().cast();
    // Check whether "group" widget has been clicked
    boolean bGroupWidgetClick = isGroupWidgetClicked(event, target);
    // Find the cell where the event occurred.
    TableCellElement eventTableCell = findNearestParentCell(target);
    if (eventTableCell == null) {
        return;
    }
    int htmlCol = eventTableCell.getCellIndex();
    Element trElem = eventTableCell.getParentElement();
    if (trElem == null) {
        return;
    }
    TableRowElement tr = TableRowElement.as(trElem);
    int htmlRow = tr.getSectionRowIndex();
    // Convert HTML coordinates to physical coordinates
    CellValue<?> htmlCell = data.get(htmlRow).get(htmlCol);
    Coordinate eventPhysicalCoordinate = htmlCell.getPhysicalCoordinate();
    CellValue<?> eventPhysicalCell = data.get(eventPhysicalCoordinate.getRow()).get(eventPhysicalCoordinate.getCol());
    // Event handlers
    if (eventType.equals("mousedown")) {
        handleMousedownEvent(event, eventPhysicalCoordinate, bGroupWidgetClick);
        return;
    } else if (eventType.equals("mousemove")) {
        handleMousemoveEvent(event, eventPhysicalCoordinate);
        return;
    } else if (eventType.equals("mouseup")) {
        handleMouseupEvent(event, eventPhysicalCoordinate);
        return;
    } else if (eventType.equals("keydown")) {
        handleKeyboardNavigationEvent(event);
        if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
            // events.
            switch(rangeDirection) {
                case UP:
                    eventPhysicalCell = selections.first();
                    break;
                case DOWN:
                    eventPhysicalCell = selections.last();
                    break;
            }
            eventPhysicalCoordinate = eventPhysicalCell.getCoordinate();
            eventTableCell = tbody.getRows().getItem(eventPhysicalCell.getHtmlCoordinate().getRow()).getCells().getItem(eventPhysicalCell.getHtmlCoordinate().getCol());
        }
    }
    // Pass event and physical cell to Cell Widget for handling
    Cell<CellValue<? extends Comparable<?>>> cellWidget = columns.get(eventPhysicalCoordinate.getCol()).getCell();
    // Implementations of AbstractCell aren't forced to initialise consumed events
    Set<String> consumedEvents = cellWidget.getConsumedEvents();
    if (consumedEvents != null && consumedEvents.contains(eventType)) {
        Context context = new Context(eventPhysicalCoordinate.getRow(), eventPhysicalCoordinate.getCol(), eventPhysicalCoordinate);
        // The element containing the cell's HTML is nested inside two DIVs
        Element parent = eventTableCell.getFirstChildElement().getFirstChildElement();
        cellWidget.onBrowserEvent(context, parent, eventPhysicalCell, event, null);
    }
}
Also used : Context(com.google.gwt.cell.client.Cell.Context) TableRowElement(com.google.gwt.dom.client.TableRowElement) TableCellElement(com.google.gwt.dom.client.TableCellElement) TableSectionElement(com.google.gwt.dom.client.TableSectionElement) DivElement(com.google.gwt.dom.client.DivElement) TableRowElement(com.google.gwt.dom.client.TableRowElement) Element(com.google.gwt.dom.client.Element) Coordinate(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.Coordinate) EventTarget(com.google.gwt.dom.client.EventTarget) TableCellElement(com.google.gwt.dom.client.TableCellElement)

Aggregations

EventTarget (com.google.gwt.dom.client.EventTarget)16 Element (com.google.gwt.dom.client.Element)11 Point (com.gwtmobile.ui.client.utils.Point)4 NativeEvent (com.google.gwt.dom.client.NativeEvent)3 Node (com.google.gwt.dom.client.Node)2 TableCellElement (com.google.gwt.dom.client.TableCellElement)2 TableRowElement (com.google.gwt.dom.client.TableRowElement)2 TableSectionElement (com.google.gwt.dom.client.TableSectionElement)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 NodeDragMoveEvent (com.ait.lienzo.client.core.event.NodeDragMoveEvent)1 NodeDragMoveHandler (com.ait.lienzo.client.core.event.NodeDragMoveHandler)1 Point2D (com.ait.lienzo.client.core.types.Point2D)1 Context (com.google.gwt.cell.client.Cell.Context)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 ButtonElement (com.google.gwt.dom.client.ButtonElement)1 DivElement (com.google.gwt.dom.client.DivElement)1 LIElement (com.google.gwt.dom.client.LIElement)1 Style (com.google.gwt.dom.client.Style)1 TableElement (com.google.gwt.dom.client.TableElement)1