Search in sources :

Example 81 with Element

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

the class HeaderPart method convertItemToOpenable.

private Element convertItemToOpenable(String key, SafeHtml title) {
    activateItem(key, false, this::getItem);
    Element element = getItem(key);
    ensureItems().remove(key);
    element.setClassName("dropdown");
    final AnchorElement a = AnchorElement.as(element.getFirstChildElement());
    a.removeAttribute("href");
    Event.sinkEvents(a, Event.ONCLICK);
    Event.setEventListener(a, new EventListener() {

        @Override
        public void onBrowserEvent(Event event) {
            openableClick(a);
            event.stopPropagation();
        }
    });
    a.addClassName("dropdown-toggle");
    a.setInnerSafeHtml(title);
    Element ul = Document.get().createULElement();
    ul.addClassName("dropdown-menu");
    element.appendChild(ul);
    ensureOpenables().put(key, element);
    return element;
}
Also used : Element(com.google.gwt.dom.client.Element) AnchorElement(com.google.gwt.dom.client.AnchorElement) ImageElement(com.google.gwt.dom.client.ImageElement) AnchorElement(com.google.gwt.dom.client.AnchorElement) Event(com.google.gwt.user.client.Event) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) EventListener(com.google.gwt.user.client.EventListener)

Example 82 with Element

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

the class HeaderPart method addItem.

private void addItem(Element parent, SafeHtml title, SafeUri href) {
    String key = href.asString().replaceFirst("#", "");
    Element element = getItem(key);
    if (element == null) {
        element = Document.get().createLIElement();
        final AnchorElement a = Document.get().createAnchorElement();
        a.setHref(href);
        element.appendChild(a);
        a.setInnerSafeHtml(title);
        parent.appendChild(element);
        ensureItems().put(key, element);
    }
}
Also used : Element(com.google.gwt.dom.client.Element) AnchorElement(com.google.gwt.dom.client.AnchorElement) ImageElement(com.google.gwt.dom.client.ImageElement) AnchorElement(com.google.gwt.dom.client.AnchorElement)

Example 83 with Element

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

the class PostHelper method handlePluginContentReady.

/**
 * @return
 */
public static HandlerRegistration handlePluginContentReady() {
    return processor().addPluginContentReadyHandler((event, plugin, lines, params, id, content) -> {
        Element el = Document.get().getElementById(id);
        if (plugin instanceof IncludePlugin || plugin instanceof PostsPlugin) {
            if (el != null && content != null) {
                el.setInnerHTML(content);
            }
        } else if (plugin instanceof MapPlugin) {
            if (el != null) {
                MapHelper.showMap(el, lines, params);
            }
        } else if (plugin instanceof FormPlugin) {
            if (el != null && content != null) {
                el.removeAllChildren();
                // FIXME: probably leaking this
                // on unload never seems to get called
                Widget form = FormPlugin.createWidget(lines, params);
                RootPanel.get().add(form);
                el.appendChild(form.getElement());
            }
        }
    });
}
Also used : MapPlugin(com.willshex.blogwt.client.markdown.plugin.MapPlugin) Element(com.google.gwt.dom.client.Element) IncludePlugin(org.markdown4j.client.IncludePlugin) Widget(com.google.gwt.user.client.ui.Widget) PostsPlugin(com.willshex.blogwt.client.markdown.plugin.PostsPlugin) FormPlugin(com.willshex.blogwt.client.markdown.plugin.FormPlugin)

Example 84 with Element

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

the class AbstractVerticalMergableGridWidget method makeTableCellElement.

// Build a TableCellElement
@SuppressWarnings("rawtypes")
private TableCellElement makeTableCellElement(int iCol, DynamicDataRow rowData) {
    TableCellElement tce = null;
    // Column to handle rendering
    DynamicColumn<T> column = columns.get(iCol);
    CellValue<? extends Comparable<?>> cellData = rowData.get(iCol);
    int rowSpan = cellData.getRowSpan();
    if (rowSpan > 0) {
        // Use Elements rather than Templates as it's easier to set attributes that need to be dynamic
        tce = Document.get().createTDElement();
        DivElement div = Document.get().createDivElement();
        DivElement divText = Document.get().createDivElement();
        tce.addClassName(resources.cellTableCell());
        tce.addClassName(resources.cellTableColumn(column.getModelColumn()));
        div.setClassName(resources.cellTableCellDiv());
        divText.addClassName(resources.cellTableTextDiv());
        // Set widths
        int colWidth = column.getWidth();
        div.getStyle().setWidth(colWidth, Unit.PX);
        divText.getStyle().setWidth(colWidth, Unit.PX);
        tce.getStyle().setWidth(colWidth, Unit.PX);
        // Set heights, TD includes border, DIV does not
        int divHeight = cellHeightCalculator.calculateHeight(rowSpan);
        div.getStyle().setHeight(divHeight, Unit.PX);
        tce.setRowSpan(rowSpan);
        // Styling depending upon state
        if (cellData.isOtherwise()) {
            tce.addClassName(resources.cellTableCellOtherwise());
        } else {
            tce.removeClassName(resources.cellTableCellOtherwise());
        }
        if (cellData instanceof CellValue.GroupedCellValue) {
            CellValue.GroupedCellValue gcv = (CellValue.GroupedCellValue) cellData;
            if (gcv.hasMultipleValues()) {
                tce.addClassName(resources.cellTableCellMultipleValues());
            }
        } else {
            tce.removeClassName(resources.cellTableCellMultipleValues());
        }
        if (cellData.isSelected()) {
            tce.addClassName(resources.cellTableCellSelected());
        } else {
            tce.removeClassName(resources.cellTableCellSelected());
        }
        // Render the cell and set inner HTML
        SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
        if (!cellData.isOtherwise()) {
            Coordinate c = cellData.getCoordinate();
            Context context = new Context(c.getRow(), c.getCol(), c);
            column.render(context, rowData, cellBuilder);
        } else {
            cellBuilder.appendEscaped("<otherwise>");
        }
        divText.setInnerHTML(cellBuilder.toSafeHtml().asString());
        // Construct the table
        tce.appendChild(div);
        div.appendChild(divText);
        tce.setTabIndex(0);
        // Add on "Grouping" widget, if applicable
        if (rowSpan > 1 || cellData.isGrouped()) {
            Element de = DOM.createDiv();
            DivElement divGroup = DivElement.as(de);
            divGroup.setTitle(Constants.INSTANCE.groupCells());
            divGroup.addClassName(resources.cellTableGroupDiv());
            if (cellData.isGrouped()) {
                divGroup.setInnerHTML(selectorUngroupedCellsHtml);
            } else {
                divGroup.setInnerHTML(selectorGroupedCellsHtml);
            }
            div.appendChild(divGroup);
        }
    }
    return tce;
}
Also used : Context(com.google.gwt.cell.client.Cell.Context) 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) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) DivElement(com.google.gwt.dom.client.DivElement) GWT(com.google.gwt.core.client.GWT) Coordinate(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.Coordinate) TableCellElement(com.google.gwt.dom.client.TableCellElement)

Example 85 with Element

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

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