com.google.gwt.core.shared.GWT Java Examples

The following examples show how to use com.google.gwt.core.shared.GWT. 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: GwtMockitoRunnerlessTest.java    From gwtmockito with Apache License 2.0 6 votes vote down vote up
@Test
public void canUseProvidersForTypes() {
  GwtMockito.useProviderForType(AnotherInterface.class, new FakeProvider<AnotherInterface>() {
    @Override
    public AnotherInterface getFake(Class<?> type) {
      return new AnotherInterface() {
        @Override
        public String doSomethingElse() {
          return "some value";
        }
      };
    }
  });

  AnotherInterface result = GWT.create(AnotherInterface.class);

  assertEquals("some value", result.doSomethingElse());
}
 
Example #2
Source File: GwtMockitoTest.java    From gwtmockito with Apache License 2.0 6 votes vote down vote up
@Test
public void canUseProvidersForTypes() {
  GwtMockito.useProviderForType(AnotherInterface.class, new FakeProvider<AnotherInterface>() {
    @Override
    public AnotherInterface getFake(Class<?> type) {
      return new AnotherInterface() {
        @Override
        public String doSomethingElse() {
          return "some value";
        }
      };
    }
  });

  AnotherInterface result = GWT.create(AnotherInterface.class);

  assertEquals("some value", result.doSomethingElse());
}
 
Example #3
Source File: EventBinderTest.java    From gwteventbinder with Apache License 2.0 6 votes vote down vote up
public void testEventBinder_withHandlersInSuperclass() {
  EventBus eventBus = new SimpleEventBus();
  SubPresenter presenter = new SubPresenter();
  SubPresenter.MyEventBinder binder = GWT.create(SubPresenter.MyEventBinder.class);
  binder.bindEventHandlers(presenter, eventBus);

  eventBus.fireEvent(new FirstEvent());
  eventBus.fireEvent(new SecondEvent());
  eventBus.fireEvent(new ThirdEvent());

  // FirstEvent has a handler in both classes, so it should be handled twice
  assertEquals(1, presenter.firstEventsHandled);
  assertEquals(1, presenter.firstEventsWithoutParameterHandled);
  assertEquals(1, presenter.subclassFirstEventsHandled);

  // SecondEvent's handler is overridden in the subclass, so it should only be handled there
  assertEquals(0, presenter.secondEventsHandled);
  assertEquals(1, presenter.subclassSecondEventsHandled);

  // ThirdEvent is only handled in the superclass
  assertEquals(1, presenter.thirdEventsHandled);

  // First+Second events are handled in superclass
  assertEquals(2, presenter.firstAndSecondEventsHandled);
}
 
Example #4
Source File: NodeShape.java    From EasyML with Apache License 2.0 6 votes vote down vote up
protected int getContainerOffsetTop() {
	if (containerOffsetTop < 0 || !sync) {
		int scrollTop = 0;
		Element parent = DOM.getParent(getWidget().getElement());
		while (parent != null) {
			if (getScrollTop(parent) > 0) {
				scrollTop += getScrollTop(parent);
				GWT.log("Scroll Top detected : " + scrollTop);
			}
			if (containerFinder.isContainer(parent)) {
				containerOffsetTop = DOM.getAbsoluteTop(parent) - scrollTop;
			}
			parent = DOM.getParent(parent);
		}
	}
	return containerOffsetTop;
}
 
Example #5
Source File: PageDecoder.java    From djvu-html5 with GNU General Public License v2.0 6 votes vote down vote up
private boolean decodePage(PageItem pageItem) {
	DjVuPage page = pageItem.page;
	try {
		if (page == null) {
			page = pageItem.page = document.getPage(pageItem.pageNum);
			if (page == null)
				return true; // not downloaded yet
			GWT.log("Decoding page " + pageItem.pageNum);
		}
		if (page.decodeStep()) {
			pageItem.isDecoded = true;
			if (pageItem.info == null) {
				pageItem.setInfo(page.getInfo());
				pageItem.setText(page.getText());
			}
			pageItem.memoryUsage = page.getMemoryUsage();
			pagesMemoryUsage += pageItem.memoryUsage;
		}
		return true;
	} catch (IOException e) {
		GWT.log("Error while decoding page " + pageItem.pageNum, e);
		return false;
	}
}
 
Example #6
Source File: VButtonValueRenderer.java    From vaadin-grid-util with MIT License 6 votes vote down vote up
private Button genButton(final int bitm) {
	Button btn = GWT.create(Button.class);
	btn.setStylePrimaryName("v-nativebutton");
	switch (bitm) {
		case VIEW_BITM:
			btn.addStyleName("v-view");
			break;
		case EDIT_BITM:
			btn.addStyleName("v-edit");
			break;
		case DELETE_BITM:
			btn.addStyleName("v-delete");
			break;

	}
	btn.setHTML("<span></span>");
	btn.addClickHandler(new ClickHandler() {

		@Override
		public void onClick(final ClickEvent event) {
			VButtonValueRenderer.this.clickedBITM = bitm;
			VButtonValueRenderer.super.onClick(event);
		}
	});
	return btn;
}
 
Example #7
Source File: HistoryViewer.java    From swellrt with Apache License 2.0 6 votes vote down vote up
private ContentDocument createContentDocument(boolean validateSchema) {

    DocInitialization op;
    try {
      op = DocProviders.POJO.parse("").asOperation();
    } catch (IllegalArgumentException e) {
      GWT.log("Exception processing content", e);
      return null;
    }



    if (validateSchema) {
      ViolationCollector vc = new ViolationCollector();
      if (!DocOpValidator.validate(vc, getSchema(), op).isValid()) {
        GWT.log("Error validating content " + vc.firstDescription());
      }
    }
    return new ContentDocument(getRegistries(), op, DOC_SCHEMA);

  }
 
Example #8
Source File: GanttWidget.java    From gantt with Apache License 2.0 6 votes vote down vote up
@Override
public void onDoubleClick(DoubleClickEvent event) {
    GWT.log("onDoubleClick(DoubleClickEvent)");
    if (event.getNativeButton() == NativeEvent.BUTTON_LEFT) {
        doubleClickDetectionMaxTimer.cancel();
        if (!insideDoubleClickDetectionInterval && numberOfMouseClicksDetected < 2) {
            return; // ignore double-click
        }
        if (targetBarElement != null) {
            disableClickOnNextMouseUp();
            targetBarElement = null;
        }
        Element bar = getBar(event.getNativeEvent());
        if (bar != null && numberOfMouseClicksDetected > 1) {
            fireClickRpc(bar, event.getNativeEvent());
        }
        cancelDoubleClickDetection();
    }
}
 
Example #9
Source File: GanttWidget.java    From gantt with Apache License 2.0 6 votes vote down vote up
@Override
public void onMouseUp(MouseUpEvent event) {
    GWT.log("onMouseUp(MouseUpEvent)");
    if (event.getNativeButton() == NativeEvent.BUTTON_LEFT) {
        GanttWidget.this.onTouchOrMouseUp(event.getNativeEvent());

    } else {
        if (secondaryClickOnNextMouseUp) {
            Element bar = getBar(event.getNativeEvent());
            if (bar != null && isEnabled()) {
                getRpc().stepClicked(getStepUid(bar), event.getNativeEvent(), bar);
            }
        }
        secondaryClickOnNextMouseUp = true;
    }
}
 
Example #10
Source File: GanttWidget.java    From gantt with Apache License 2.0 6 votes vote down vote up
@Override
public void onPointerDown(PointerDownEvent event) {
    GWT.log("onPointerDown(PointerDownEvent)");

    if (currentPointerEventId == -1) {
        currentPointerEventId = event.getPointerId();
    } else {
        event.preventDefault();
        return; // multi-touch not supported
    }
    pendingPointerDownEvent = event.getNativeEvent();
    capturePoint = new Point(getTouchOrMouseClientX(event.getNativeEvent()),
            getTouchOrMouseClientY(event.getNativeEvent()));
    pointerTouchStartedTimer.schedule(POINTER_TOUCH_DETECTION_INTERVAL);
    event.preventDefault();
}
 
Example #11
Source File: GwtTreeImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public GwtTreeImpl() {
  super(new GwtTreeModel(), null, GWT.<CellTree.Resources>create(DefaultCellTreeResources.class), new CellTreeMessages() {
    @Override
    public String showMore() {
      // should not never called - due page size is max
      return "SHOW_MORE";
    }

    @Override
    public String emptyTree() {
      return "loading...";
    }
  }, Integer.MAX_VALUE);

  sinkEvents(Event.ONCONTEXTMENU);

  getTreeViewModel().init(this);
}
 
Example #12
Source File: SvgArrowWidget.java    From gantt with Apache License 2.0 6 votes vote down vote up
protected void cancelMove(boolean forceReset, NativeEvent event) {
    GWT.log("Relasing captured point.");
    if (captureElement != null) {
        Event.releaseCapture(captureElement);
    }
    movePointElement.removeFromParent();
    getElement().getParentElement().removeClassName(SELECTION_STYLE_NAME);
    moveRegisteration.removeHandler();
    if (touchCancelRegisteration != null) {
        touchCancelRegisteration.removeHandler();
    }
    captureElement = null;

    if (forceReset
            || (handler != null && !handler.onArrowChanged(
                    selectPredecessorMode, event))) {
        // cancel
        resetArrow();
    }
    selectPredecessorMode = false;
    selectFollowerMode = false;
    currentPointerEventId = -1;
    pendingPointerDownEvent = null;
}
 
Example #13
Source File: UriBuilderImpl.java    From requestor with Apache License 2.0 6 votes vote down vote up
@Override
public UriBuilder matrixParam(String name, Object... values) throws IllegalArgumentException {
    assertNotNullOrEmpty(name, "Parameter name cannot be null or empty.", false);
    assertNotNull(values, "Parameter values cannot be null.");

    if (matrixParams == null) {
        matrixParams = new HashMap<String, Buckets>();
    }

    // At least one segment must exist
    assertNotNull(segments, "There is no segment added to the URI. " +
            "There must be at least one segment added in order to bind matrix parameters");

    String segment = segments.get(segments.size() - 1);

    Buckets segmentParams = matrixParams.get(segment);
    if (segmentParams == null) {
        segmentParams = GWT.create(Buckets.class);
        matrixParams.put(segment, segmentParams);
    }
    for (Object value : values) {
        segmentParams.add(name, value != null ? value.toString() : null);
    }

    return this;
}
 
Example #14
Source File: EventBinderTest.java    From gwteventbinder with Apache License 2.0 6 votes vote down vote up
public void testEventBinder() {
  EventBus eventBus = new SimpleEventBus();
  TestPresenter presenter = new TestPresenter();
  TestPresenter.MyEventBinder binder = GWT.create(TestPresenter.MyEventBinder.class);
  binder.bindEventHandlers(presenter, eventBus);

  // Test one event
  assertEquals(0, presenter.firstEventsHandled);
  eventBus.fireEvent(new FirstEvent());
  assertEquals(1, presenter.firstEventsHandled);
  assertEquals(1, presenter.firstEventsWithoutParameterHandled);
  assertEquals(1, presenter.firstAndSecondEventsHandled);

  // Test another event twice
  assertEquals(0, presenter.secondEventsHandled);
  eventBus.fireEvent(new SecondEvent());
  eventBus.fireEvent(new SecondEvent());
  assertEquals(2, presenter.secondEventsHandled);
  assertEquals(3, presenter.firstAndSecondEventsHandled);
}
 
Example #15
Source File: StatRecorder.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Records an http request call tree.
 */
void recordRequest(ExecutionNode node) {
  if (!GWT.isClient() && getSessionContext() != null && getSessionContext().isAuthenticated()) {
    getSessionStore().storeRequest(node);
  }
  globalStore.storeRequest(node);
}
 
Example #16
Source File: StatRecorder.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Records a single incident of measure and duration in millis with threshold.
 */
void record(String name, String module, int duration, int threshold) {
  if (!GWT.isClient() && getSessionContext() != null && getSessionContext().isAuthenticated()) {
    getSessionStore().recordMeasurement(name, module, duration, threshold);
  }
  globalStore.recordMeasurement(name, module, duration, threshold);
}
 
Example #17
Source File: UriBuilderImpl.java    From requestor with Apache License 2.0 5 votes vote down vote up
@Override
public UriBuilder queryParam(String name, Object... values) throws IllegalArgumentException {
    assertNotNull(name, "Parameter name cannot be null.");
    assertNotNull(values, "Parameter values cannot be null.");

    if (queryParams == null) queryParams = GWT.create(Buckets.class);
    for (Object value : values) {
        queryParams.add(name, value != null ? value.toString() : null);
    }
    return this;
}
 
Example #18
Source File: GanttWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * This is called when target bar element is moved successfully. Element's
 * CSS attributes 'left' and 'width' are updated (unit in pixels).
 *
 * @param bar
 *            Moved Bar element
 * @param y
 */
protected void moveCompleted(Element bar, int y, NativeEvent event) {
    double deltay = y - capturePoint.getY();
    GWT.log("Position delta y: " + deltay + "px" + " capture point y is " + capturePoint.getY());

    Element newPosition = findStepElement(bar, (int) capturePointAbsTopPx,
            (int) (capturePointAbsTopPx + getElementHeightWithMargin(bar)), y, deltay);
    internalMoveOrResizeCompleted(bar, newPosition, true, event);
}
 
Example #19
Source File: GanttWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * @param child
 *            Child widget.
 * @param container
 *            Parent element.
 * @param beforeIndex
 *            Target index of element in DOM.
 * @param domInsert
 *            true: Insert at specific position. false: append at the end.
 */
@Override
protected void insert(Widget child, Element container, int beforeIndex, boolean domInsert) {
    GWT.log("Count content elements: " + content.getChildCount() + " ("
            + getAdditionalNonWidgetContentElementCount() + " non-widget non-step elements, "
            + (getAdditonalContentElementCount() - getAdditionalNonWidgetContentElementCount())
            + " non-step widgets.)");

    // Validate index; adjust if the widget is already a child of this
    // panel.
    int adjustedBeforeStepIndex = adjustIndex(child, beforeIndex - getAdditionalNonWidgetContentElementCount())
            - getAdditionalWidgetContentElementCount();

    // Detach new child. Might also remove additional widgets like
    // predecessor arrows. May affect contentHeight.
    child.removeFromParent();

    // Logical attach.
    getChildren().insert(child, adjustedBeforeStepIndex + getAdditionalWidgetContentElementCount());

    // Physical attach.
    if (domInsert) {
        DOM.insertChild(container, child.getElement(), adjustedBeforeStepIndex + getAdditonalContentElementCount());
    } else {
        DOM.appendChild(container, child.getElement());
    }

    // Adopt.
    adopt(child);
}
 
Example #20
Source File: SvgArrowWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
protected void startMoving(NativeEvent event, Element element) {
    if (element.equals(startingPoint)) {
        selectPredecessorMode = true;
        startingPoint.getStyle().setVisibility(Visibility.HIDDEN);
    } else if (element.equals(endingPoint)) {
        selectFollowerMode = true;
        endingPoint.getStyle().setVisibility(Visibility.HIDDEN);
    }
    capturePointScrollTop = getElement().getParentElement()
            .getParentElement().getScrollTop();
    capturePointScrollLeft = getElement().getParentElement()
            .getParentElement().getScrollLeft();
    getParent().getElement().appendChild(movePointElement);
    getElement().getParentElement().addClassName(SELECTION_STYLE_NAME);
    GWT.log("Capturing clicked point.");
    captureElement = getElement();
    Event.setCapture(getElement());
    event.stopPropagation();

    // enable MODE for new predecessor/following step
    // selection.
    addMoveHandler();

    capturePoint = new Point(getTouchOrMouseClientX(event),
            getTouchOrMouseClientY(event));
    originalWidth = width;
    originalHeight = height;
}
 
Example #21
Source File: GanttWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * Update Gantt chart's timeline and content for the given steps. This won't
 * add any steps, but will update the content widths and heights.
 *
 * @param steps
 */
public void update(List<StepWidget> steps) {
    if (startDate < 0 || endDate < 0 || startDate >= endDate) {
        GWT.log("Invalid start and end dates. Gantt chart can't be rendered. Start: " + startDate + ", End: "
                + endDate);
        return;
    }

    content.getStyle().setHeight(contentHeight, Unit.PX);

    GWT.log("GanttWidget's active TimeZone: " + getLocaleDataProvider().getTimeZone().getID() + " (raw offset: "
            + getLocaleDataProvider().getTimeZone().getStandardOffset() + ")");

    timeline.setCurrentDateAndTime(isShowCurrentTime(), getCurrentDate(), getCurrentHour(), getTimestamp());
    // tell timeline to notice vertical scrollbar before updating it
    timeline.setNoticeVerticalScrollbarWidth(isContentOverflowingVertically());
    timeline.update(resolution, startDate, endDate, firstDayOfRange, firstHourOfRange, localeDataProvider);
    setContentMinWidth(timeline.getMinWidth());
    updateContainerStyle();
    updateContentWidth();

    updateStepWidths(steps);

    wasTimelineOverflowingHorizontally = timeline.isTimelineOverflowingHorizontally();

    updateCurrentTime();
}
 
Example #22
Source File: GanttWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
public GanttWidget() {

        setElement(DivElement.as(DOM.createDiv()));
        setStyleName(STYLE_GANTT);

        nowElement.setClassName(STYLE_NOW_ELEMENT);

        moveElement.setClassName(STYLE_MOVE_ELEMENT);
        // not visible by default
        moveElement.getStyle().setDisplay(Display.NONE);

        timeline = GWT.create(TimelineWidget.class);

        container = DivElement.as(DOM.createDiv());
        container.setClassName(STYLE_GANTT_CONTAINER);

        content = DivElement.as(DOM.createDiv());
        content.setClassName(STYLE_GANTT_CONTENT);
        container.appendChild(content);

        content.appendChild(moveElement);
        content.appendChild(nowElement);

        scrollbarSpacer = DivElement.as(DOM.createDiv());
        scrollbarSpacer.getStyle().setHeight(AbstractNativeScrollbar.getNativeScrollbarHeight(), Unit.PX);
        scrollbarSpacer.getStyle().setDisplay(Display.NONE);

        getElement().appendChild(timeline.getElement());
        getElement().appendChild(container);
        getElement().appendChild(scrollbarSpacer);
    }
 
Example #23
Source File: GridButtonRenderer.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Button createWidget() {
    Button b = GWT.create(Button.class);
    b.addClickHandler(this);
    b.setStylePrimaryName("v-nativebutton");
    return b;
}
 
Example #24
Source File: MyWidget.java    From gwtmockito with Apache License 2.0 5 votes vote down vote up
public void loadDataFromRpc() {
  MyServiceAsync service = GWT.create(MyService.class);
  service.getData(new AsyncCallback<String>() {
    @Override
    public void onSuccess(String result) {
      data.setText(result);
    }

    @Override
    public void onFailure(Throwable caught) {}
  });
}
 
Example #25
Source File: UniTimeFrameDialog.java    From unitime with Apache License 2.0 5 votes vote down vote up
public static void openDialog(String title, String source, String width, String height, boolean noCacheTS) {
	if (sDialog == null) {
		if (Window.getClientWidth() <= 800)
			sDialog = GWT.create(UniTimeFrameDialogDisplay.Mobile.class);
		else
			sDialog = GWT.create(UniTimeFrameDialogDisplay.class);
	}
	sDialog.openDialog(title, source, width, height, noCacheTS);
}
 
Example #26
Source File: GanttWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    GWT.log("doubleClickDetectionMaxTimer.run()");

    boolean doFireClick = numberOfMouseClicksDetected > 0 && previousMouseUpEvent != null
            && previousMouseUpBarElement != null && !isMoveOrResizingInProgress();
    NativeEvent targetEvent = previousMouseUpEvent;
    Element targetElement = previousMouseUpBarElement;
    cancelDoubleClickDetection();
    if (doFireClick) {
        fireClickRpc(targetElement, targetEvent);
    }
}
 
Example #27
Source File: GwtMockitoTest.java    From gwtmockito with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCreateFakeMessages() {
  SampleMessages messages = GWT.create(SampleMessages.class);

  assertEquals("noArgs", messages.noArgs());
  assertEquals("oneArg(somearg)", messages.oneArg("somearg"));
  assertEquals("twoArgs(onearg, twoarg)", messages.twoArgs("onearg", "twoarg"));
  assertEquals("safeHtml(arg)",
      messages.safeHtml(SafeHtmlUtils.fromTrustedString("arg")).asString());
  assertEquals("safeHtmlWithUri(argX, http://uriY)",
      messages.safeHtmlWithUri(SafeHtmlUtils.fromTrustedString("argX"),
          UriUtils.fromSafeConstant("http://uriY")).asString());
}
 
Example #28
Source File: GoogleAnalytics.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static GoogleAnalytics init(String account, String domain) {
	GoogleAnalytics ga = GoogleAnalytics.cache.get(account);
	if (ga == null) {
		ga = GWT.create(GoogleAnalytics.class);
		ga.initialize(account, domain);
	}
	return ga;
}
 
Example #29
Source File: GoogleAnalytics.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static GoogleAnalytics get(String account) {
	GoogleAnalytics ga = GoogleAnalytics.cache.get(account);
	if (ga == null) {
		ga = GWT.create(GoogleAnalytics.class);
		ga.initialize(account);
	}
	return ga;
}
 
Example #30
Source File: GanttWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to find Step element by given starting point and y-position
 * and delta-y. Starting point is there to optimize performance a bit as
 * there's no need to iterate through every single step element.
 *
 * @param startFromBar
 *            Starting point element
 * @param newY
 *            target y-axis position
 * @param deltay
 *            delta-y relative to starting point element.
 * @return Step element at y-axis position. May be same element as given
 *         startFromBar element.
 */
protected Element findStepElement(Element startFromBar, int startTopY, int startBottomY, int newY, double deltay) {
    boolean subStep = isSubBar(startFromBar);
    if (subStep) {
        startFromBar = startFromBar.getParentElement();
    }

    if (isBetween(newY, startTopY, startBottomY)) {
        GWT.log("findStepElement returns same: Y " + newY + " between " + startTopY + "-" + startBottomY);
        return startFromBar;
    }
    int startIndex = getChildIndex(content, startFromBar);
    Element barCanditate;
    int i = startIndex;
    if (deltay > 0) {
        i++;
        for (; i < content.getChildCount(); i++) {
            barCanditate = Element.as(content.getChild(i));
            if (isBetween(newY, barCanditate.getAbsoluteTop(), barCanditate.getAbsoluteBottom())) {
                if (!subStep && i == (startIndex + 1)) {
                    // moving directly over the following step will be
                    // ignored (if not sub-step).
                    return startFromBar;
                }
                return barCanditate;
            }
        }
    } else if (deltay < 0) {
        i--;
        for (; i >= getAdditonalContentElementCount(); i--) {
            barCanditate = Element.as(content.getChild(i));
            if (isBetween(newY, barCanditate.getAbsoluteTop(), barCanditate.getAbsoluteBottom())) {
                return barCanditate;
            }
        }
    }
    return startFromBar;
}