Search in sources :

Example 1 with Handler

use of org.opennms.features.topology.app.internal.gwt.client.d3.D3Events.Handler in project opennms by OpenNMS.

the class VTopologyComponent method vertexClickHandler.

private Handler<GWTVertex> vertexClickHandler() {
    return new D3Events.Handler<GWTVertex>() {

        @Override
        public void call(GWTVertex vertex, int index) {
            if (D3.eventDefaultPrevented()) {
                return;
            }
            NativeEvent event = D3.getEvent();
            SVGGElement vertexElement = event.getCurrentEventTarget().cast();
            vertexElement.getParentElement().appendChild(vertexElement);
            event.preventDefault();
            event.stopPropagation();
            final MouseEventDetails mouseDetails = MouseEventDetailsBuilder.buildMouseEventDetails(event, getElement());
            m_serverRpc.vertexClicked(vertex.getId(), mouseDetails, Navigator.getPlatform());
        }
    };
}
Also used : SVGGElement(org.opennms.features.topology.app.internal.gwt.client.svg.SVGGElement) MouseEventDetails(com.vaadin.shared.MouseEventDetails) MarqueeSelectHandler(org.opennms.features.topology.app.internal.gwt.client.handler.MarqueeSelectHandler) PanHandler(org.opennms.features.topology.app.internal.gwt.client.handler.PanHandler) Handler(org.opennms.features.topology.app.internal.gwt.client.d3.D3Events.Handler) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 2 with Handler

use of org.opennms.features.topology.app.internal.gwt.client.d3.D3Events.Handler in project opennms by OpenNMS.

the class VTopologyComponent method vertexDragStartHandler.

private Handler<GWTVertex> vertexDragStartHandler() {
    return new Handler<GWTVertex>() {

        @Override
        public void call(GWTVertex vertex, int index) {
            NativeEvent event = D3.getEvent();
            Element draggableElement = Element.as(event.getEventTarget()).getParentElement();
            D3 selection = null;
            boolean isSelected = draggableElement.getAttribute("class").equals("vertex selected");
            if (isSelected) {
                selection = D3.d3().selectAll(GWTVertex.SELECTED_VERTEX_CLASS_NAME);
            } else {
                selection = D3.d3().select(Element.as(event.getEventTarget()).getParentElement());
            }
            m_dragObject = new DragObject(VTopologyComponent.this.m_topologyView, draggableElement, m_topologyView.getSVGViewPort(), selection);
            D3.getEvent().preventDefault();
            D3.getEvent().stopPropagation();
        }
    };
}
Also used : SVGGElement(org.opennms.features.topology.app.internal.gwt.client.svg.SVGGElement) Element(com.google.gwt.dom.client.Element) DragObject(org.opennms.features.topology.app.internal.gwt.client.handler.DragObject) MarqueeSelectHandler(org.opennms.features.topology.app.internal.gwt.client.handler.MarqueeSelectHandler) PanHandler(org.opennms.features.topology.app.internal.gwt.client.handler.PanHandler) Handler(org.opennms.features.topology.app.internal.gwt.client.d3.D3Events.Handler) NativeEvent(com.google.gwt.dom.client.NativeEvent) D3(org.opennms.features.topology.app.internal.gwt.client.d3.D3)

Example 3 with Handler

use of org.opennms.features.topology.app.internal.gwt.client.d3.D3Events.Handler in project opennms by OpenNMS.

the class MarqueeSelectHandler method selectVertices.

private void selectVertices() {
    // We use the svgIconOverlay to determine the selection and ignore the status border, the label
    // and possible invisible elements, such as status badge, navigate to target etc, as the vertex is
    // slightly greater than the svgIconOverlay and the user probably uses the icon itself to make the selection.
    D3 iconOverlay = m_svgTopologyMap.selectAllVertexElements().select(".svgIconOverlay");
    JsArray<JsArray<SVGElement>> selection = iconOverlay.cast();
    final JsArray<SVGElement> elemArray = selection.get(0);
    iconOverlay.each(new Handler<GWTVertex>() {

        @Override
        public void call(GWTVertex vertex, int index) {
            SVGElement elem = elemArray.get(index).cast();
            boolean selected = inSelection(elem);
            vertex.setSelected(selected);
        }
    });
}
Also used : JsArray(com.google.gwt.core.client.JsArray) SVGElement(org.opennms.features.topology.app.internal.gwt.client.svg.SVGElement) GWTVertex(org.opennms.features.topology.app.internal.gwt.client.GWTVertex) D3(org.opennms.features.topology.app.internal.gwt.client.d3.D3)

Example 4 with Handler

use of org.opennms.features.topology.app.internal.gwt.client.d3.D3Events.Handler 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 Handler

use of org.opennms.features.topology.app.internal.gwt.client.d3.D3Events.Handler in project opennms by OpenNMS.

the class VTopologyComponent method setupDragBehavior.

private void setupDragBehavior(final Element panElem, final DragHandlerManager handlerManager) {
    D3Drag d3Pan = D3.getDragBehavior();
    d3Pan.on(D3Events.DRAG_START.event(), new Handler<Element>() {

        @Override
        public void call(Element elem, int index) {
            handlerManager.onDragStart(elem);
        }
    });
    d3Pan.on(D3Events.DRAG.event(), new Handler<Element>() {

        @Override
        public void call(Element elem, int index) {
            handlerManager.onDrag(elem);
        }
    });
    d3Pan.on(D3Events.DRAG_END.event(), new Handler<Element>() {

        @Override
        public void call(Element elem, int index) {
            handlerManager.onDragEnd(elem);
        }
    });
    D3 select = D3.d3().select(panElem);
    select.call(d3Pan);
}
Also used : SVGGElement(org.opennms.features.topology.app.internal.gwt.client.svg.SVGGElement) Element(com.google.gwt.dom.client.Element) D3Drag(org.opennms.features.topology.app.internal.gwt.client.d3.D3Drag) 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)

Aggregations

D3 (org.opennms.features.topology.app.internal.gwt.client.d3.D3)4 NativeEvent (com.google.gwt.dom.client.NativeEvent)3 MarqueeSelectHandler (org.opennms.features.topology.app.internal.gwt.client.handler.MarqueeSelectHandler)3 PanHandler (org.opennms.features.topology.app.internal.gwt.client.handler.PanHandler)3 SVGGElement (org.opennms.features.topology.app.internal.gwt.client.svg.SVGGElement)3 Element (com.google.gwt.dom.client.Element)2 Point (com.google.gwt.touch.client.Point)2 D3Drag (org.opennms.features.topology.app.internal.gwt.client.d3.D3Drag)2 Handler (org.opennms.features.topology.app.internal.gwt.client.d3.D3Events.Handler)2 SVGPoint (org.opennms.features.topology.app.internal.gwt.client.svg.SVGPoint)2 JsArray (com.google.gwt.core.client.JsArray)1 EventTarget (com.google.gwt.dom.client.EventTarget)1 MouseEventDetails (com.vaadin.shared.MouseEventDetails)1 GWTVertex (org.opennms.features.topology.app.internal.gwt.client.GWTVertex)1 D3Behavior (org.opennms.features.topology.app.internal.gwt.client.d3.D3Behavior)1 DragHandlerManager (org.opennms.features.topology.app.internal.gwt.client.handler.DragHandlerManager)1 DragObject (org.opennms.features.topology.app.internal.gwt.client.handler.DragObject)1 ServiceRegistry (org.opennms.features.topology.app.internal.gwt.client.service.ServiceRegistry)1 DefaultServiceRegistry (org.opennms.features.topology.app.internal.gwt.client.service.support.DefaultServiceRegistry)1 SVGElement (org.opennms.features.topology.app.internal.gwt.client.svg.SVGElement)1