com.google.gwt.dom.client.Document Java Examples

The following examples show how to use com.google.gwt.dom.client.Document. 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: AbstractDropdown.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void resetInner() {
	this.anchor.getElement().removeAllChildren();
	if (this.iconType != null) {
		Icon icon = new Icon();
		icon.setType(this.iconType);

		this.anchor.getElement().appendChild(icon.getElement());
	}
	if (this.label != null) {
		Text textElem = Document.get().createTextNode(this.label);
		this.anchor.getElement().appendChild(textElem);
	}
	Text spaceElem = Document.get().createTextNode(" ");
	this.anchor.getElement().appendChild(spaceElem);
	this.anchor.getElement().appendChild(this.caret);
}
 
Example #2
Source File: MapWidget.java    From unitime with Apache License 2.0 6 votes vote down vote up
public static void insert(final RootPanel panel) {
	RPC.execute(new MapPropertiesRequest(), new AsyncCallback<MapPropertiesInterface>() {
		@Override
		public void onFailure(Throwable caught) {
		}

		@Override
		public void onSuccess(MapPropertiesInterface result) {
			MapWidget map = MapWidget.createMap(TextBox.wrap(Document.get().getElementById("coordX")), TextBox.wrap(Document.get().getElementById("coordY")), result);
			if (map != null) {
				panel.add(map);
				panel.setVisible(true);
				map.onShow();
			}
		}
	});
}
 
Example #3
Source File: ConfigViewImpl.java    From bitcoin-transaction-explorer with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void setValue(final AdministratedApplicationConfig value, final boolean fireEvents) {
  for (int i = 0; i < connectorListBox.getItemCount(); i++) {
    if(connectorListBox.getValue(i).equals(value.getBlockchainSource().name())) {
      connectorListBox.setSelectedIndex(i);
      DomEvent.fireNativeEvent(Document.get().createChangeEvent(), connectorListBox);
      break;
    }
  }

  currentEditor.setValue(value);

  applicationTitle.setText(value.getApplicationTitle());
  applicationSubtitle.setText(value.getApplicationSubTitle());
  donationAddress.setText(value.getHostDonationAddress());
}
 
Example #4
Source File: MaterialWindow.java    From gwt-material-addins with Apache License 2.0 6 votes vote down vote up
@Override
protected void onLoad() {
    super.onLoad();

    // Add handlers to action buttons
    registerHandler(iconMaximize.addClickHandler(event -> toggleMaximize()));

    registerHandler(toolbar.addDoubleClickHandler(event -> {
        toggleMaximize();
        Document.get().getDocumentElement().getStyle().setCursor(Style.Cursor.DEFAULT);
    }));

    registerHandler(iconClose.addClickHandler(event -> {
        if (!preventClose) {
            if (!isOpen()) {
                open();
            } else {
                close();
            }
        }
    }));

    AddinsDarkThemeReloader.get().reload(MaterialWindowDarkTheme.class);
}
 
Example #5
Source File: NavRootNodeEditorView.java    From dashbuilder with Apache License 2.0 6 votes vote down vote up
@Override
public void addCommand(String name, Command command) {
    AnchorElement anchor = Document.get().createAnchorElement();
    anchor.setInnerText(name);

    LIElement li = Document.get().createLIElement();
    li.getStyle().setCursor(Style.Cursor.POINTER);
    li.appendChild(anchor);
    commandMenu.appendChild((Node) li);

    Event.sinkEvents(anchor, Event.ONCLICK);
    Event.setEventListener(anchor, event -> {
        if(Event.ONCLICK == event.getTypeInt()) {
            command.execute();
        }
    });
}
 
Example #6
Source File: KeyBindingRegistryIntegrationGwtTest.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/** Ensure that when other keys are pressed, they are not passed to the action. */
public void testAlternativeKeyPress() {
  KeyBindingRegistry bindings = new KeyBindingRegistry();
  callTracker = 0;
  EditorAction testAction = new EditorAction() {
    public void execute(EditorContext context) {
      callTracker++;
    }
  };
  bindings.registerAction(KeyCombo.ORDER_G, testAction);
  EditorImpl editor = createEditor(bindings);

  // This event is not ORDER_G, it has other accelerators thrown in.
  Event rawEvent = Document.get().createKeyPressEvent(
      true, true, true, false, G_CODE, G_CODE).cast();
  editor.onJavaScriptEvent("keypress", rawEvent);
  assertEquals("Callback action called on unregistered keypress", callTracker, 0);
}
 
Example #7
Source File: KeyBindingRegistryIntegrationGwtTest.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Ensure that new keybindings are used after changing them in the editor.
 */
public void testReregistrationKeyBinding() {
  KeyBindingRegistry bindings = new KeyBindingRegistry();
  callTracker = 0;
  EditorAction testAction = new EditorAction() {
    public void execute(EditorContext context) {
      callTracker++;
    }
  };
  bindings.registerAction(KeyCombo.ORDER_G, testAction);

  EditorImpl editor = createEditor(bindings);
  Event rawEvent = Document.get().createKeyPressEvent(
      true, false, false, false, G_CODE, G_CODE).cast();
  editor.onJavaScriptEvent("keypress", rawEvent);
  // callTracker should be 1 assuming the test above passes

  bindings.removeAction(KeyCombo.ORDER_G);
  initEditor(editor, Editor.ROOT_REGISTRIES, bindings);
  editor.onJavaScriptEvent("keypress", rawEvent);
  assertEquals("Callback action called on deregistered keypress", callTracker, 1);
}
 
Example #8
Source File: DomLogger.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Appends an entry to the log panel.
 * @param formatted
 * @param level
 */
public static void appendEntry(String formatted, Level level) {
  DivElement entry = Document.get().createDivElement();
  entry.setClassName(RESOURCES.css().entry());
  entry.setInnerHTML(formatted);

  // Add the style name associated with the log level.
  switch (level) {
    case ERROR:
      entry.addClassName(RESOURCES.css().error());
      break;
    case FATAL:
      entry.addClassName(RESOURCES.css().fatal());
      break;
    case TRACE:
      entry.addClassName(RESOURCES.css().trace());
      break;
  }

  // Make fatals detectable by WebDriver, so that tests can early out on
  // failure:
  if (level.equals(Level.FATAL)) {
    latestFatalError = formatted;
  }
  writeOrCacheOutput(entry);
}
 
Example #9
Source File: CustomAnalyticsImpl.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void init(String userAccount) {
  Element firstScript = Document.get().getElementsByTagName("script").getItem(0);

  ScriptElement config = Document.get().createScriptElement(
      "var _gaq = _gaq || [];_gaq.push(['_setAccount', '" + userAccount
          + "']);_gaq.push (['_gat._anonymizeIp']);_gaq.push(['_trackPageview']);");

  firstScript.getParentNode().insertBefore(config, firstScript);

  ScriptElement script = Document.get().createScriptElement();

  // Add the google analytics script.
  script.setSrc(("https:".equals(Window.Location.getProtocol())
      ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js");
  script.setType("text/javascript");
  script.setAttribute("async", "true");

  firstScript.getParentNode().insertBefore(script, firstScript);
}
 
Example #10
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 #11
Source File: EditorEventHandlerGwtTest.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Ensure that the event handler normalises the selection when necessary
 * Note that this is currently just for firefox.
 */
public void testNormalisesSelection() {
  FakeEditorEvent fakeEvent = FakeEditorEvent.create(KeySignalType.INPUT, 'a');
  final Point<ContentNode> caret =
      Point.<ContentNode> end(newParaElement());

  EditorEventsSubHandler subHandler = new FakeEditorEventsSubHandler();
  FakeEditorInteractor interactor = setupFakeEditorInteractor(new FocusedContentRange(caret));
  final Point<ContentNode> newCaret = Point.<ContentNode>inText(
      new ContentTextNode(Document.get().createTextNode("hi"), null), 2);
  interactor.call(FakeEditorInteractor.NORMALIZE_POINT).returns(newCaret);
  interactor.call(FakeEditorInteractor.SET_CARET).nOf(1).withArgs(newCaret);
  interactor.call(FakeEditorInteractor.NOTIFYING_TYPING_EXTRACTOR).nOf(1).withArgs(
      newCaret, false);
  EditorEventHandler handler = createEditorEventHandler(interactor, subHandler);

  handler.handleEvent(fakeEvent);
  interactor.checkExpectations();
}
 
Example #12
Source File: ContentTextNodeGwtTest.java    From swellrt with Apache License 2.0 5 votes vote down vote up
public void testContentDataInitialisedFromNodelet() {
  ContentDocument dom = TestEditors.createTestDocument();

  ContentTextNode txt = new ContentTextNode(
      Document.get().createTextNode("abc"),
      dom.debugGetContext());
  assertEquals("abc", txt.getData());
}
 
Example #13
Source File: ImeExtractor.java    From swellrt with Apache License 2.0 5 votes vote down vote up
public static void register(ElementHandlerRegistry registry) {
  registry.registerRenderer(WRAPPER_TAGNAME, new Renderer() {
    @Override
    public Element createDomImpl(Renderable element) {
      return element.setAutoAppendContainer(Document.get().createSpanElement());
    }
  });
}
 
Example #14
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 #15
Source File: WebClient.java    From swellrt with Apache License 2.0 5 votes vote down vote up
private void setupWavePanel() {
  // Hide the frame until waves start getting opened.
  UIObject.setVisible(waveFrame.getElement(), false);

  Document.get().getElementById("signout").setInnerText(messages.signout());

  // Handles opening waves.
  ClientEvents.get().addWaveSelectionEventHandler(new WaveSelectionEventHandler() {
    @Override
    public void onSelection(WaveRef waveRef) {
      openWave(waveRef, false, null);
    }
  });
}
 
Example #16
Source File: CajolerFacade.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private static IFrameElement createCajaFrame() {
  IFrameElement cajaFrame = Document.get().createIFrameElement();
  cajaFrame.setFrameBorder(0);
  cajaFrame.setAttribute("width", "0");
  cajaFrame.setAttribute("height", "0");
  Document.get().getBody().appendChild(cajaFrame);
  Document cajaFrameDoc = cajaFrame.getContentDocument();
  cajaFrameDoc.getBody().appendChild(
      cajaFrameDoc.createScriptElement(RESOURCES.supportingJs().getText()));
  cajaFrameDoc.getBody().appendChild(
      cajaFrameDoc.createScriptElement(RESOURCES.taming().getText()));
  return cajaFrame;
}
 
Example #17
Source File: CubaFileUploadProgressWindow.java    From cuba with Apache License 2.0 5 votes vote down vote up
private void hideModalityCurtain() {
    Document.get().getBody().removeClassName(MODAL_WINDOW_OPEN_CLASSNAME);

    modalityCurtain.removeFromParent();

    if (BrowserInfo.get().isIE()) {
        // IE leaks memory in certain cases unless we release the reference
        // (#9197)
        modalityCurtain = null;
    }
}
 
Example #18
Source File: AddressBookPage.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@PresentHandler
void presentAddressBook(AddressBookPlace place) {
	Document.get().setTitle("PWT - Sample - Address book");

	List<Group> groups = ContactService.get().getGroups();
	Collection<String> groupsItems = Lists.newArrayList();
	for (int i = 1; i < groups.size(); i++) {
		groupsItems.add(groups.get(i).getName());
	}
	this.groupSelect.setItems(groupsItems);
	this.groupsList.edit(groups);
	this.displayGroup(groups.get(0));
}
 
Example #19
Source File: CellTreeNodeView.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Update the image based on the current state.
 *
 * @param isLoading true if still loading data
 */
private void updateImage(boolean isLoading) {
  // Early out if this is a root node.
  if (isRootNode()) {
    return;
  }

  // Replace the image element with a new one.
  boolean isTopLevel = parentNode.isRootNode();
  SafeHtml html = tree.getClosedImageHtml(isTopLevel);
  if (open) {
    html = isLoading ? tree.getLoadingImageHtml() : tree.getOpenImageHtml(isTopLevel);
  }
  if (nodeInfoLoaded && nodeInfo == null) {
    html = LEAF_IMAGE;
  }
  Element tmp = Document.get().createDivElement();
  tmp.setInnerSafeHtml(html);
  Element imageElem = tmp.getFirstChildElement();

  Element oldImg = getImageElement();
  oldImg.getParentElement().replaceChild(imageElem, oldImg);

  // Set 'aria-expanded' state
  // don't set aria-expanded on the leaf nodes
  if (isLeaf()) {
    Roles.getTreeitemRole().removeAriaExpandedState(getElement());
  }
  else {
    Roles.getTreeitemRole().setAriaExpandedState(getElement(), ExpandedValue.of(open));
  }
}
 
Example #20
Source File: MaterialMasonry.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
public MaterialMasonry() {
    super(Document.get().createDivElement(), AddinsCssName.MASONRY, CssName.ROW);

    sizerDiv.setWidth("8.3333%");
    sizerDiv.setStyleName(AddinsCssName.COL_SIZER);
    add(sizerDiv);
}
 
Example #21
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 #22
Source File: GwtMockitoTest.java    From gwtmockito with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unused")
public void shouldAllowOnlyJavascriptCastsThatAreValidJavaCasts() {
  // Casts to ancestors should be legal
  JavaScriptObject o = Document.get().createDivElement().cast();
  Node n = Document.get().createDivElement().cast();
  DivElement d = Document.get().createDivElement().cast();

  // Casts to sibling elements shouldn't be legal (even though they are in javascript)
  try {
    IFrameElement i = Document.get().createDivElement().cast();
    fail("Exception not thrown");
  } catch (ClassCastException expected) {}
}
 
Example #23
Source File: MaterialRangeTest.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
public void testChangeHandler() {
    MaterialRange range = getWidget();

    final boolean[] firedEvent = {false};
    range.addChangeHandler(changeEvent -> firedEvent[0] = true);
    ChangeEvent.fireNativeEvent(Document.get().createChangeEvent(), range.getRangeInputElement());
    assertTrue(firedEvent[0]);
}
 
Example #24
Source File: Page.java    From requestor with Apache License 2.0 5 votes vote down vote up
private static void setPageElementText(String id, String title, boolean alignCenter) {
    final Element e = Document.get().getElementById(id);
    e.setInnerText(title);
    if (alignCenter) {
        e.addClassName("text-center");
    } else {
        e.removeClassName("text-center");
    }
}
 
Example #25
Source File: AnnotationBoundaryRenderer.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public Element createDomImpl(Renderable element) {
  Element nodelet = Document.get().createSpanElement();

  DomHelper.makeUnselectable(nodelet);
  DomHelper.setContentEditable(nodelet, false, false);

  element.setAutoAppendContainer(nodelet);
  return nodelet;
}
 
Example #26
Source File: WordCloudApp.java    From swcv with MIT License 5 votes vote down vote up
private void createWordCloud()
{
    TextArea textArea = TextArea.wrap(Document.get().getElementById("input_text"));
    String text = textArea.getText().trim();
    if (!text.isEmpty())
    {
        createWordCloud(text);
    }
    else
    {
        textArea.setFocus(true);
    }
}
 
Example #27
Source File: ContentTextNodeGwtTest.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
public void testContentDataInitialisedFromNodelet() {
  ContentDocument dom = TestEditors.createTestDocument();

  ContentTextNode txt = new ContentTextNode(
      Document.get().createTextNode("abc"),
      dom.debugGetContext());
  assertEquals("abc", txt.getData());
}
 
Example #28
Source File: CheckBox.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public Element createDomImpl(Renderable element) {
  InputElement inputElem = Document.get().createCheckInputElement();
  inputElem.setClassName(CheckConstants.css.check());

  // Wrap in non-editable span- Firefox does not fire events for checkboxes
  // inside contentEditable region.
  SpanElement nonEditableSpan = Document.get().createSpanElement();
  DomHelper.setContentEditable(nonEditableSpan, false, false);
  nonEditableSpan.appendChild(inputElem);

  return nonEditableSpan;
}
 
Example #29
Source File: FakeUser.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")  // NOTE(zdwang): This is for (Point<Node>) action[1]
public void run(TypingExtractor extractor, Object... actions) throws HtmlMissing, HtmlInserted {
  for (Object a : actions) {
    Object[] action = (Object[]) a;
    Point<Node> sel = getSelectionStart();
    Text txt = sel == null ? null : sel.getContainer().<Text>cast();
    Action type = (Action) action[0];
    switch (type) {
      case MOVE:
        //extractor.flush();
        setCaret((Point<Node>) action[1]);
        break;
      case TYPE:
        String typed = (String) action[1];
        extractor.somethingHappened(getSelectionStart());
        if (sel.isInTextNode()) {
          txt.insertData(sel.getTextOffset(), (String) action[1]);
          moveCaret(((String) action[1]).length());
        } else {
          txt = Document.get().createTextNode(typed);
          sel.getContainer().insertBefore(txt, sel.getNodeAfter());
          setCaret(Point.inText((Node)txt, typed.length()));
        }
        break;
      case BACKSPACE:
      case DELETE:
        extractor.somethingHappened(getSelectionStart());
        int amount = (Integer) action[1];
        if (type == Action.BACKSPACE) {
          moveCaret(-amount);
        }
        deleteText(amount);
        break;
      case SPLIT:
        sel.getContainer().<Text>cast().splitText(sel.getTextOffset());
        moveCaret(0);
        break;
    }
  }
}
 
Example #30
Source File: InlineAnchorStaticRenderer.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public Element createDomImpl(Renderable element) {
  Element e = Document.get().createElement(Blips.THREAD_INLINE_ANCHOR_TAGNAME);
  // Do the things that the doodad API should be doing by default.
  DomHelper.setContentEditable(e, false, false);
  DomHelper.makeUnselectable(e);
  // ContentElement attempts this, and fails, so we have to do this ourselves.
  e.getStyle().setProperty("whiteSpace", "normal");
  e.getStyle().setProperty("lineHeight", "normal");

  return e;
}