use of com.haulmont.cuba.client.ClientConfig in project cuba by cuba-platform.
the class DesktopWindow method close.
@Override
public boolean close(final String actionId) {
if (!forceClose) {
if (!delegate.preClose(actionId))
return false;
}
ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
if (!forceClose && isModified()) {
final Committable committable = (getWrapper() instanceof Committable) ? (Committable) getWrapper() : (this instanceof Committable) ? (Committable) this : null;
if ((committable != null) && clientConfig.getUseSaveConfirmation()) {
windowManager.showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("saveUnsaved"), MessageType.WARNING, new Action[] { new DialogAction(Type.OK, Status.PRIMARY).withCaption(messages.getMainMessage("closeUnsaved.save")).withHandler(event -> {
committable.commitAndClose();
}), new BaseAction("discard").withIcon("icons/cancel.png").withCaption(messages.getMainMessage("closeUnsaved.discard")).withHandler(event -> {
committable.close(actionId, true);
}), new DialogAction(Type.CANCEL).withIcon(null).withHandler(event -> {
doAfterClose = null;
}) });
} else {
windowManager.showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("closeUnsaved"), MessageType.WARNING, new Action[] { new DialogAction(Type.YES).withHandler(event -> {
getWrapper().close(actionId, true);
}), new DialogAction(Type.NO, Status.PRIMARY).withHandler(event -> {
doAfterClose = null;
}) });
}
return false;
}
if (!clientConfig.getManualScreenSettingsSaving()) {
if (delegate.getWrapper() != null) {
delegate.getWrapper().saveSettings();
} else {
saveSettings();
}
}
delegate.disposeComponents();
windowManager.close(this);
boolean res = onClose(actionId);
if (res && doAfterClose != null) {
doAfterClose.run();
}
stopTimers();
userActionsLog.trace("Window {} was closed", getId());
return res;
}
use of com.haulmont.cuba.client.ClientConfig in project cuba by cuba-platform.
the class NoUserSessionHandler method showNoUserSessionDialog.
protected void showNoUserSessionDialog(App app) {
Messages messages = AppBeans.get(Messages.NAME);
Window dialog = new NoUserSessionExceptionDialog();
dialog.setStyleName("c-nousersession-dialog");
dialog.setCaption(messages.getMainMessage("dialogs.Information", locale));
dialog.setClosable(false);
dialog.setResizable(false);
dialog.setModal(true);
AppUI ui = app.getAppUI();
if (ui.isTestMode()) {
dialog.setCubaId("optionDialog");
dialog.setId(ui.getTestIdManager().getTestId("optionDialog"));
}
Label messageLab = new CubaLabel();
messageLab.setWidthUndefined();
messageLab.setValue(messages.getMainMessage("noUserSession.message", locale));
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(true);
layout.setWidthUndefined();
layout.setStyleName("c-nousersession-dialog-layout");
layout.setSpacing(true);
dialog.setContent(layout);
Button reloginBtn = new Button();
if (ui.isTestMode()) {
reloginBtn.setCubaId("reloginBtn");
reloginBtn.setId(ui.getTestIdManager().getTestId("reloginBtn"));
}
reloginBtn.addStyleName(WebButton.ICON_STYLE);
reloginBtn.addStyleName("c-primary-action");
reloginBtn.addClickListener(event -> relogin());
reloginBtn.setCaption(messages.getMainMessage(Type.OK.getMsgKey()));
String iconName = AppBeans.get(Icons.class).get(Type.OK.getIconKey());
reloginBtn.setIcon(AppBeans.get(IconResolver.class).getIconResource(iconName));
ClientConfig clientConfig = AppBeans.get(Configuration.class).getConfig(ClientConfig.class);
setClickShortcut(reloginBtn, clientConfig.getCommitShortcut());
reloginBtn.focus();
layout.addComponent(messageLab);
layout.addComponent(reloginBtn);
layout.setComponentAlignment(reloginBtn, Alignment.BOTTOM_RIGHT);
ui.addWindow(dialog);
dialog.center();
}
use of com.haulmont.cuba.client.ClientConfig in project cuba by cuba-platform.
the class FileLoaderClientImpl method saveStreamWithServlet.
protected void saveStreamWithServlet(FileDescriptor fd, Supplier<InputStream> inputStreamSupplier, @Nullable StreamingProgressListener streamingListener) throws FileStorageException, InterruptedException {
Object context = serverSelector.initContext();
String selectedUrl = serverSelector.getUrl(context);
if (selectedUrl == null) {
throw new FileStorageException(FileStorageException.Type.IO_EXCEPTION, fd.getName());
}
ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
String fileUploadContext = clientConfig.getFileUploadContext();
while (true) {
String url = selectedUrl + fileUploadContext + "?s=" + userSessionSource.getUserSession().getId() + "&f=" + fd.toUrlParam();
try (InputStream inputStream = inputStreamSupplier.get()) {
InputStreamProgressEntity.UploadProgressListener progressListener = null;
if (streamingListener != null) {
progressListener = streamingListener::onStreamingProgressChanged;
}
HttpPost method = new HttpPost(url);
method.setEntity(new InputStreamProgressEntity(inputStream, ContentType.APPLICATION_OCTET_STREAM, progressListener));
HttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager();
HttpClient client = HttpClientBuilder.create().setConnectionManager(connectionManager).build();
try {
HttpResponse response = client.execute(method);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
break;
} else {
log.debug("Unable to upload file to {}\n{}", url, response.getStatusLine());
selectedUrl = failAndGetNextUrl(context);
if (selectedUrl == null) {
throw new FileStorageException(FileStorageException.Type.fromHttpStatus(statusCode), fd.getName());
}
}
} catch (InterruptedIOException e) {
log.trace("Uploading has been interrupted");
throw new InterruptedException("File uploading is interrupted");
} catch (IOException e) {
log.debug("Unable to upload file to {}\n{}", url, e);
selectedUrl = failAndGetNextUrl(context);
if (selectedUrl == null) {
throw new FileStorageException(FileStorageException.Type.IO_EXCEPTION, fd.getName(), e);
}
} finally {
connectionManager.shutdown();
}
} catch (IOException | RetryUnsupportedException e) {
throw new FileStorageException(FileStorageException.Type.IO_EXCEPTION, fd.getName(), e);
}
}
}
use of com.haulmont.cuba.client.ClientConfig in project cuba by cuba-platform.
the class FileLoaderClientImpl method openStreamWithServlet.
protected InputStream openStreamWithServlet(FileDescriptor fd) throws FileStorageException {
ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
String fileDownloadContext = clientConfig.getFileDownloadContext();
Object context = serverSelector.initContext();
String selectedUrl = serverSelector.getUrl(context);
if (selectedUrl == null) {
throw new FileStorageException(FileStorageException.Type.IO_EXCEPTION, fd.getName());
}
while (true) {
String url = selectedUrl + fileDownloadContext + "?s=" + userSessionSource.getUserSession().getId() + "&f=" + fd.getId().toString();
HttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager();
HttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connectionManager).build();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse httpResponse = httpClient.execute(httpGet);
int httpStatus = httpResponse.getStatusLine().getStatusCode();
if (httpStatus == HttpStatus.SC_OK) {
HttpEntity httpEntity = httpResponse.getEntity();
if (httpEntity != null) {
return httpEntity.getContent();
} else {
log.debug("Unable to download file from {}\nHttpEntity is null", url);
selectedUrl = failAndGetNextUrl(context);
if (selectedUrl == null) {
throw new FileStorageException(FileStorageException.Type.IO_EXCEPTION, fd.getName());
}
}
} else {
log.debug("Unable to download file from {}\n{}", url, httpResponse.getStatusLine());
selectedUrl = failAndGetNextUrl(context);
if (selectedUrl == null) {
throw new FileStorageException(FileStorageException.Type.fromHttpStatus(httpStatus), fd.getName());
}
}
} catch (InterruptedIOException e) {
log.trace("Downloading has been interrupted");
throw new FileStorageException(FileStorageException.Type.IO_EXCEPTION, fd.getName(), e);
} catch (IOException ex) {
log.debug("Unable to download file from {}\n{}", url, ex);
selectedUrl = failAndGetNextUrl(context);
if (selectedUrl == null) {
throw new FileStorageException(FileStorageException.Type.IO_EXCEPTION, fd.getName(), ex);
}
}
}
}
use of com.haulmont.cuba.client.ClientConfig in project cuba by cuba-platform.
the class RemoveAction method setConfiguration.
@Inject
protected void setConfiguration(Configuration configuration) {
ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
setShortcut(clientConfig.getTableRemoveShortcut());
}
Aggregations