com.vaadin.flow.component.Text Java Examples
The following examples show how to use
com.vaadin.flow.component.Text.
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: UIInternalsTest.java From flow with Apache License 2.0 | 6 votes |
@Test public void showRouteTarget_componentHasNoPush_pushIsDisabled() { PushConfiguration pushConfig = setUpInitialPush(); useV14Bootstrap(); DeploymentConfiguration deploymentConfiguration = vaadinService .getDeploymentConfiguration(); Mockito.when(deploymentConfiguration.getPushMode()) .thenReturn(PushMode.AUTOMATIC); internals.showRouteTarget(Mockito.mock(Location.class), new Text(""), Collections.emptyList()); Mockito.verify(pushConfig).setPushMode(PushMode.AUTOMATIC); Mockito.verify(pushConfig, Mockito.times(0)) .setTransport(Mockito.any()); }
Example #2
Source File: UsageStatisticsView.java From flow with Apache License 2.0 | 6 votes |
public UsageStatisticsView() { NativeButton print = new NativeButton( "Print usage statistics to the console", e -> { getUI().get().getPage().executeJs( "var basket = localStorage.getItem('vaadin.statistics.basket'); if (basket) basket = JSON.parse(basket); console.log(basket)"); }); NativeButton clear = new NativeButton("Clear usage statistics", e -> { getUI().get().getPage().executeJs( "localStorage.removeItem('vaadin.statistics.basket')"); }); NativeButton push = new NativeButton("Enable push", e -> getUI().get() .getPushConfiguration().setPushMode(PushMode.AUTOMATIC)); NativeButton template = new NativeButton("Use PolymerTemplate", e -> { add(new HiddenTemplateView()); }); add(new Text( "View for manually testing usage statistics gathering for Flow features." + " After a feature has been used, the page should be reloaded before verifying that usage info has been gathered."), new Div(print, clear, push, template)); }
Example #3
Source File: DnDDisabledView.java From flow with Apache License 2.0 | 6 votes |
private void createEventLog() { eventLog = new Div(); eventLog.add(new Text("Events:")); eventLog.add(new NativeButton("Clear", event -> { eventLog.getChildren().filter(component -> component instanceof Div) .forEach(eventLog::remove); eventCounter = 0; })); eventLog.add(new NativeButton("Data: " + data, event -> { data = !data; event.getSource().setText("Data: " + data); })); eventLog.setHeightFull(); eventLog.setWidth("400px"); eventLog.getStyle().set("display", "inline-block").set("border", "2px " + "solid"); }
Example #4
Source File: PreserveOnRefreshReAddView.java From flow with Apache License 2.0 | 6 votes |
public PreserveOnRefreshReAddView() { Text text1 = new Text("Text"); Text text2 = new Text("Another Text"); Div container = new Div(); container.setId("container"); NativeButton setText = new NativeButton("Set text", e -> { container.removeAll(); container.add(text1); }); NativeButton setAnotherText = new NativeButton("Set another text", e -> { container.removeAll(); container.add(text2); }); setText.setId("set-text"); setAnotherText.setId("set-another-text"); add(setText, setAnotherText, container); }
Example #5
Source File: SynchronizedPropertyView.java From flow with Apache License 2.0 | 6 votes |
private void addSyncWithInitialValue() { add(new Text("Synchronized on 'change' event with initial value")); final Div syncOnChangeInitialValueLabel = new Div(); syncOnChangeInitialValueLabel.setId("syncOnChangeInitialValueLabel"); Element syncOnChangeInitialValue = ElementFactory.createInput(); syncOnChangeInitialValueLabel.setText("Server value on create: " + syncOnChangeInitialValue.getProperty("value")); syncOnChangeInitialValue.setAttribute("id", "syncOnChangeInitialValue"); syncOnChangeInitialValue.addPropertyChangeListener("value", "change", event -> { }); syncOnChangeInitialValue.addEventListener("change", e -> { syncOnChangeInitialValueLabel .setText("Server value in change listener: " + syncOnChangeInitialValue.getProperty("value")); }); syncOnChangeInitialValue.setProperty("value", "initial"); getElement().appendChild(syncOnChangeInitialValue); add(syncOnChangeInitialValueLabel); }
Example #6
Source File: AbstractTwoComponentsCrudLayout.java From crudui with Apache License 2.0 | 5 votes |
@Override public void showDialog(String caption, Component form) { if (caption != null) { Div label = new Div(new Text(caption)); label.getStyle().set("color", "var(--lumo-primary-text-color)"); formCaptionLayout.removeAll(); formCaptionLayout.add(label); secondComponent.addComponentAtIndex(secondComponent.getComponentCount() - 1, formCaptionLayout); } else if (formCaptionLayout.getElement().getParent() != null) { formCaptionLayout.getElement().getParent().removeChild(formCaptionLayout.getElement()); } formComponentLayout.removeAll(); formComponentLayout.add(form); }
Example #7
Source File: BasicComponentView.java From flow with Apache License 2.0 | 5 votes |
@Override protected void onShow() { getElement().getStyle().set("margin", "1em"); getElement().setAttribute("id", "root"); Text text = new Text(TEXT); Input input = new Input(); input.setPlaceholder("Synchronized on change event"); NativeButton button = new NativeButton(BUTTON_TEXT, e -> { Div greeting = new Div(); greeting.addClassName("thankYou"); String buttonText = e.getSource().getElement().getText(); greeting.setText("Thank you for clicking \"" + buttonText + "\" at (" + e.getClientX() + "," + e.getClientY() + ")! The field value is " + input.getValue()); greeting.addClickListener(e2 -> remove(greeting)); add(greeting); }); Div helloWorld = new Div(); helloWorld.setText(DIV_TEXT); helloWorld.addClassName("hello"); helloWorld.setId("hello-world"); helloWorld.addClickListener(e -> { helloWorld.setText("Stop touching me!"); helloWorld.getElement().getClassList().clear(); }); Style s = helloWorld.getElement().getStyle(); s.set("color", "red"); s.set("fontWeight", "bold"); add(text, helloWorld, button, input); }
Example #8
Source File: AbstractErrorHandlerView.java From flow with Apache License 2.0 | 5 votes |
@Override protected void onAttach(AttachEvent attachEvent) { if (attachEvent.isInitialAttach()) { attachEvent.getSession().setErrorHandler(e -> { Div div = new Div( new Text("An error occurred: " + e.getThrowable())); div.addClassName("error"); add(div); }); } }
Example #9
Source File: ExceptionsDuringPropertyUpdatesView.java From flow with Apache License 2.0 | 5 votes |
@Override protected void onAttach(AttachEvent attachEvent) { if (attachEvent.isInitialAttach()) { attachEvent.getSession().setErrorHandler(e -> { Div div = new Div( new Text("An error occurred: " + e.getThrowable())); div.addClassName("error"); add(div); }); } }
Example #10
Source File: CompositeView.java From flow with Apache License 2.0 | 5 votes |
public CompositeView() { Div name = new Div(); name.setText("Name on server: "); name.setId(CompositeNestedView.NAME_ID); NameField nameField = new NameField(); nameField.setId(CompositeNestedView.NAME_FIELD_ID); nameField.addNameChangeListener(e -> { name.setText("Name on server: " + nameField.getName()); String text = "Name value changed to " + nameField.getName() + " on the "; if (e.isFromClient()) { text += "client"; } else { text += "server"; } Div changeMessage = new Div(); changeMessage.setText(text); add(changeMessage); }); add(name, nameField, new Hr()); Input serverInput = new Input(); serverInput.setId(SERVER_INPUT_ID); NativeButton serverInputButton = createButton("Set", SERVER_INPUT_BUTTON_ID, e -> { nameField.setName(serverInput.getValue()); serverInput.clear(); }); add(new Text("Enter a value to set the name on the server"), serverInput, serverInputButton); add(new Hr()); PaperSliderComposite paperSliderComposite = new PaperSliderComposite(); paperSliderComposite.setId(COMPOSITE_PAPER_SLIDER); add(paperSliderComposite); }
Example #11
Source File: SynchronizedPropertyView.java From flow with Apache License 2.0 | 5 votes |
private void addSyncMultipleProperties() { add(new Text( "Synchronize 'value' on 'input' event and 'valueAsNumber' on 'blur'")); Div valueLabel = new Div(); valueLabel.setId("multiSyncValueLabel"); Div valueAsNumberLabel = new Div(); valueAsNumberLabel.setId("multiSyncValueAsNumberLabel"); Element multiSync = ElementFactory.createInput("number"); multiSync.setAttribute("id", "multiSyncValue"); multiSync.addPropertyChangeListener("valueAsNumber", "blur", event -> { }); multiSync.addPropertyChangeListener("value", "input", event -> { }); multiSync.addEventListener("input", e -> { valueLabel .setText("Server value: " + multiSync.getProperty("value")); }); multiSync.addEventListener("blur", e -> { valueAsNumberLabel.setText("Server valueAsNumber: " + multiSync.getProperty("valueAsNumber")); }); getElement().appendChild(multiSync); add(valueLabel, valueAsNumberLabel); }
Example #12
Source File: SynchronizedPropertyView.java From flow with Apache License 2.0 | 5 votes |
private void addSimpleSync() { add(new Text("Synchronized on 'change' event")); Div label = new Div(); label.setId("syncOnChangeLabel"); InputSync syncOnChange = new InputSync(label, "change"); syncOnChange.setId("syncOnChange"); add(syncOnChange); add(label); }
Example #13
Source File: ClientUpdateModeView.java From flow with Apache License 2.0 | 5 votes |
public ClientUpdateModeView() { ClientUpdateModeTemplate template = new ClientUpdateModeTemplate(); add(template); Element element = template.getElement(); Stream.of("value", "indirectAllowed", "indirect", "twoWayDenied") .forEach(propertyName -> { element.addPropertyChangeListener(propertyName, event -> add( new Text(propertyName + " changed to " + event.getValue()), new Html("<br>"))); }); }
Example #14
Source File: HelloWorldUI.java From flow with Apache License 2.0 | 5 votes |
@Override protected void init(VaadinRequest request) { NativeButton b = new NativeButton("Hello", e -> { add(new Text("Hello!")); }); add(b); }
Example #15
Source File: InjectScriptTagView.java From flow with Apache License 2.0 | 5 votes |
@ClientCallable private void changeValue() { getModel().setValue("<!-- <SCRIPT>"); getElement().removeAllChildren(); Div slot = new Div(new Text("<!-- <SCRIPT> --><!-- <SCRIPT></SCRIPT>")); slot.setId("slot-2"); getElement().appendChild(slot.getElement()); }
Example #16
Source File: DependencyView.java From flow with Apache License 2.0 | 5 votes |
@Override protected void onShow() { add(new Text( "This test initially loads a stylesheet which makes all text red, a JavaScript for logging window messages, a JavaScript for handling body click events and an HTML which sends a window message"), new Hr(), new Hr()); Div clickBody = new Div(); clickBody.setText("Hello, click the body please"); clickBody.setId("hello"); add(clickBody); NativeButton jsOrder = new NativeButton("Test JS order", e -> { getPage().addJavaScript("/test-files/js/set-global-var.js"); getPage().addJavaScript("/test-files/js/read-global-var.js", LoadMode.LAZY); }); jsOrder.setId("loadJs"); NativeButton allBlue = new NativeButton( "Load 'everything blue' stylesheet", e -> { getPage().addStyleSheet( "/test-files/css/allblueimportant.css"); }); allBlue.setId("loadBlue"); NativeButton loadUnavailableResources = new NativeButton( "Load unavailable resources", e -> { getPage().addStyleSheet("/not-found.css"); getPage().addJavaScript("/not-found.js"); }); loadUnavailableResources.setId("loadUnavailableResources"); Div log = new Div(); log.setId("log"); add(jsOrder, allBlue, loadUnavailableResources, new Hr(), log); }
Example #17
Source File: ServerSideForwardView.java From flow with Apache License 2.0 | 5 votes |
public ServerSideForwardView() { add(new Text("Server view forward")); setId("serverForwardView"); final NativeButton forwardViewButton = new NativeButton( "Open Server View which does forward to Client View", buttonClickEvent -> { final UI ui = buttonClickEvent.getSource().getUI().get(); ui.navigate(ForwardView.class); }); forwardViewButton.setId("goToServerForwardView"); add(forwardViewButton); }
Example #18
Source File: DnDCustomComponentView.java From flow with Apache License 2.0 | 5 votes |
public DnDCustomComponentView() { Stream.of(EffectAllowed.values()).map(DraggableItem::new) .forEach(this::add); dropTarget = new Div(); dropTarget.add(new Text("Drop Here")); dropTarget.setWidth("200px"); dropTarget.setHeight("200px"); dropTarget.getStyle().set("border", "solid 1px pink"); add(dropTarget); DropTarget.create(dropTarget).addDropListener(event -> event.getSource() .add(new Span(event.getDragData().get().toString()))); }
Example #19
Source File: ValueContextTest.java From flow with Apache License 2.0 | 5 votes |
@Test public void getLocale_localeComesFromComponentUI() { UI.setCurrent(null); UI ui = new UI(); ui.setLocale(Locale.GERMAN); Text text = new Text(""); ui.add(text); ValueContext context = new ValueContext(text); Assert.assertEquals(Locale.GERMAN, context.getLocale().get()); }
Example #20
Source File: InjectScriptTagView.java From flow with Apache License 2.0 | 4 votes |
public InjectScriptTagView() { getModel().setValue("<!-- <script>"); Div slot = new Div(new Text("<!-- <script> --><!-- <script></script>")); slot.setId("slot-1"); getElement().appendChild(slot.getElement()); }
Example #21
Source File: ComponentWithExternalJavaScript.java From flow with Apache License 2.0 | 4 votes |
public ComponentWithExternalJavaScript() { add(new Text("A component with external JavaScript")); }
Example #22
Source File: AnchorTest.java From flow with Apache License 2.0 | 4 votes |
@Test public void createWithComponent() { Anchor anchor = new Anchor("#", new Text("Home")); Assert.assertEquals(anchor.getElement().getAttribute("href"), "#"); Assert.assertEquals(anchor.getElement().getText(), "Home"); }
Example #23
Source File: DnDView.java From flow with Apache License 2.0 | 4 votes |
public DnDView() { setWidth("1000px"); setHeight("800px"); getStyle().set("display", "flex"); eventLog = new Div(); eventLog.add(new Text("Events:")); eventLog.add(new NativeButton("Clear", event -> { eventLog.getChildren().filter(component -> component instanceof Div) .forEach(eventLog::remove); eventCounter = 0; })); eventLog.add(new NativeButton("Data: " + data, event -> { data = !data; event.getSource().setText("Data: " + data); })); eventLog.setHeightFull(); eventLog.setWidth("400px"); eventLog.getStyle().set("display", "inline-block").set("border", "2px " + "solid"); add(eventLog); Div startLane = createLane("start"); startLane.add(createDraggableBox(null)); Stream.of(EffectAllowed.values()).map(this::createDraggableBox) .forEach(startLane::add); Div noEffectLane = createDropLane(null); Div copyDropLane = createDropLane(DropEffect.COPY); Div moveDropLane = createDropLane(DropEffect.MOVE); Div linkDropLane = createDropLane(DropEffect.LINK); Div noneDropLane = createDropLane(DropEffect.NONE); Div deactivatedLane = createDropLane(DropEffect.COPY); deactivatedLane.setId("lane-deactivated"); deactivatedLane.getChildren().findFirst().ifPresent( component -> component.getElement().setText("deactivated")); DropTarget.configure(deactivatedLane, false); eventLog.add(createToggleDropTargetsButton(noEffectLane, copyDropLane, moveDropLane, linkDropLane, noneDropLane)); eventLog.add(createToggleDragSourcesButton(startLane)); add(startLane, noEffectLane, copyDropLane, moveDropLane, linkDropLane, noneDropLane, deactivatedLane); }
Example #24
Source File: JavaScriptReturnValueView.java From flow with Apache License 2.0 | 4 votes |
public NativeRadioButtonGroup(String caption) { getContent().add(new Text(caption)); this.group = caption.replaceAll(" ", "").toLowerCase(); }
Example #25
Source File: ComponentWithExternalJsModule.java From flow with Apache License 2.0 | 4 votes |
public ComponentWithExternalJsModule() { add(new Text("A component with external JsModule")); }
Example #26
Source File: MemoryLeakUI.java From flow with Apache License 2.0 | 4 votes |
@Override protected void init(VaadinRequest request) { NativeButton button = new NativeButton("Hello", e -> add(new Text("Hello"))); button.setId("hello"); add(button); }
Example #27
Source File: NativeRadioButtonGroup.java From flow with Apache License 2.0 | 4 votes |
public NativeRadioButtonGroup(String caption) { getContent().add(new Text(caption)); this.group = caption.replaceAll(" ", "").toLowerCase(); getContent().getStyle().set("display", "block"); }
Example #28
Source File: MainLayout.java From flow with Apache License 2.0 | 4 votes |
public MainLayout() { add(new Text("Main layout")); setId("mainLayout"); }
Example #29
Source File: EmptyUI.java From flow with Apache License 2.0 | 4 votes |
public EmptyUI() { setId("emptyUi"); add(new Text("Empty view")); }
Example #30
Source File: PushView.java From flow with Apache License 2.0 | 4 votes |
public PushView() { setId("pushView"); add(new Text("Push View")); }