Refactor UI Error Handler. Need to put UI in constructor. So the message
is shown in the same browser window. Signed-off-by: Melanie Retter <melanie.retter@bosch-si.com>
This commit is contained in:
@@ -18,10 +18,15 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.vaadin.server.ClientConnector.ConnectorErrorEvent;
|
||||
import com.vaadin.server.DefaultErrorHandler;
|
||||
import com.vaadin.server.ErrorEvent;
|
||||
import com.vaadin.server.Page;
|
||||
import com.vaadin.shared.Connector;
|
||||
import com.vaadin.ui.AbstractComponent;
|
||||
import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.Notification.Type;
|
||||
import com.vaadin.ui.UI;
|
||||
|
||||
/**
|
||||
* Default handler for SP UI.
|
||||
@@ -38,10 +43,23 @@ public class HawkbitUIErrorHandler extends DefaultErrorHandler {
|
||||
|
||||
final Optional<Page> originError = getPageOriginError(event);
|
||||
|
||||
final HawkbitErrorNotificationMessage message = buildNotification(getRootExceptionFrom(event));
|
||||
|
||||
if (originError.isPresent()) {
|
||||
final HawkbitErrorNotificationMessage message = buildNotification(getRootExceptionFrom(event));
|
||||
message.show(originError.get());
|
||||
final Connector connector = ((ConnectorErrorEvent) event).getConnector();
|
||||
// in case of BulkUpload
|
||||
if (connector instanceof UI) {
|
||||
((UI) (((ConnectorErrorEvent) event).getConnector())).access(() -> message.show(originError.get()));
|
||||
return;
|
||||
}
|
||||
// Other UI components
|
||||
if (connector instanceof AbstractComponent) {
|
||||
((AbstractComponent) connector).getUI().access(() -> message.show(originError.get()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Default
|
||||
HawkbitErrorNotificationMessage.show(message.getCaption(), message.getDescription(), Type.HUMANIZED_MESSAGE);
|
||||
}
|
||||
|
||||
private static Throwable getRootExceptionFrom(final ErrorEvent event) {
|
||||
@@ -66,7 +84,7 @@ public class HawkbitUIErrorHandler extends DefaultErrorHandler {
|
||||
return Optional.fromNullable(errorOrigin.getUI().getPage());
|
||||
}
|
||||
|
||||
return Optional.of(Page.getCurrent());
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
protected HawkbitErrorNotificationMessage buildNotification(final Throwable exception) {
|
||||
|
||||
@@ -100,6 +100,7 @@ public class BulkUploadHandler extends CustomComponent
|
||||
final TargetBulkUpdateWindowLayout targetBulkUpdateWindowLayout;
|
||||
|
||||
private transient EntityFactory entityFactory;
|
||||
private final UI uiInstance;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -111,8 +112,9 @@ public class BulkUploadHandler extends CustomComponent
|
||||
*/
|
||||
public BulkUploadHandler(final TargetBulkUpdateWindowLayout targetBulkUpdateWindowLayout,
|
||||
final TargetManagement targetManagement, final ManagementUIState managementUIState,
|
||||
final DeploymentManagement deploymentManagement, final I18N i18n) {
|
||||
final DeploymentManagement deploymentManagement, final I18N i18n, final UI uiInstance) {
|
||||
this.targetBulkUpdateWindowLayout = targetBulkUpdateWindowLayout;
|
||||
this.uiInstance = uiInstance;
|
||||
this.comboBox = targetBulkUpdateWindowLayout.getDsNamecomboBox();
|
||||
this.descTextArea = targetBulkUpdateWindowLayout.getDescTextArea();
|
||||
this.targetManagement = targetManagement;
|
||||
@@ -213,7 +215,6 @@ public class BulkUploadHandler extends CustomComponent
|
||||
* below event.
|
||||
*/
|
||||
eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_UPLOAD_PROCESS_STARTED));
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
innerCounter++;
|
||||
readEachLine(line, innerCounter, totalFileSize);
|
||||
@@ -222,9 +223,7 @@ public class BulkUploadHandler extends CustomComponent
|
||||
} catch (final IOException e) {
|
||||
LOG.error("Error reading file {}", tempFile.getName(), e);
|
||||
} catch (final RuntimeException e) {
|
||||
if (UI.getCurrent() != null) {
|
||||
UI.getCurrent().getErrorHandler().error(new com.vaadin.server.ErrorEvent(e));
|
||||
}
|
||||
uiInstance.getErrorHandler().error(new ConnectorErrorEvent(uiInstance, e));
|
||||
} finally {
|
||||
deleteFile();
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.Link;
|
||||
import com.vaadin.ui.ProgressBar;
|
||||
import com.vaadin.ui.TextArea;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.Window;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
@@ -174,7 +175,7 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
|
||||
|
||||
private BulkUploadHandler getBulkUploadHandler() {
|
||||
final BulkUploadHandler bulkUploadHandler = new BulkUploadHandler(this, targetManagement, managementUIState,
|
||||
deploymentManagement, i18n);
|
||||
deploymentManagement, i18n, UI.getCurrent());
|
||||
bulkUploadHandler.buildLayout();
|
||||
bulkUploadHandler.addStyleName(SPUIStyleDefinitions.BULK_UPLOAD_BUTTON);
|
||||
return bulkUploadHandler;
|
||||
|
||||
Reference in New Issue
Block a user