/** * Called when an event occurs in a rendered instance of this Cell. The parent element refers to * the element that contains the rendered cell, NOT to the outermost element that the Cell * rendered. */ @Override public void onBrowserEvent( com.google.gwt.cell.client.Cell.Context context, Element parent, String value, NativeEvent event, com.google.gwt.cell.client.ValueUpdater<String> valueUpdater) { // Let AbstractCell handle the keydown event. super.onBrowserEvent(context, parent, value, event, valueUpdater); // Handle the click event. if ("click".equals(event.getType())) { // Ignore clicks that occur outside of the outermost element. EventTarget eventTarget = event.getEventTarget(); if (parent.isOrHasChild(Element.as(eventTarget))) { // if (parent.getFirstChildElement().isOrHasChild( // Element.as(eventTarget))) { // use this to get the selected element!! Element el = Element.as(eventTarget); // check if we really click on the image if (callback != null && el.getNodeName().equalsIgnoreCase("IMG")) { final String s = el.getParentElement().getAttribute("name"); final KieContainer container = containersProvider.getContainer(value); final boolean isUp = SharedUtils.getContainerStatus(container); final boolean isKieApp = container.getType() != null && KieImageCategory.KIEAPP.equals(container.getType().getCategory()); if (ContainerActionsCell.PLAY.equals(s) && !isUp) { callback.onStart(container); } else if (ContainerActionsCell.STOP.equals(s) && isUp) { callback.onStop(container); } else if (ContainerActionsCell.RELOAD.equals(s) && isUp) { callback.onRestart(container); } else if (ContainerActionsCell.REMOVE.equals(s)) { callback.onRemove(container); } else if (ContainerActionsCell.VIEW_LOGS.equals(s)) { callback.onViewLogs(container); } else if (ContainerActionsCell.VIEW_DETAILS.equals(s) && isUp && isKieApp) { callback.onViewDetails(container); } else if (ContainerActionsCell.NAVIGATE.equals(s) && isUp && isKieApp) { callback.onNavigate(container); } } } } };
@Override protected void render( com.google.gwt.cell.client.Cell.Context context, SafeHtml data, SafeHtmlBuilder sb) { /* * Always do a null check on the value. Cell widgets can pass null to * cells if the underlying data contains a null, or if the data arrives * out of order. */ if (data == null) { return; } final KieContainer container = containersProvider.getContainer(data.asString()); final boolean isUp = SharedUtils.getContainerStatus(container); final boolean isKieApp = container.getType() != null && KieImageCategory.KIEAPP.equals(container.getType().getCategory()); // If the value comes from the user, we escape it to avoid XSS attacks. // SafeHtml safeValue = SafeHtmlUtils.fromString(data.asString()); // Use the template to create the Cell's html. // SafeStyles styles = SafeStylesUtils.fromTrustedString(safeValue // .asString()); // generate the image cell SafeHtml rendered = templates.cell( PLAY, isUp ? disabledStyle : enabledStyle, ICON_PLAY, Constants.INSTANCE.start()); sb.append(rendered); /* -- Disabled STOP container button, as it sometimes fails from the Docker remote API. -- rendered = templates.cell(STOP, isUp ? enabledStyle : disabledStyle, ICON_STOP, Constants.INSTANCE.stop()); sb.append(rendered); */ rendered = templates.cell( RELOAD, isUp ? enabledStyle : disabledStyle, ICON_RELOAD, Constants.INSTANCE.restart()); sb.append(rendered); rendered = templates.cell(REMOVE, enabledStyle, ICON_REMOVE, Constants.INSTANCE.remove()); sb.append(rendered); rendered = templates.cell(VIEW_LOGS, enabledStyle, ICON_VIEW_LOGS, Constants.INSTANCE.viewLogs()); sb.append(rendered); if (isKieApp) { rendered = templates.cell( VIEW_DETAILS, isUp ? enabledStyle : disabledStyle, ICON_VIEW_DETAILS, Constants.INSTANCE.viewDetails()); sb.append(rendered); rendered = templates.cell( NAVIGATE, isUp ? enabledStyle : disabledStyle, ICON_NAVIGATE, Constants.INSTANCE.navigate()); sb.append(rendered); } }