/** * Initialize the ComboBoxMultiselect with default settings and register client to server RPC implementation. */ private void init() { registerRpc(this.rpc); registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent)); addDataGenerator((final T data, final JsonObject jsonObject) -> { String caption = getItemCaptionGenerator().apply(data); if (caption == null) { caption = ""; } jsonObject.put(DataCommunicatorConstants.NAME, caption); final String style = this.itemStyleGenerator.apply(data); if (style != null) { jsonObject.put(ComboBoxMultiselectConstants.STYLE, style); } final Resource icon = getItemIconGenerator().apply(data); if (icon != null) { final String iconUrl = ResourceReference.create(icon, ComboBoxMultiselect.this, null) .getURL(); jsonObject.put(ComboBoxMultiselectConstants.ICON, iconUrl); } }); }
protected void downloadExport(final String export, String filename) { StreamSource ss = new StreamSource() { private static final long serialVersionUID = 1L; public InputStream getStream() { try { return new ByteArrayInputStream(export.getBytes(Charset.forName("utf-8"))); } catch (Exception e) { log.error("Failed to export configuration", e); CommonUiUtils.notify("Failed to export configuration.", Type.ERROR_MESSAGE); return null; } } }; String datetime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); StreamResource resource = new StreamResource(ss, String.format("%s-config-%s.json", filename, datetime)); final String KEY = "export"; setResource(KEY, resource); Page.getCurrent().open(ResourceReference.create(resource, this, KEY).getURL(), null); }
protected void exportConfiguration() { final String export = context.getImportExportService().exportAgent(agent.getId(), AppConstants.SYSTEM_USER); StreamSource ss = new StreamSource() { private static final long serialVersionUID = 1L; public InputStream getStream() { try { return new ByteArrayInputStream(export.getBytes()); } catch (Exception e) { log.error("Failed to export configuration", e); CommonUiUtils.notify("Failed to export configuration.", Type.ERROR_MESSAGE); return null; } } }; String datetime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); StreamResource resource = new StreamResource(ss, String.format("%s-config-%s.json", agent.getName().toLowerCase().replaceAll(" ", "-"), datetime)); final String KEY = "export"; setResource(KEY, resource); Page.getCurrent().open(ResourceReference.create(resource, this, KEY).getURL(), null); }
protected void download() { String stepId = (String) stepTable.getSelectedRow(); if (stepId != null) { final File file = executionService.getExecutionStepLog(stepId); StreamSource ss = new StreamSource() { private static final long serialVersionUID = 1L; public InputStream getStream() { try { return new FileInputStream(file); } catch (Exception e) { log.error("Failed to download log file", e); CommonUiUtils.notify("Failed to download log file", Type.ERROR_MESSAGE); return null; } } }; StreamResource resource = new StreamResource(ss, file.getName()); final String KEY = "export"; setResource(KEY, resource); Page.getCurrent().open(ResourceReference.create(resource, this, KEY).getURL(), null); } }
private List<MenuItemState> convertItemsToState(List<MenuItem> items) { if (items == null || items.size() == 0) { return null; } List<MenuItemState> state = new ArrayList<>(); for (MenuItem item : items) { MenuItemState menuItemState = new MenuItemState(); if (!item.isVisible()) { continue; } menuItemState.id = item.getId(); menuItemState.text = item.getText(); menuItemState.checkable = item.isCheckable(); menuItemState.checked = item.isChecked(); menuItemState.description = item.getDescription(); menuItemState.enabled = item.isEnabled(); menuItemState.separator = item.isSeparator(); menuItemState.icon = ResourceReference.create(item.getIcon(), this, ""); menuItemState.styleName = item.getStyleName(); menuItemState.childItems = convertItemsToState(item.getChildren()); state.add(menuItemState); } return state; }