@Override public void setCampaignList(List<Campaign> campaignList) { int i = 0; TableSectionElement tbody = campaignTable.getTBodies().getItem(0); for (final Campaign cam : campaignList) { TableRowElement tr = tbody.insertRow(i); tr.setAttribute("class", "items"); TableCellElement tdName = tr.insertCell(0); tdName.setInnerText(cam.getTitle()); TableCellElement tdCat = tr.insertCell(1); tdCat.setAttribute("class", "text-right color-success"); tdCat.setInnerText(cam.getTags().get(0)); TableCellElement tcDate = tr.insertCell(2); tcDate.setInnerText(cam.getDate()); TableCellElement tcOp = tr.insertCell(3); tcOp.setClassName("text-center"); AnchorElement aEdit = Document.get().createAnchorElement(); aEdit.setClassName("label label-default"); aEdit.setInnerHTML("<i class=\"fa fa-pencil\"></i>"); AnchorElement aDel = Document.get().createAnchorElement(); aDel.setClassName("label label-danger"); aDel.setInnerHTML("<i class=\"fa fa-times\"></i>"); tcOp.appendChild(aEdit); tcOp.appendChild(aDel); Event.sinkEvents(aEdit, Event.ONCLICK); Event.setEventListener( aEdit, new EventListener() { @Override public void onBrowserEvent(Event event) { System.out.println("ok"); if (Event.ONCLICK == event.getTypeInt()) { listener.goTo(new EditCampaignPlace("", cam)); } } }); Event.sinkEvents(aDel, Event.ONCLICK); Event.setEventListener( aDel, new EventListener() { @Override public void onBrowserEvent(Event event) { if (Event.ONCLICK == event.getTypeInt()) { Window.alert("Borrar " + cam.getTitle()); } } }); i++; } }
@Override public void sinkEvents() { Element dashBoardView = DOM.getElementById("dashBoardView"); Event.sinkEvents(dashBoardView, Event.ONCLICK); Event.setEventListener( dashBoardView, new EventListener() { @Override public void onBrowserEvent(Event event) { if (Event.ONCLICK == event.getTypeInt()) { listener.goTo(new DashBoardPlace("")); } } }); Element beaconsView = DOM.getElementById("beaconsView"); Event.sinkEvents(beaconsView, Event.ONCLICK); Event.setEventListener( beaconsView, new EventListener() { @Override public void onBrowserEvent(Event event) { if (Event.ONCLICK == event.getTypeInt()) { listener.goTo(new BeaconsPlace("")); } } }); Element campaignView = DOM.getElementById("campaignView"); Event.sinkEvents(campaignView, Event.ONCLICK); Event.setEventListener( campaignView, new EventListener() { @Override public void onBrowserEvent(Event event) { if (Event.ONCLICK == event.getTypeInt()) { listener.goTo(new CampaignPlace("")); } } }); Element beacon = DOM.getElementById("beacon"); Event.sinkEvents(beacon, Event.ONCLICK); Event.setEventListener( beacon, new EventListener() { @Override public void onBrowserEvent(Event event) { if (Event.ONCLICK == event.getTypeInt()) { listener.goTo(new BeaconsPlace("")); } } }); }
@Override protected void gwtSetUp() throws Exception { parent = Document.get().createDivElement(); child = Document.get().createTextInputElement(); img = Document.get().createImageElement(); Document.get().getBody().appendChild(parent); parent.appendChild(child); parent.appendChild(img); Event.sinkEvents(parent, ALL_EVENTS); Event.sinkEvents(child, ALL_EVENTS); Event.sinkEvents(img, ALL_EVENTS); }
@Override public void sinkEvents(int eventBitsToAdd) { // Sink on the actual element because that's what gets clicked if (isOrWasAttached()) { Event.sinkEvents(getElement(), eventBitsToAdd | Event.getEventsSunk(getElement())); } else { super.sinkEvents(eventBitsToAdd); } }
// Trigger a test failure synchronously, but from within an event handler. // (The exception thrown from fail() will get caught by the GWT // UncaughtExceptionHandler). private void synchronousFailure(final String failMsg) { ButtonElement btn = Document.get().createButtonElement(); Document.get().getBody().appendChild(btn); Event.sinkEvents(btn, Event.ONCLICK); EventListener listener = new EventListener() { public void onBrowserEvent(Event event) { failNow(failMsg); } }; DOM.setEventListener(btn.<com.google.gwt.user.client.Element>cast(), listener); btn.click(); }
protected void failViaUncaughtException(final String failMsg) { ButtonElement btn = Document.get().createPushButtonElement(); Document.get().getBody().appendChild(btn); Event.sinkEvents(btn, Event.ONCLICK); EventListener listener = new EventListener() { @Override public void onBrowserEvent(Event event) { failNow(failMsg); } }; DOM.setEventListener(btn, listener); btn.click(); }
/** * Test {@link Cell#onBrowserEvent(Element, Object, Object, NativeEvent, ValueUpdater)} with the * specified conditions. * * @param cell the cell to use * @param startHtml the innerHTML of the cell before the test starts * @param event the event to fire * @param value the cell value * @param expectedValue the expected value passed to the value updater, or null if none expected * @param dispatchToFirstChild true to dispatch to the first child of the rendered parent element, * if one is available * @return the parent element */ protected Element testOnBrowserEvent( final Cell<T> cell, String startHtml, NativeEvent event, final T value, T expectedValue, boolean dispatchToFirstChild) { // Setup the parent element. final Element parent = Document.get().createDivElement(); parent.setInnerHTML(startHtml); Document.get().getBody().appendChild(parent); // If the element has a child, use it as the event target. Element target = parent; if (dispatchToFirstChild) { Element child = parent.getFirstChildElement(); target = (child == null) ? parent : child; } // Pass the event to the cell. final MockValueUpdater valueUpdater = new MockValueUpdater(); Event.setEventListener( parent, new EventListener() { public void onBrowserEvent(Event event) { try { DOM.setEventListener(parent, null); Context context = new Context(0, 0, DEFAULT_KEY); cell.onBrowserEvent(context, parent, value, event, valueUpdater); parent.removeFromParent(); } catch (Exception e) { // We are in an event loop, so events may not propagate out to JUnit. fail("An exception occured while handling the event: " + e.getMessage()); } } }); Event.sinkEvents(target, Event.getTypeInt(event.getType())); target.dispatchEvent(event); assertNull(DOM.getEventListener(parent)); // Check the expected value and view data. valueUpdater.assertLastValue(expectedValue); return parent; }
public EventListener acquireLockOnDemand(final Element element) { Event.sinkEvents(element, lockDemandDetector.getLockDemandEventTypes()); EventListener lockDemandListener = new EventListener() { @Override public void onBrowserEvent(Event event) { if (isLockedByCurrentUser()) { return; } if (lockDemandDetector.isLockRequired(event)) { acquireLock(); } } }; Event.setEventListener(element, lockDemandListener); return lockDemandListener; }