private void scrollToSelectedRow() { int row = iTable.getSelectedRow(); if (row < 0) return; Element scroll = iScroll.getElement(); Element item = iTable.getRowFormatter().getElement(iTable.getSelectedRow()); if (item==null) return; int realOffset = 0; while (item !=null && !item.equals(scroll)) { realOffset += item.getOffsetTop(); item = item.getOffsetParent(); } scroll.setScrollTop(realOffset - scroll.getOffsetHeight() / 2); }
private SubmitCompleteHandler getSubmitCompleteHandler() { return new SubmitCompleteHandler() { public void onSubmitComplete(final SubmitCompleteEvent event) { final Element label = DOM.createLabel(); label.setInnerHTML(event.getResults()); final String csvData = label.getInnerText(); if (hasError(csvData)) { showAlert("Error: " + csvData); } else { parseCsvData(csvData); autoMessageBox.hide(); } } private boolean hasError(final String contentFile) { return contentFile.startsWith("413") || contentFile.startsWith("500"); } }; }
protected void scrollToSelectedRow() { if (iCourses.getSelectedRow() < 0) return; Element scroll = iCoursesPanel.getElement(); com.google.gwt.dom.client.Element item = iCourses.getRowFormatter().getElement(iCourses.getSelectedRow()); if (item==null) return; int realOffset = 0; while (item !=null && !item.equals(scroll)) { realOffset += item.getOffsetTop(); item = item.getOffsetParent(); } scroll.setScrollTop(realOffset - scroll.getOffsetHeight() / 2); }
protected void scrollToSelectedRow() { if (iDegreePlanTable.getSelectedRow() < 0) return; Element scroll = iDegreePlanPanel.getElement(); com.google.gwt.dom.client.Element item = iDegreePlanTable.getRowFormatter().getElement(iDegreePlanTable.getSelectedRow()); if (item == null) return; int realOffset = 0; while (item !=null && !item.equals(scroll)) { realOffset += item.getOffsetTop(); item = item.getOffsetParent(); } scroll.setScrollTop(realOffset - scroll.getOffsetHeight() / 2); }
@Override public ViewSocket getAssessmentHeaderViewSocket() { Element element = getViewJs(extensionJsObject); Widget widget = null; if (element != null) { widget = new ElementWrapperWidget(element); } final Widget widget2 = widget; return new ViewSocket() { @Override public Widget getView() { return widget2; } }; }
public static Element getElementByVaadinWidget(Widget widget, VaadinWidgetType widgetType) { if (widgetType == null) { return widget.getElement(); } switch (widgetType) { case TEXTFIELD: return widget.getElement(); case DATEFIELD: return ((VAbstractTextualDate) widget).text.getElement(); case COMBOBOX: return ((VComboBox) widget).tb.getElement(); case CHECKBOXGROUP: // returning the outer div for styling purpose return widget.getElement(); case CHECKBOX: // returning the outer div for styling purpose return widget.getElement(); case NATIVESELECT: return ((VNativeSelect) widget).getListBox().getElement(); default: return widget.getElement(); } }
@Override public ViewSocket getAssessmentFooterViewSocket() { Element e = getViewJs(extensionJsObject); Widget w = null; if (e != null) w = new ElementWrapperWidget(e); final Widget w2 = w; return new ViewSocket() { @Override public Widget getView() { return w2; } }; }
public static void showHintForExam(final Element relativeObject, final Long examId, final Long periodId) { sLastLocationId = examId; sShowHint = true; RPC.execute(RoomInterface.PeriodPreferenceRequest.loadForExam(examId, null), new AsyncCallback<RoomInterface.PeriodPreferenceModel>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(RoomInterface.PeriodPreferenceModel result) { if (examId.equals(sLastLocationId) && sShowHint && result != null) { if (periodId != null) result.setAssignedPeriodId(periodId); GwtHint.showHint(relativeObject, content(result)); } } }); }
@Test public void setPropertyTest() { // prepare Map<String, String> propertyStyle = new HashMap<String, String>(); propertyStyle.put("lineWidth", "0"); propertyStyle.put("lineCap", "miter"); propertyStyle.put("lineJoin", "square"); propertyStyle.put("miterLimit", "3"); // test testObject.applyStyles(mock(Element.class), propertyStyle); verify(nativeStyleHelper, times(4)).applyProperty(any(Element.class), any(String.class), any(String.class)); for (Map.Entry<String, String> entry : propertyStyle.entrySet()) { verify(nativeStyleHelper).applyProperty(any(Element.class), Matchers.eq(entry.getKey()), Matchers.eq(entry.getValue())); } }
@Test public void callFunctionTest() { // prepare Map<String, String> propertyStyle = new HashMap<String, String>(); propertyStyle.put("lineWidth", "0"); propertyStyle.put("lineCap", "miter"); propertyStyle.put("lineJoin", "square"); propertyStyle.put("miterLimit", "3"); propertyStyle.put("fn-lineCap", "miter"); propertyStyle.put("fn-lineJoin", "square"); propertyStyle.put("fn-miterLimit", "3"); // test testObject.applyStyles(mock(Element.class), propertyStyle); verify(nativeStyleHelper, times(0)).callFunction(any(Element.class), any(String.class), any(String.class)); testObject.addFunctionToWhiteList("lineCap"); testObject.addFunctionToWhiteList("miterLimit"); testObject.applyStyles(mock(Element.class), propertyStyle); verify(nativeStyleHelper, times(2)).callFunction(any(Element.class), any(String.class), any(String.class)); }
public static void showHint(final Element relativeObject, final String instructorId, boolean includeNotAvailable, final String pattern) { sLastInstructorId = instructorId; RPC.execute(InstructorAvailabilityRequest.load(instructorId, includeNotAvailable), new AsyncCallback<InstructorAvailabilityModel>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(InstructorAvailabilityModel result) { if (pattern != null) result.setPattern(pattern); if (instructorId.equals(sLastInstructorId) && result != null) GwtHint.showHint(relativeObject, content(result)); } }); }
public void onBrowserEvent(final Event event) { Element td = getEventTargetCell(event); if (td==null) return; final Element tr = DOM.getParent(td); int col = DOM.getChildIndex(tr, td); Element body = DOM.getParent(tr); int row = DOM.getChildIndex(body, tr); Widget widget = getWidget(row, col); if (widget != null && widget instanceof UniTimeHeaderPanel) { super.onBrowserEvent(event); return; } switch (DOM.eventGetType(event)) { case Event.ONMOUSEOVER: getRowFormatter().addStyleName(row, "hover"); break; case Event.ONMOUSEOUT: getRowFormatter().removeStyleName(row, "hover"); break; } super.onBrowserEvent(event); }
private Element getInput() { if (VaadinWidgetType.CHECKBOX.equals(widgetType)) { // we want to apply aria attributes to the input / not the styling div return widgetElement.getFirstChildElement(); } else if (VaadinWidgetType.CHECKBOXGROUP.equals(widgetType)) { // just a reminder - CheckBoxGroup can have the describedby here because // the outer div has tabindex and is kinda like a fieldset for all inputs. return widgetElement; } // anything else return widgetElement; }
public int getRowForWidget(Widget w) { for (Element td = w.getElement(); td != null; td = DOM.getParent(td)) { if (td.getPropertyString("tagName").equalsIgnoreCase("td")) { Element tr = DOM.getParent(td); Element body = DOM.getParent(tr); if (body == getBodyElement()) return DOM.getChildIndex(body, tr); } if (td == getBodyElement()) { return -1; } } return -1; }
private native void openImageNative(String imageSrc, Element title) /*-{ $wnd.$.magnificPopup.open({ items: { src: imageSrc }, type: 'image', image: { titleSrc: function () { return title } }, closeOnContentClick: true }); }-*/;
private void swapRows(int r0, int r1) { if (r0 == r1) return; if (r0 > r1) { swapRows(r1, r0); } else { // r0 < r1 Element body = getBodyElement(); Element a = DOM.getChild(body, r0); Element b = DOM.getChild(body, r1); body.removeChild(a); body.removeChild(b); DOM.insertChild(body, b, r0); DOM.insertChild(body, a, r1); } }
void setDescription(String description, ContentMode contentMode) { Element element = getInput(); if (description == null || description.isEmpty() || description.trim().isEmpty()) { if (hasFeedback) { Roles.getTextboxRole().setAriaDescribedbyProperty(element, Id.of(this.feedback)); } else { Roles.getTextboxRole().removeAriaDescribedbyProperty(element); } small.setInnerHTML(isDescriptionHeightReservedIfEmpty ? " " : ""); hasDescription = false; return; } if (!hasDescription) { if (hasFeedback) { Roles.getTextboxRole().setAriaDescribedbyProperty(element, Id.of(small), Id.of(this.feedback)); } else { Roles.getTextboxRole().setAriaDescribedbyProperty(element, Id.of(small)); } hasDescription = true; } if (ContentMode.HTML == contentMode) { small.setInnerHTML(description); } else { small.setInnerText(description); } }
/** * Na androidzie podczas swipe gapy zle sie rysowaly nachodzac na siebie. * Pozbycie sie z nich focusa na czas swipe rozwiazalo problem */ private void dropFocus() { focusDropped = true; NodeList<Element> elementsByTagName = rootPanelDelegate.getBodyElement().getElementsByTagName("input"); for (int x = 0; x < elementsByTagName.getLength(); ++x) { elementsByTagName.getItem(x).blur(); } }
public TableEvent(Event sourceEvent, int row, int col, Element tr, Element td, T data) { iRow = row; iCol = col; iTR = tr; iTD = td; iData = data; iSourceEvent = sourceEvent; }
@Override public void onMouseDown(MouseDownEvent event) { startX = event.getClientX(); startY = event.getClientY(); if (isDisabled() || event.getNativeButton() != NativeEvent.BUTTON_LEFT) { return; } clickTarget = Element.as(event.getNativeEvent().getEventTarget()); mouseMoveCanceled = false; if ((weekGrid.getCalendar().isItemMoveAllowed() && getCalendarItem().isMoveable()) || (clickTargetsResize() && getCalendarItem().isResizeable())) { moveRegistration = addMouseMoveHandler(this); setFocus(true); try { startYrelative = (int) ((double) event.getRelativeY(caption) % slotHeight); startXrelative = (event.getRelativeX(weekGrid.getElement()) - weekGrid.timebar.getOffsetWidth()) % getDateCellWidth(); } catch (Exception e) { GWT.log("Exception calculating relative start position", e); } mouseMoveStarted = false; Style s = getElement().getStyle(); s.setZIndex(1000); startDatetimeFrom = (Date) calendarItem.getStartTime().clone(); startDatetimeTo = (Date) calendarItem.getEndTime().clone(); Event.setCapture(getElement()); } // make sure the right cursor is always displayed if (clickTargetsResize() && getCalendarItem().isResizeable()) { addGlobalResizeStyle(); } /* * We need to stop the event propagation or else the WeekGrid range * select will kick in */ event.stopPropagation(); event.preventDefault(); }
@Override public void init() { if (media != null) { Element audioElement = mediaDescriptor.getMediaObject().getElement(); configureMediaBase(); initExecutor(); setNativeListeners(audioElement); } }
private void setNativeListeners(Element audioElement) { ArrayList<HTML5MediaEventsType> eventTypes = Lists.newArrayList(HTML5MediaEventsType.canplay, HTML5MediaEventsType.suspend, HTML5MediaEventsType.ended, HTML5MediaEventsType.error, HTML5MediaEventsType.pause, HTML5MediaEventsType.play, HTML5MediaEventsType.volumechange, HTML5MediaEventsType.timeupdate, HTML5MediaEventsType.durationchange); for (HTML5MediaEventsType eventType : eventTypes) { html5MediaNativeListeners.addListener(audioElement, eventType.toString()); } }
private void centerMainPreloader(int x, int y, Element preloaderElement) { preloaderElement.setId(MAIN_PRELOADER_ID); preloaderElement.getStyle().setPosition(Style.Position.ABSOLUTE); int leftOffset = x - preloaderElement.getOffsetWidth() / 2; preloaderElement.getStyle().setLeft(leftOffset, Style.Unit.PX); int topOffset = y - preloaderElement.getOffsetHeight() / 2; preloaderElement.getStyle().setTop(topOffset, Style.Unit.PX); }
public int getYPositionRelativeToTarget(NativeEvent event, Element target) { Touch touch = getTouch(event); float positionY = 0;// hack dont change to int if (touch == null) { positionY = getRelativeY(event, target); } else { positionY = touch.getRelativeY(target); } return (int) positionY; }
private native static void nativeCopyToClipboard(Element e)/*-{ alert('here'); e.focus(); e.select(); $doc.execCommand('Copy'); alert('Copied'); }-*/;
/** * Hack for IE to not select text when dragging. * * @param e * The element to apply the hack on */ private native void blockSelect(Element e) /*-{ e.onselectstart = function() { return false; } e.ondragstart = function() { return false; } }-*/;
/** * Overridden to send ValueChangeEvents only when appropriate. */ @Override public void onBrowserEvent(Event event) { switch (DOM.eventGetType(event)) { case Event.ONMOUSEUP: case Event.ONBLUR: case Event.ONKEYDOWN: // Note the old value for onValueChange purposes (in ONCLICK case) oldValue = getValue(); break; case Event.ONCLICK: EventTarget target = event.getEventTarget(); if (Element.is(target) && labelElem.isOrHasChild(Element.as(target))) { // They clicked the label. Note our pre-click value, and // short circuit event routing so that other click handlers // don't hear about it oldValue = getValue(); return; } // It's not the label. Let our handlers hear about the // click... super.onBrowserEvent(event); // ...and now maybe tell them about the change ValueChangeEvent.fireIfNotEqual(AccessibleRadioButton.this, oldValue, getValue()); return; } super.onBrowserEvent(event); }
private native void createSwiffyObject(String iframeId, Element container)/*-{ var iframe = $doc.getElementById(iframeId); iframe.contentWindow.swiffyObject = iframe.contentWindow .getSwiffyObject(); iframe.contentWindow.swiffyStage = new iframe.contentWindow.swiffy.Stage( container, iframe.contentWindow.swiffyObject); }-*/;
/** * Creates a ListBox widget that wraps an existing <select> element. * <p/> * This element must already be attached to the document. If the element is removed from the document, you must call {@link RootPanel#detachNow(Widget)}. * * @param element the element to be wrapped * @return list box */ public static AccessibleListBox wrap(Element element) { // Assert that the element is attached. assert Document.get().getBody().isOrHasChild(element); AccessibleListBox listBox = new AccessibleListBox(element); // Mark it attached and remember it for cleanup. listBox.onAttach(); RootPanel.detachOnWindowClose(listBox); return listBox; }
@Override public void onMouseUp(MouseUpEvent event) { if (mouseMoveCanceled || event.getNativeButton() != NativeEvent.BUTTON_LEFT) { return; } Event.releaseCapture(getElement()); setFocus(false); if (moveRegistration != null) { moveRegistration.removeHandler(); moveRegistration = null; } int endX = event.getClientX(); int endY = event.getClientY(); int xDiff = 0, yDiff = 0; if (startX != -1 && startY != -1) { // Drag started xDiff = startX - endX; yDiff = startY - endY; } startX = -1; startY = -1; mouseMoveStarted = false; Style s = getElement().getStyle(); s.setZIndex(1); if (!clickTargetsResize()) { // check if mouse has moved over threshold of 3 pixels boolean mouseMoved = (xDiff < -3 || xDiff > 3 || yDiff < -3 || yDiff > 3); if (!weekGrid.getCalendar().isDisabled() && mouseMoved) { // Item Move: // - calendar must be enabled // - calendar must not be in read-only mode weekGrid.itemMoved(this); } else if (!weekGrid.getCalendar().isDisabled() && getCalendarItem().isClickable()) { // Item Click: // - calendar must be enabled (read-only is allowed) EventTarget et = event.getNativeEvent().getEventTarget(); Element e = Element.as(et); if (e == caption || e == eventContent || e.getParentElement() == caption) { if (weekGrid.getCalendar().getItemClickListener() != null) { weekGrid.getCalendar().getItemClickListener().itemClick(calendarItem); } } } } else { // click targeted resize bar removeGlobalResizeStyle(); if (weekGrid.getCalendar().getItemResizeListener() != null) { weekGrid.getCalendar().getItemResizeListener().itemResized(calendarItem); } dateCell.recalculateItemWidths(); } }
@Provides @Singleton public PositionHelper getPositionHelper() { PositionHelper helper = mock(PositionHelper.class); when(helper.getXPositionRelativeToTarget(Matchers.any(NativeEvent.class), Matchers.any(Element.class))).thenReturn(20); when(helper.getYPositionRelativeToTarget(Matchers.any(NativeEvent.class), Matchers.any(Element.class))).thenReturn(20); return helper; }
@Before public void init() { Widget widget = mock(Widget.class); com.google.gwt.user.client.Element viewElement = mock(com.google.gwt.user.client.Element.class); when(view.asWidget()).thenReturn(widget); when(widget.getElement()).thenReturn(viewElement); when(viewElement.getFirstChildElement()).thenReturn(scriptElement); }
public String getStackText(int index) { if (index >= getWidgetCount()) { return null; } Element tdWrapper = DOM.getChild((Element) DOM.getChild(body, index * 2), 0); return DOM.getFirstChild(tdWrapper).getInnerText(); }
@Override public void onBrowserEvent(Event event) { Element target = DOM.eventGetTarget(event); switch (DOM.eventGetType(event)) { case Event.ONMOUSEDOWN: boolean open = iFilterOpen.getElement().equals(target); boolean close = iFilterClose.getElement().equals(target); boolean clear = iFilterClear.getElement().equals(target); boolean filter = iFilter.getElement().equals(target); if (isFilterPopupShowing() || close) { hideFilterPopup(); } else if (open) { hideSuggestions(); showFilterPopup(); } if (clear) { iFilter.setText(""); removeAllChips(); setAriaLabel(toAriaString()); ValueChangeEvent.fire(FilterBox.this, getValue()); } if (!filter) { event.stopPropagation(); event.preventDefault(); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { iFilter.setFocus(true); } }); } break; } }
public static void showHint(final Element relativeObject, final long locationId, boolean eventAvailability) { sLastLocationId = locationId; sShowHint = true; RPC.execute(RoomInterface.RoomSharingRequest.load(locationId, eventAvailability), new AsyncCallback<RoomInterface.RoomSharingModel>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(RoomInterface.RoomSharingModel result) { if (locationId == sLastLocationId && sShowHint && result != null) GwtHint.showHint(relativeObject, content(result)); } }); }
public AriaCheckBox(Element elem) { super(elem); iAriaLabel = DOM.createLabel(); iAriaLabel.setId(DOM.createUniqueId()); iAriaLabel.setClassName("unitime-AriaLabel"); DOM.appendChild(getElement(), iAriaLabel); Roles.getCheckboxRole().setAriaLabelledbyProperty(elem, Id.of(iAriaLabel)); }
@PostConstruct private void initialize() { addDialogListener(); addCloseButtonHandler(); openProjectDialog.getUploadPanel().addSubmitCompleteHandler(new SubmitCompleteHandler() { public void onSubmitComplete(final SubmitCompleteEvent event) { final Element label = DOM.createLabel(); label.setInnerHTML(event.getResults()); final String jsonProject = label.getInnerText(); openProjectDialog.hide(); if (hasError(jsonProject)) { autoMessageBox.hide(); showAlert("Error: " + jsonProject); return; } projectLoader.load(jsonProject); autoMessageBox.hide(); } private boolean hasError(final String contentFile) { return contentFile.startsWith("413") || contentFile.startsWith("500") || contentFile.startsWith("204") || contentFile.startsWith("406"); } }); }
public AriaHiddenLabel(String text, boolean asHtml) { setElement((Element)DOM.createSpan()); setStyleName("unitime-AriaHiddenLabel"); if (text != null) { if (asHtml) setHTML(text); else setText(text); } }