Search in sources :

Example 61 with Element

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

the class ModifyKeyboardShortcutsWidget method showToolTip.

private void showToolTip(Object object, String text) {
    assert object instanceof Element;
    Element el = (Element) object;
    int index = StringUtil.parseInt(el.getAttribute("__rstudio_masked_index"), -1);
    KeyboardShortcutEntry conflictBinding = originalBindings_.get(index);
    Element divEl = DOM.createDiv();
    Element spanEl = DOM.createSpan();
    spanEl.setInnerHTML(text);
    divEl.appendChild(spanEl);
    String conflictDescription = describeCommand(conflictBinding);
    // We use an anchor element here just to get browser default styling for
    // anchor links; we take over the click behaviour to ensure that the normal
    // 'href' navigation doesn't actually occur.
    Element conflictEl = DOM.createAnchor();
    conflictEl.setAttribute("href", "#");
    conflictEl.setInnerHTML(conflictDescription);
    divEl.appendChild(conflictEl);
    MiniPopupPanel tooltip = new MiniPopupPanel(true);
    bindNativeClickToSelectRow(conflictEl, tooltip.getElement(), index);
    tooltip.getElement().appendChild(divEl);
    tooltip.show();
    PopupPositioner.setPopupPosition(tooltip, el.getAbsoluteRight(), el.getAbsoluteBottom(), 10);
}
Also used : Element(com.google.gwt.dom.client.Element) TableRowElement(com.google.gwt.dom.client.TableRowElement) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 62 with Element

use of com.google.gwt.dom.client.Element 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 63 with Element

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

the class MiniPopupPanel method addDragHandler.

private void addDragHandler() {
    if (dragHandler_ != null)
        dragHandler_.removeHandler();
    dragHandler_ = Event.addNativePreviewHandler(new NativePreviewHandler() {

        @Override
        public void onPreviewNativeEvent(NativePreviewEvent npe) {
            if (npe.getNativeEvent().getButton() != NativeEvent.BUTTON_LEFT)
                return;
            int type = npe.getTypeInt();
            if (type == Event.ONMOUSEDOWN || type == Event.ONMOUSEMOVE || type == Event.ONMOUSEUP) {
                if (dragging_) {
                    handleDrag(npe);
                    return;
                }
                Element target = npe.getNativeEvent().getEventTarget().cast();
                String tagName = target.getTagName().toLowerCase();
                for (String tag : TAGS_EXCLUDE_DRAG) if (tagName.equals(tag))
                    return;
                if (DomUtils.isDescendantOfElementWithTag(target, TAGS_EXCLUDE_DRAG))
                    return;
                Element self = MiniPopupPanel.this.getElement();
                if (!DomUtils.isDescendant(target, self))
                    return;
                handleDrag(npe);
            }
        }
    });
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) Element(com.google.gwt.dom.client.Element) Point(org.rstudio.core.client.Point)

Example 64 with Element

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

the class GlassAttacher method createGlassWidget.

private static Widget createGlassWidget() {
    HTML glass = new HTML();
    glass.setSize("100%", "100%");
    Element glassElem = glass.getElement();
    glassElem.getStyle().setBackgroundColor("white");
    glassElem.getStyle().setProperty("opacity", "0.0");
    glassElem.getStyle().setProperty("filter", "alpha(opacity=0)");
    return glass;
}
Also used : Element(com.google.gwt.dom.client.Element) HTML(com.google.gwt.user.client.ui.HTML)

Example 65 with Element

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

the class ChunkSatelliteWindow method onInitialize.

@Override
protected void onInitialize(LayoutPanel mainPanel, JavaScriptObject params) {
    chunkWindowParams_ = params.cast();
    String title = "RStudio: Notebook Output";
    Window.setTitle(title);
    ChunkOutputHost chunkOutputHost = new ChunkOutputHost() {

        @Override
        public void onOutputRemoved(final ChunkOutputWidget widget) {
        }

        @Override
        public void onOutputHeightChanged(ChunkOutputWidget widget, int height, boolean ensureVisible) {
        }
    };
    chunkOutputWidget_ = new ChunkOutputWidget(chunkWindowParams_.getDocId(), chunkWindowParams_.getChunkId(), RmdChunkOptions.create(), ChunkOutputWidget.EXPANDED, // can close
    false, chunkOutputHost, ChunkOutputSize.Full);
    Element ele = chunkOutputWidget_.getElement();
    ele.addClassName(ThemeStyles.INSTANCE.selectableText());
    // Append the chunkOutputWidget as an HTML element, not as a widget.
    // Why? Chunks are widgets that are attached to the ACE editor as HTML
    // elements, not as widgets. The reason being that GWT does not support
    // triggering events for widgets that are not attached to their hierarchy.
    // Therefore, if we attach this element as a widget, GWT will remove 
    // events in some cases which will cause functionality to be lost.
    mainPanel.getElement().appendChild(chunkOutputWidget_.getElement());
    chunkOutputWidget_.getElement().getStyle().setHeight(100, Unit.PCT);
    mainPanel.addStyleName("ace_editor");
    pEventBus_.get().addHandler(ChunkSatelliteCodeExecutingEvent.TYPE, this);
    pEventBus_.get().addHandler(ChunkSatelliteCacheEditorStyleEvent.TYPE, this);
    pEventBus_.get().addHandler(ChunkPlotRefreshedEvent.TYPE, this);
    pEventBus_.get().addHandler(ChunkPlotRefreshFinishedEvent.TYPE, this);
    pEventBus_.get().addHandler(ChunkChangeEvent.TYPE, this);
    pEventBus_.get().addHandler(RmdChunkOutputFinishedEvent.TYPE, this);
    pEventBus_.get().addHandler(RmdChunkOutputEvent.TYPE, this);
    Window.addWindowClosingHandler(new ClosingHandler() {

        @Override
        public void onWindowClosing(ClosingEvent arg0) {
            server_.cleanReplayNotebookChunkPlots(chunkWindowParams_.getDocId(), chunkWindowParams_.getChunkId(), new ServerRequestCallback<Void>() {

                @Override
                public void onError(ServerError error) {
                }
            });
        }
    });
    pEventBus_.get().fireEventToMainWindow(new ChunkSatelliteWindowOpenedEvent(chunkWindowParams_.getDocId(), chunkWindowParams_.getChunkId()));
}
Also used : ChunkSatelliteWindowOpenedEvent(org.rstudio.studio.client.workbench.views.source.editors.text.events.ChunkSatelliteWindowOpenedEvent) ChunkOutputHost(org.rstudio.studio.client.workbench.views.source.editors.text.rmd.ChunkOutputHost) ServerError(org.rstudio.studio.client.server.ServerError) Element(com.google.gwt.dom.client.Element) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) ClosingEvent(com.google.gwt.user.client.Window.ClosingEvent) ClosingHandler(com.google.gwt.user.client.Window.ClosingHandler)

Aggregations

Element (com.google.gwt.dom.client.Element)340 DivElement (com.google.gwt.dom.client.DivElement)19 TableRowElement (com.google.gwt.dom.client.TableRowElement)19 NativeEvent (com.google.gwt.dom.client.NativeEvent)16 Test (org.junit.Test)14 EventTarget (com.google.gwt.dom.client.EventTarget)11 SVGSVGElement (elemental.svg.SVGSVGElement)11 InputElement (com.google.gwt.dom.client.InputElement)10 Node (com.google.gwt.dom.client.Node)9 TableCellElement (com.google.gwt.dom.client.TableCellElement)9 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)8 AnchorElement (com.google.gwt.dom.client.AnchorElement)8 ImageElement (com.google.gwt.dom.client.ImageElement)8 LabelElement (com.google.gwt.dom.client.LabelElement)8 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)8 Image (com.google.gwt.user.client.ui.Image)8 SpanElement (com.google.gwt.dom.client.SpanElement)7 Style (com.google.gwt.dom.client.Style)7 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)7 Widget (com.google.gwt.user.client.ui.Widget)7