Skip to content

Commit 376370e

Browse files
javier-godoypaodb
authored andcommitted
refactor: initialize ErrorWindow on attach
Also initialize it the first time that getChildren is called (even if it isn't attached) in order to allow reusing the dialog contents in ErrorView. Close #44
1 parent 32b58fc commit 376370e

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/main/java/com/flowingcode/vaadin/addons/errorwindow/ErrorWindow.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,9 +32,11 @@
3232
import com.vaadin.flow.component.orderedlayout.FlexComponent.Alignment;
3333
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
3434
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
35+
import com.vaadin.flow.shared.Registration;
3536
import java.io.ByteArrayOutputStream;
3637
import java.io.PrintWriter;
3738
import java.util.UUID;
39+
import java.util.stream.Stream;
3840
import org.slf4j.Logger;
3941
import org.slf4j.LoggerFactory;
4042
import org.vaadin.olli.ClipboardHelper;
@@ -64,6 +66,8 @@ public class ErrorWindow extends Dialog {
6466

6567
private ErrorWindowI18n i18n;
6668

69+
private Registration attachListenerRegistration;
70+
6771
public ErrorWindow(final Throwable cause) {
6872
this(cause, null, isProductionMode(), ErrorWindowI18n.createDefault());
6973
}
@@ -96,7 +100,22 @@ public ErrorWindow(
96100
this.errorMessage = errorMessage;
97101
this.productionMode = productionMode;
98102
this.i18n = i18n;
99-
initWindow();
103+
104+
attachListenerRegistration = addAttachListener(ev -> {
105+
attachListenerRegistration = null;
106+
ev.unregisterListener();
107+
initWindow();
108+
});
109+
}
110+
111+
@Override
112+
public Stream<Component> getChildren() {
113+
if (attachListenerRegistration != null) {
114+
attachListenerRegistration.remove();
115+
attachListenerRegistration = null;
116+
initWindow();
117+
}
118+
return super.getChildren();
100119
}
101120

102121
public ErrorWindow(ErrorDetails errorDetails) {

0 commit comments

Comments
 (0)