Java 类com.vaadin.server.ResourceReference 实例源码

项目:vaadin-combobox-multiselect    文件:ComboBoxMultiselect.java   
/**
 * 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);
        }
    });
}
项目:vaadin-combobox-multiselect    文件:ComboBoxMultiselect.java   
/**
 * 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);
        }
    });
}
项目:metl    文件:ReleasesView.java   
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);
    }
项目:metl    文件:EditAgentPanel.java   
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);
}
项目:metl    文件:ExecutionRunPanel.java   
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);
    }
}
项目:metl    文件:ExportDialog.java   
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);
    }
项目:context-menu    文件:ContextMenu.java   
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;
}