com.google.gwt.user.client.ui.RootPanel Java Examples

The following examples show how to use com.google.gwt.user.client.ui.RootPanel. 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: CubaFileDownloaderConnector.java    From cuba with Apache License 2.0 6 votes vote down vote up
public void downloadFileById(String resourceId) {
    final String url = getResourceUrl(resourceId);
    if (url != null && !url.isEmpty()) {
        final IFrameElement iframe = Document.get().createIFrameElement();

        Style style = iframe.getStyle();
        style.setVisibility(Style.Visibility.HIDDEN);
        style.setHeight(0, Style.Unit.PX);
        style.setWidth(0, Style.Unit.PX);

        iframe.setFrameBorder(0);
        iframe.setTabIndex(-1);
        iframe.setSrc(url);
        RootPanel.getBodyElement().appendChild(iframe);

        Timer removeTimer = new Timer() {
            @Override
            public void run() {
                iframe.removeFromParent();
            }
        };
        removeTimer.schedule(60 * 1000);
    }
}
 
Example #2
Source File: ImageThumbnailWidget.java    From swellrt with Apache License 2.0 6 votes vote down vote up
private void cleanUp() {
  RootPanel.get().remove(doubleLoadedImage);

  final HandlerRegistration onLoadReg = onLoadHandlerRegistration;
  final HandlerRegistration onErrorReg = onErrorHandlerRegistration;

  // HACK(user): There is a bug in GWT which stops us from removing a listener in HOSTED
  // mode inside the invoke context.  Put the remove in a deferred command to avoid this
  // error
  ScheduleCommand.addCommand(new Scheduler.Task() {
    public void execute() {
      onLoadReg.removeHandler();
      onErrorReg.removeHandler();
    }
  });

  onLoadHandlerRegistration = null;
  onErrorHandlerRegistration = null;

  completed = true;
}
 
Example #3
Source File: RoomSharingWidget.java    From unitime with Apache License 2.0 6 votes vote down vote up
public void insert(final RootPanel panel, boolean eventAvailability) {
	Long locationId = Long.valueOf(panel.getElement().getInnerHTML().trim());
	RPC.execute(RoomInterface.RoomSharingRequest.load(locationId, eventAvailability), new AsyncCallback<RoomSharingModel>() {
		@Override
		public void onFailure(Throwable caught) {
			UniTimeNotifications.error(MESSAGES.failedToLoadRoomAvailability(caught.getMessage()));
		}

		@Override
		public void onSuccess(RoomSharingModel result) {
			panel.getElement().setInnerText(null);
			setModel(result);
			panel.add(RoomSharingWidget.this);
			panel.setVisible(true);
		}
	});
}
 
Example #4
Source File: CubaMainTabSheetWidget.java    From cuba with Apache License 2.0 6 votes vote down vote up
public CubaMainTabSheetWidget() {
    RootPanel rootPanel = RootPanel.get();

    dragEndHandler = rootPanel.addBitlessDomHandler(event ->
                    handleBadDD(event.getNativeEvent()),
                    DragEndEvent.getType());

    dropHandler = rootPanel.addBitlessDomHandler(event ->
                    handleBadDD(event.getNativeEvent()),
                    DropEvent.getType());

    dragLeaveHandler = rootPanel.addBitlessDomHandler(event -> {
        Element element = event.getRelativeElement();
        if (element == null || element == rootPanel.getElement()) {
            VDragAndDropManager.get().interruptDrag();
        }
    }, DragLeaveEvent.getType());
}
 
Example #5
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 #6
Source File: MaterialNavBarTest.java    From gwt-material with Apache License 2.0 6 votes vote down vote up
public void testTypes() {
    final int OFFSET = 100;
    MaterialNavBarShrink shrinkNavBar = new MaterialNavBarShrink();

    MaterialHeader header = new MaterialHeader();
    header.add(shrinkNavBar);
    RootPanel.get().add(header);

    assertTrue(shrinkNavBar.getStyleName().contains(NavBarType.SHRINK.getCssName()));

    shrinkNavBar.setScrollOffset(OFFSET);
    assertEquals(OFFSET, shrinkNavBar.getScrollOffset());

    final boolean[] expandFired = {false};
    shrinkNavBar.addExpandHandler(event -> expandFired[0] = true);

    NavBarExpandEvent.fire(shrinkNavBar);
    assertTrue(expandFired[0]);

    final boolean[] shrinkFired = {false};
    shrinkNavBar.addShrinkHandler(event -> shrinkFired[0] = true);

    NavBarShrinkEvent.fire(shrinkNavBar);
    assertTrue(shrinkFired[0]);
}
 
Example #7
Source File: CubaPopupViewWidget.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected int getPositionTop(int popupPositionTop) {
    if (popupPositionTop != -1) {
        return popupPositionTop;
    }

    RootPanel rootPanel = RootPanel.get();
    int windowTop = rootPanel.getAbsoluteTop();
    int windowHeight = rootPanel.getOffsetHeight();
    int windowBottom = windowTop + windowHeight;
    int popupHeight = popup.getOffsetHeight();

    int top = getAbsoluteTop() + (getOffsetHeight() - popupHeight) / 2;

    if ((top + popupHeight) > windowBottom) {
        top -= (top + popupHeight) - windowBottom;
    }

    if (top < 0) {
        top = 0;
    }
    return top;
}
 
Example #8
Source File: MaterialWindow.java    From gwt-material-addins with Apache License 2.0 6 votes vote down vote up
/**
 * Close the window.
 */
public void close() {
    // Turn back the cursor to POINTER
    RootPanel.get().getElement().getStyle().setCursor(Style.Cursor.DEFAULT);

    windowCount--;
    if (closeAnimation == null) {
        getOpenMixin().setOn(false);
        if (windowOverlay != null && windowOverlay.isAttached() && windowCount < 1) {
            windowOverlay.removeFromParent();
        }
        CloseEvent.fire(this, false);
    } else {
        closeAnimation.animate(this, () -> {
            getOpenMixin().setOn(false);
            if (windowOverlay != null && windowOverlay.isAttached() && windowCount < 1) {
                windowOverlay.removeFromParent();
            }
            CloseEvent.fire(this, false);
        });
    }
}
 
Example #9
Source File: UniTimeMenuBar.java    From unitime with Apache License 2.0 6 votes vote down vote up
private void attach(final RootPanel rootPanel) {
	RPC.execute(new MenuInterface.MenuRpcRequest(), new AsyncCallback<GwtRpcResponseList<MenuInterface>>() {
		@Override
		public void onSuccess(GwtRpcResponseList<MenuInterface> result) {
			initMenu(iMenu, result, 0);
			if (iSimple != null)
				rootPanel.add(iSimple);
			rootPanel.add(UniTimeMenuBar.this);
			if (iSimple != null)
				iSimple.setHeight(iMenu.getOffsetHeight() + "px");
		}
		@Override
		public void onFailure(Throwable caught) {
		}
	});
}
 
Example #10
Source File: StudentScheduleTable.java    From unitime with Apache License 2.0 6 votes vote down vote up
public void insert(final RootPanel panel) {
	String studentId = panel.getElement().getInnerText().trim();
	panel.getElement().setInnerText(null);
	panel.add(this);
	sSectioningService.lookupStudent(iOnline, studentId, new AsyncCallback<ClassAssignmentInterface.Student>() {
		@Override
		public void onSuccess(Student result) {
			if (result != null) {
				panel.setVisible(true);
				setStudent(result);
				if (SectioningCookie.getInstance().getEnrollmentCoursesDetails()) {
					refresh();
				} else {
					clear();
					iHeader.clearMessage();
					iHeader.setCollapsible(false);
				}
			}
		}
		@Override
		public void onFailure(Throwable caught) {}
	});
}
 
Example #11
Source File: MockComponentsUtil.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the preferred size of the specified DOM element in an array of the
 * form {@code [width, height]}.
 *
 * @see #getPreferredSizeOfDetachedWidget(Widget)
 * @param element the DOM element to compute the size for
 * @return the natural width and height of the element
 */
public static int[] getPreferredSizeOfElement(Element element) {
  Element root = RootPanel.get().getElement();
  root.appendChild(element);

  String[] style = clearSizeStyle(element);
  int width = element.getOffsetWidth() + 4;
  int height = element.getOffsetHeight() + 6;
  if (height < 26) {
    height = 26;
  }
  restoreSizeStyle(element, style);

  root.removeChild(element);
  return new int[] { width, height };
}
 
Example #12
Source File: SampleEntryPoint.java    From gwteventbinder with Apache License 2.0 6 votes vote down vote up
@Override
public void onModuleLoad() {
  // Create the object graph - a real application would use Gin
  SimpleEventBus eventBus = new SimpleEventBus();

  SidebarPresenter sidebarPresenter = new SidebarPresenter(eventBus);
  Button sidebarView = new Button("Contacts");
  sidebarView.getElement().getStyle().setFloat(Style.Float.LEFT);
  sidebarView.getElement().getStyle().setMarginRight(20, Unit.PX);
  sidebarPresenter.setView(sidebarView);
  RootPanel.get().add(sidebarView);

  ContactsPresenter contactsPresenter = new ContactsPresenter(eventBus);
  VerticalPanel contactsView = new VerticalPanel();
  contactsPresenter.setView(contactsView);
  RootPanel.get().add(contactsView);

  // Start listening for events in the presenter
  contactsPresenter.start();

  // Eagerly bind the server proxy
  ServerProxy server = new ServerProxy(eventBus);
}
 
Example #13
Source File: PasteFormatRendererGwtTest.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private void testHelper(String content, String expectedResult) {
  EditorImpl editor = (EditorImpl) Editors.create();
  RootPanel.get().add(editor);
  editor.init(Editor.ROOT_REGISTRIES, null, EditorSettings.DEFAULT);
  initWithContent(editor, content);
  String result = renderPasteHtml(editor);
  assertEquals(expectedResult, result);
  RootPanel.get().remove(editor);
}
 
Example #14
Source File: ClipboardSupport.java    From jetpad-projectional-open-source with Apache License 2.0 5 votes vote down vote up
private TextArea createClipboardTextArea() {
  final TextArea pasteArea = new TextArea();
  pasteArea.setPixelSize(0, 0);
  Style style = pasteArea.getElement().getStyle();
  style.setPosition(Style.Position.FIXED);
  RootPanel.get().add(pasteArea);
  pasteArea.setFocus(true);
  return pasteArea;
}
 
Example #15
Source File: FocusManager.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Installs a key handler for key events on this window.
 *
 * @param handler handler to receive key events.
 */
static void install(KeySignalHandler handler) {
  //
  // NOTE: There are three potential candidate elements for sinking keyboard
  // events: the window, the document, and the document body. IE7 does not
  // fire events on the window element, and GWT's RootPanel is already a
  // listener on the body, leaving the document as the only cross-browser
  // whole-window event-sinking 'element'.
  //
  DocumentPanel panel = new DocumentPanel(handler);
  panel.setElement(Document.get().<Element>cast());
  panel.addDomHandler(panel, KeyDownEvent.getType());
  panel.addDomHandler(panel, KeyPressEvent.getType());
  panel.addDomHandler(panel, KeyUpEvent.getType());
  RootPanel.detachOnWindowClose(panel);
  panel.onAttach();
}
 
Example #16
Source File: MaterialLoaderTest.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
public void testLoaderBasic() {
    MaterialLoader.loading(true);
    ComplexPanel panel = RootPanel.get();

    // when / then
    checkLoader(panel);
}
 
Example #17
Source File: TimetablePage.java    From unitime with Apache License 2.0 5 votes vote down vote up
public static void __search() {
	final int left = Window.getScrollLeft();
	final int top = Window.getScrollTop();
	TimetablePage page = (TimetablePage)RootPanel.get("UniTimeGWT:Body").getWidget(0);
	page.search(new AsyncCallback<Boolean>() {
		@Override
		public void onFailure(Throwable caught) {
		}
		@Override
		public void onSuccess(Boolean result) {
			if (result)
				Window.scrollTo(left, top);
		}
	});
}
 
Example #18
Source File: MaterialTextAreaTest.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
public void testFocus() {
    // given
    MaterialTextArea textArea = getWidget();

    // when / then
    checkResizeRule(textArea);
    textArea.removeFromParent();
    RootPanel.get().add(textArea);
    checkResizeRule(textArea);
}
 
Example #19
Source File: Modal.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void show() {
	RootPanel.get().add(this);
	Scheduler.get().scheduleDeferred(new ScheduledCommand() {
		@Override
		public void execute() {
			StyleUtils.addStyle(ModalBackdrop.this, Modal.STYLE_VISIBLE);
		}
	});
}
 
Example #20
Source File: SingleListBoxDemo.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
@Override
public void onModuleLoad() {

    eventListBox = new ListBox(true);
    eventListBox.setVisibleItemCount(20);
    RootPanel.get("eventlog").add(eventListBox);

    singleListBox = new SingleListBox();
    singleListBox.addItem("Apples");
    singleListBox.addItem("Bananas");
    singleListBox.addItem("Oranges");
    singleListBox.addItem("Pears");
    singleListBox.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            addEvent("ValueChangeEvent: " + event.getValue());
        }
    });
    Panel select = RootPanel.get("select");
    select.add(singleListBox);

    Panel toggle = RootPanel.get("toggle");
    toggle.add(createSetAddMissingValue(true));
    toggle.add(createSetAddMissingValue(false));

    Panel controls1 = RootPanel.get("controls1");
    controls1.add(createSelectButton("Bananas"));
    controls1.add(createSelectButton("Pears"));

    Panel controls2 = RootPanel.get("controls2");
    controls2.add(createSelectButton("Kiwis"));
    controls2.add(createSelectButton("Watermelons"));
}
 
Example #21
Source File: UniTimeNotifications.java    From unitime with Apache License 2.0 5 votes vote down vote up
protected void addNotification(final Notification notification) {
	RootPanel.get().add(notification, Window.getScrollLeft() + Window.getClientWidth() - 445, Window.getScrollTop() + Window.getClientHeight());
	iAnimation.cancel();
	for (Iterator<Notification> i = iNotifications.iterator(); i.hasNext(); ) {
		Notification n = i.next();
		if (n.equals(notification)) {
			n.hide(); i.remove();
		}
	}
	move();
	iNotifications.add(0, notification);
	iAnimation.run(1000);
	Timer timer = new Timer() {
		@Override
		public void run() {
			notification.hide();
			iNotifications.remove(notification);
		}
	};
	notification.addClickHandler(new ClickHandler() {
		@Override
		public void onClick(ClickEvent event) {
			notification.hide();
			iNotifications.remove(notification);
			move();
		}
	});
	timer.schedule(10000);
}
 
Example #22
Source File: MaterialCutoutTest.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
@Override
protected MaterialCutOut createWidget() {
    // given
    MaterialCutOut cutOut = new MaterialCutOut();
    target = new MaterialIcon(IconType.POLYMER);
    RootPanel.get().add(target);

    // when
    cutOut.setTarget(target);

    // then
    assertEquals(target.getElement(), cutOut.getTargetElement());
    return cutOut;
}
 
Example #23
Source File: MaterialDropdownTest.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
public void testEmptyItems() {
    MaterialDropDown dropdown = getWidget(false);

    dropdown.clear();
    dropdown.add(new ListItem());
    RootPanel.get().add(dropdown);
}
 
Example #24
Source File: DesktopUniversalPopup.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * @param isVisible Whether or not the mask should be visible on the screen.
 */
private void setMaskVisible(boolean isVisible) {
  if (isVisible) {
    RootPanel.get().getElement().appendChild(getOrCreateMask());
  } else {
    RootPanel.get().getElement().removeChild(getOrCreateMask());
  }
}
 
Example #25
Source File: MaterialLoader.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the Loader component
 */
public void show() {
    Widget widget = null;
    if (!(container instanceof RootPanel)) {
        if (!(container instanceof MaterialDialog)) {
            container.getElement().getStyle().setPosition(Style.Position.RELATIVE);
        }
        div.getElement().getStyle().setPosition(Style.Position.ABSOLUTE);
    }
    if (scrollDisabled) {
        RootPanel.get().getElement().getStyle().setOverflow(Style.Overflow.HIDDEN);
    }
    if (type == LoaderType.CIRCULAR) {
        div.setStyleName(CssName.VALIGN_WRAPPER + " " + CssName.LOADER_WRAPPER);
        div.add(preLoader);
        widget = preLoader;
    } else if (type == LoaderType.PROGRESS) {
        div.setStyleName(CssName.VALIGN_WRAPPER + " " + CssName.PROGRESS_WRAPPER);
        progress.getElement().getStyle().setProperty("margin", "auto");
        div.add(progress);
        widget = progress;
    }

    if (message != null) {
        div.add(messageLabel);
        messageLabel.setText(message);
    }
    container.add(div);

    if (widget != null && widget instanceof HasOverlayStyle) {
        hasOverlayStyle = (HasOverlayStyle) widget;
        hasOverlayStyle.setOverlayOption(overlayOption);
        hasOverlayStyle.applyOverlayStyle($(div.getElement()));
    }
}
 
Example #26
Source File: MaterialToast.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
public boolean isOpen() {
    String id = getId();
    if (id != null && !id.isEmpty()) {
        Widget toast = RootPanel.get(id);
        return toast.isAttached() && toast.isVisible();
    }
    return false;
}
 
Example #27
Source File: MaterialToast.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
public void close() {
    String id = getId();
    if (id != null && !id.isEmpty()) {
        Widget toast = RootPanel.get(id);
        if (toast != null && toast.isAttached()) {
            element.remove();
        }
    }
}
 
Example #28
Source File: MaterialOverlayTest.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
public void testNestedOverlay() {
    // given
    MaterialOverlay overlay = getWidget();
    MaterialOverlay child = new MaterialOverlay();
    overlay.add(child);

    // when / then
    overlay.open();
    child.open();
    child.close();

    child.addCloseHandler(closeEvent -> assertEquals("hidden", RootPanel.get().getElement().getStyle().getOverflow()));
    assertEquals(RootPanel.get(), overlay.getParent());
    assertEquals(overlay, child.getParent());
}
 
Example #29
Source File: ErrorDisplay.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void show() {
	if (!this.showing) {
		RootPanel.get().add(this.modal);
		this.modal.show();
	}
	this.showing = true;
}
 
Example #30
Source File: EventDispatcherPanelGwtTest.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/** Injects some HTML into the DOM. */
private static Element load(SafeHtml html) {
  Element container = Document.get().createDivElement();
  container.setInnerHTML(html.asString());
  Element content = container.getFirstChildElement();
  RootPanel.get().getElement().appendChild(content);
  return content;
}