Java Code Examples for com.google.gwt.dom.client.Document#get()

The following examples show how to use com.google.gwt.dom.client.Document#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewComponentClientCriterionTest.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Test
@Description("Exception occures when processing serialized data structure for preparing the drop targets to show.")
public void exceptionWhenProcessingDropTargetHintsDataStructure() {
    final ViewComponentClientCriterion cut = new ViewComponentClientCriterion();

    // prepare configuration:
    final Document document = Document.get();
    final UIDL uidl = GWT.create(UIDL.class);
    when(uidl.getIntAttribute("cda")).thenReturn(2);
    when(uidl.getStringAttribute("da0")).thenReturn("no-problem");
    when(uidl.getStringAttribute("da1")).thenReturn("problem-bear");
    doThrow(new RuntimeException()).when(uidl).getStringAttribute("da1");

    // act
    try {
        cut.showDropTargetHints(uidl);
    } catch (final RuntimeException re) {
        fail("Exception is not re-thrown in order to continue with the loop");
    }

    // assure that no-problem was invoked anyway
    verify(document).getElementById("no-problem");

    // cross-check that problem-bear was never invoked
    verify(document, Mockito.times(0)).getElementById("problem-bear");
}
 
Example 2
Source File: ViewClientCriterionTest.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Test
@Description("Check multi row drag decoration with non-table widget")
public void processMultiRowDragDecorationNonTable() {
    final ViewClientCriterion cut = new ViewClientCriterion();

    // prepare drag-event with non table widget:
    final VDragAndDropWrapper nonTable = Mockito.mock(VDragAndDropWrapper.class);
    final VDragEvent dragEvent = CriterionTestHelper.createMockedVDragEvent("thisId", nonTable);
    final Document document = Document.get();

    // act
    cut.setMultiRowDragDecoration(dragEvent);

    // assure that multi-row decoration processing was skipped
    verify(document, Mockito.never()).getElementById(ViewClientCriterion.SP_DRAG_COUNT);
}
 
Example 3
Source File: MockForm.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private static int getVerticalScrollbarWidth() {
  // We only calculate the vertical scroll bar width once, then we store it in the static field
  // verticalScrollbarWidth. If the field is non-zero, we don't need to calculate it again.
  if (verticalScrollbarWidth == 0) {
    // The following code will calculate (on the fly) the width of a vertical scroll bar.
    // We'll create two divs, one inside the other and add the outer div to the document body,
    // but off-screen where the user won't see it.
    // We'll measure the width of the inner div twice: (first) when the outer div's vertical
    // scrollbar is hidden and (second) when the outer div's vertical scrollbar is visible.
    // The width of inner div will be smaller when outer div's vertical scrollbar is visible.
    // By subtracting the two measurements, we can calculate the width of the vertical scrollbar.

    // I used code from the following websites as reference material:
    // http://jdsharp.us/jQuery/minute/calculate-scrollbar-width.php
    // http://www.fleegix.org/articles/2006-05-30-getting-the-scrollbar-width-in-pixels

    Document document = Document.get();

    // Create an outer div.
    DivElement outerDiv = document.createDivElement();
    Style outerDivStyle = outerDiv.getStyle();
    // Use absolute positioning and set the top/left so that it is off-screen.
    // We don't want the user to see anything while we do this calculation.
    outerDivStyle.setProperty("position", "absolute");
    outerDivStyle.setProperty("top", "-1000px");
    outerDivStyle.setProperty("left", "-1000px");
    // Set the width and height of the outer div to a fixed size in pixels.
    outerDivStyle.setProperty("width", "100px");
    outerDivStyle.setProperty("height", "50px");
    // Hide the outer div's scrollbar by setting the "overflow" property to "hidden".
    outerDivStyle.setProperty("overflow", "hidden");

    // Create an inner div and put it inside the outer div.
    DivElement innerDiv = document.createDivElement();
    Style innerDivStyle = innerDiv.getStyle();
    // Set the height of the inner div to be 4 times the height of the outer div so that a
    // vertical scrollbar will be necessary (but hidden for now) on the outer div.
    innerDivStyle.setProperty("height", "200px");
    outerDiv.appendChild(innerDiv);

    // Temporarily add the outer div to the document body. It's off-screen so the user won't
    // actually see anything.
    Element bodyElement = document.getElementsByTagName("body").getItem(0);
    bodyElement.appendChild(outerDiv);

    // Get the width of the inner div while the outer div's vertical scrollbar is hidden.
    int widthWithoutScrollbar = innerDiv.getOffsetWidth();
    // Show the outer div's vertical scrollbar by setting the "overflow" property to "auto".
    outerDivStyle.setProperty("overflow", "auto");
    // Now, get the width of the inner div while the vertical scrollbar is visible.
    int widthWithScrollbar = innerDiv.getOffsetWidth();

    // Remove the outer div from the document body.
    bodyElement.removeChild(outerDiv);

    // Calculate the width of the vertical scrollbar by subtracting the two widths.
    verticalScrollbarWidth = widthWithoutScrollbar - widthWithScrollbar;
  }

  return verticalScrollbarWidth;
}
 
Example 4
Source File: VDragCaptionProvider.java    From cuba with Apache License 2.0 5 votes vote down vote up
public Element getDragCaptionElement(Widget w) {
    ComponentConnector component = Util.findConnectorFor(w);
    DDLayoutState state = ((DragAndDropAwareState) root.getState()).getDragAndDropState();
    DragCaptionInfo dci = state.dragCaptions.get(component);

    Document document = Document.get();

    Element dragCaptionImage = document.createDivElement();
    Element dragCaption = document.createSpanElement();

    String dragCaptionText = dci.caption;
    if (dragCaptionText != null) {
        if (dci.contentMode == ContentMode.TEXT) {
            dragCaption.setInnerText(dragCaptionText);
        } else if (dci.contentMode == ContentMode.HTML) {
            dragCaption.setInnerHTML(dragCaptionText);
        } else if (dci.contentMode == ContentMode.PREFORMATTED) {
            PreElement preElement = document.createPreElement();
            preElement.setInnerText(dragCaptionText);
            dragCaption.appendChild(preElement);
        }
    }

    String dragIconKey = state.dragCaptions.get(component).iconKey;
    if (dragIconKey != null) {
        String resourceUrl = root.getResourceUrl(dragIconKey);
        Icon icon = component.getConnection().getIcon(resourceUrl);
        dragCaptionImage.appendChild(icon.getElement());
    }

    dragCaptionImage.appendChild(dragCaption);

    return dragCaptionImage;
}
 
Example 5
Source File: ViewComponentClientCriterionTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@Description("Process serialized data structure for preparing the drop targets to show.")
public void processSerializedDropTargetHintsDataStructure() {
    final ViewComponentClientCriterion cut = new ViewComponentClientCriterion();

    // prepare configuration:
    final Document document = Document.get();
    final UIDL uidl = GWT.create(UIDL.class);
    when(uidl.getIntAttribute("cda")).thenReturn(3);
    final Element[] elements = new Element[3];
    for (int i = 0; i < 3; i++) {
        when(uidl.getStringAttribute("da" + String.valueOf(i))).thenReturn("itemId" + String.valueOf(i));
        elements[i] = Mockito.mock(Element.class);
        when(document.getElementById("itemId" + String.valueOf(i))).thenReturn(elements[i]);
    }

    // act
    cut.showDropTargetHints(uidl);

    // assure invocation
    for (int i = 0; i < 3; i++) {
        verify(document).getElementById("itemId" + String.valueOf(i));
        verify(elements[i]).addClassName(ViewComponentClientCriterion.HINT_AREA_STYLE);
    }

    // cross-check
    verify(document, Mockito.times(0)).getElementById("itemId3");

}
 
Example 6
Source File: ViewClientCriterionTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@Description("Process serialized config for hiding the drop hints.")
public void processSerializedDropTargetHintsConfig() {
    final ViewClientCriterion cut = new ViewClientCriterion();

    // prepare configuration:
    final Document document = Document.get();
    final UIDL uidl = GWT.create(UIDL.class);
    when(uidl.getIntAttribute("cdac")).thenReturn(3);
    final Element[] elements = new Element[3];
    for (int i = 0; i < 3; i++) {
        when(uidl.getStringAttribute("dac" + String.valueOf(i))).thenReturn("itemId" + String.valueOf(i));
        elements[i] = Mockito.mock(Element.class);
        when(document.getElementById("itemId" + String.valueOf(i))).thenReturn(elements[i]);
    }

    // act
    try {
        cut.hideDropTargetHints(uidl);

        // assure invocation
        for (int i = 0; i < 3; i++) {
            verify(document).getElementById("itemId" + String.valueOf(i));
            verify(elements[i]).removeClassName(ViewComponentClientCriterion.HINT_AREA_STYLE);
        }

        // cross-check
        verify(document, Mockito.never()).getElementById("itemId3");

    } finally {
        reset(Document.get());
    }
}
 
Example 7
Source File: ViewClientCriterionTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@Description("Exception occures when processing serialized config for hiding the drop hints.")
public void exceptionWhenProcessingDropTargetHintsDataStructure() {
    final ViewClientCriterion cut = new ViewClientCriterion();

    // prepare configuration:
    final Document document = Document.get();
    final UIDL uidl = GWT.create(UIDL.class);
    when(uidl.getIntAttribute("cdac")).thenReturn(2);
    when(uidl.getStringAttribute("dac0")).thenReturn("no-problem");
    when(uidl.getStringAttribute("dac1")).thenReturn("problem-bear");
    doThrow(new RuntimeException()).when(uidl).getStringAttribute("dac1");

    // act
    try {
        cut.hideDropTargetHints(uidl);

        // assure that no-problem was invoked anyway
        verify(document).getElementById("no-problem");

        // cross-check that problem-bear was never invoked
        verify(document, Mockito.never()).getElementById("problem-bear");
    } catch (final RuntimeException re) {
        fail("Exception is not re-thrown in order to continue with the loop");
    } finally {
        reset(Document.get());
    }
}
 
Example 8
Source File: ViewClientCriterionTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@Description("Check multi row drag decoration with single selection")
public void processMultiRowDragDecorationSingleSelection() {
    final ViewClientCriterion cut = new ViewClientCriterion();

    // prepare table
    final VScrollTable table = Mockito.spy(new VScrollTable());
    table.selectedRowKeys.add("one");

    // prepare drag-event with table widget:
    final VDragEvent dragEvent = CriterionTestHelper.createMockedVDragEvent("thisId", table);

    // prepare document
    final Document document = Document.get();
    final Element ele = Mockito.mock(Element.class);
    when(document.getElementById(ViewClientCriterion.SP_DRAG_COUNT)).thenReturn(ele);

    try {
        // act
        cut.setMultiRowDragDecoration(dragEvent);

        // assure that multi-row decoration for the table was processed
        verify(document).getElementById(ViewClientCriterion.SP_DRAG_COUNT);

        // assure that no multi selection was detected
        verify(ele).removeFromParent();
    } finally {
        reset(Document.get());
    }
}
 
Example 9
Source File: ViewClientCriterionTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@Description("Check multi row drag decoration with a single item dragged while a multi selection is active in table")
public void processMultiRowDragDecorationMultiSelectionNotDragged() {
    final ViewClientCriterion cut = new ViewClientCriterion();

    // prepare table
    final VScrollTable table = Mockito.spy(new VScrollTable());
    table.selectedRowKeys.add("one");
    table.selectedRowKeys.add("two");
    table.focusedRow = Mockito.mock(VScrollTable.VScrollTableBody.VScrollTableRow.class);
    when(table.focusedRow.getKey()).thenReturn("another");

    // prepare drag-event with table widget:
    final VDragEvent dragEvent = CriterionTestHelper.createMockedVDragEvent("thisId", table);

    // prepare document
    final Document document = Document.get();
    final Element ele = Mockito.mock(Element.class);
    when(document.getElementById(ViewClientCriterion.SP_DRAG_COUNT)).thenReturn(ele);

    try {
        // act
        cut.setMultiRowDragDecoration(dragEvent);

        // assure that multi-row decoration for the table was processed
        verify(document).getElementById(ViewClientCriterion.SP_DRAG_COUNT);

        // assure that no multi selection was detected
        verify(ele).removeFromParent();
    } finally {
        reset(Document.get());
    }
}
 
Example 10
Source File: ViewClientCriterionTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@Description("Check multi row drag decoration with a valid multi selection")
public void processMultiRowDragDecorationMultiSelection() {
    final ViewClientCriterion cut = new ViewClientCriterion();

    // prepare table
    final VScrollTable table = Mockito.spy(new VScrollTable());
    table.selectedRowKeys.add("one");
    table.selectedRowKeys.add("two");
    table.focusedRow = Mockito.mock(VScrollTable.VScrollTableBody.VScrollTableRow.class);
    when(table.focusedRow.getKey()).thenReturn("one");

    // prepare drag-event with table widget:
    final VDragEvent dragEvent = CriterionTestHelper.createMockedVDragEvent("thisId", table, "myTheme");
    dragEvent.getTransferable().getDragSource().getConnection().getUIConnector();

    // prepare document
    final Document document = Document.get();
    final StyleElement ele = Mockito.spy(StyleElement.class);
    when(ele.getTagName()).thenReturn(StyleElement.TAG);
    when(document.getElementById(ViewClientCriterion.SP_DRAG_COUNT)).thenReturn(ele);

    try {
        // act
        cut.setMultiRowDragDecoration(dragEvent);

        // assure that multi-row decoration for the table was processed
        verify(document).getElementById(ViewClientCriterion.SP_DRAG_COUNT);

        // assure that no multi selection was detected
        verify(ele).setInnerSafeHtml(any(SafeHtml.class));
    } finally {
        reset(Document.get());
    }
}
 
Example 11
Source File: DocumentTitle.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onAttachOrDetach(AttachEvent event) {
	Document doc = Document.get();
	if (event.isAttached()) {
		fromTitle = doc.getTitle();
		doc.setTitle(title);
	} else {
		doc.setTitle(fromTitle);
	}
}
 
Example 12
Source File: PlaceHandler.java    From lumongo with Apache License 2.0 5 votes vote down vote up
private void initGA() {
	Document doc = Document.get();
	ScriptElement script = doc.createScriptElement();
	script.setSrc("https://ssl.google-analytics.com/ga.js");
	script.setType("text/javascript");
	script.setLang("javascript");
	doc.getBody().appendChild(script);
}
 
Example 13
Source File: PlaceHandler.java    From lumongo with Apache License 2.0 4 votes vote down vote up
public static void setBrowserWindowTitle(String newTitle) {
	if (Document.get() != null) {
		Document.get().setTitle(newTitle);
	}
}