|
| 1 | +/* |
| 2 | + * Copyright 2000-2025 Vaadin Ltd. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | + * use this file except in compliance with the License. You may obtain a copy of |
| 6 | + * the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations under |
| 14 | + * the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.vaadin.flow.uitest.ui; |
| 18 | + |
| 19 | +import com.vaadin.flow.component.ClickEvent; |
| 20 | +import com.vaadin.flow.component.Component; |
| 21 | +import com.vaadin.flow.component.ComponentEventListener; |
| 22 | +import com.vaadin.flow.component.Text; |
| 23 | +import com.vaadin.flow.component.UI; |
| 24 | +import com.vaadin.flow.component.html.Div; |
| 25 | +import com.vaadin.flow.component.html.NativeButton; |
| 26 | +import com.vaadin.flow.component.html.NativeDetails; |
| 27 | +import com.vaadin.flow.component.html.Span; |
| 28 | +import com.vaadin.flow.router.Route; |
| 29 | + |
| 30 | +@Route(value = "com.vaadin.flow.uitest.ui.AllowInertSynchronizedPropertyView") |
| 31 | +public class AllowInertSynchronizedPropertyView extends AbstractDivView { |
| 32 | + |
| 33 | + public static final String OPEN_MODAL_BUTTON = "modal-dialog-button"; |
| 34 | + public static final String READ_NATIVE_DETAILS_STATE_BUTTON = "read-native-details-state-button"; |
| 35 | + public static final String NATIVE_DETAILS_STATE = "native-details-state"; |
| 36 | + public static final String NATIVE_DETAILS_SUMMARY = "native-details-summary"; |
| 37 | + |
| 38 | + private NativeDetails nativeDetails; |
| 39 | + private Span state; |
| 40 | + |
| 41 | + @Override |
| 42 | + protected void onShow() { |
| 43 | + add(createOpenDialogButton(OPEN_MODAL_BUTTON)); |
| 44 | + |
| 45 | + nativeDetails = new NativeDetails(); |
| 46 | + add(nativeDetails); |
| 47 | + |
| 48 | + Span summary = new Span("Native details summary"); |
| 49 | + summary.setId(NATIVE_DETAILS_SUMMARY); |
| 50 | + nativeDetails.setSummary(summary); |
| 51 | + |
| 52 | + state = new Span("unknown"); |
| 53 | + state.setId(NATIVE_DETAILS_STATE); |
| 54 | + add(state); |
| 55 | + } |
| 56 | + |
| 57 | + private Component createOpenDialogButton(String id) { |
| 58 | + final NativeButton button = createButton("Open modal dialog", |
| 59 | + event -> new Dialog().open()); |
| 60 | + button.setId(id); |
| 61 | + return button; |
| 62 | + } |
| 63 | + |
| 64 | + private NativeButton createButton(String caption, |
| 65 | + ComponentEventListener<ClickEvent<NativeButton>> listener) { |
| 66 | + final NativeButton button = new NativeButton(); |
| 67 | + button.setText(caption); |
| 68 | + button.addClickListener(listener); |
| 69 | + button.getStyle().set("border", "1px solid black"); |
| 70 | + button.setWidth("100px"); |
| 71 | + return button; |
| 72 | + } |
| 73 | + |
| 74 | + public class Dialog extends Div { |
| 75 | + |
| 76 | + public Dialog() { |
| 77 | + final NativeButton readNativeDetailsStateButton = new NativeButton( |
| 78 | + "Read Native Details State", event -> { |
| 79 | + if (nativeDetails.isOpen()) { |
| 80 | + state.setText("opened"); |
| 81 | + } else { |
| 82 | + state.setText("closed"); |
| 83 | + } |
| 84 | + }); |
| 85 | + readNativeDetailsStateButton |
| 86 | + .setId(READ_NATIVE_DETAILS_STATE_BUTTON); |
| 87 | + |
| 88 | + add(new Text("A modal dialog"), readNativeDetailsStateButton); |
| 89 | + |
| 90 | + getStyle().set("position", "fixed").set("inset", "50% 50%") |
| 91 | + .set("border", "1px solid black"); |
| 92 | + } |
| 93 | + |
| 94 | + public void open() { |
| 95 | + final UI ui = UI.getCurrent(); |
| 96 | + ui.addModal(this); |
| 97 | + } |
| 98 | + } |
| 99 | +} |
0 commit comments