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();
}
}
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();
}
});
}
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_);
}
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);
}
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);
}
}
Aggregations