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