Search in sources :

Example 1 with ExportDisplay

use of com.haulmont.cuba.gui.export.ExportDisplay in project cuba by cuba-platform.

the class FileDownloadHelper method initGeneratedColumn.

/**
 * Initializes a table column for downloading files.
 *
 * @param table         table displaying some entity
 * @param fileProperty  property of the entity which is a reference to {@link FileDescriptor}
 */
public static void initGeneratedColumn(final Table table, final String fileProperty) {
    final ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.NAME);
    final ExportDisplay exportDisplay = AppBeans.get(ExportDisplay.NAME);
    table.addGeneratedColumn(fileProperty + ".name", new Table.ColumnGenerator() {

        @Override
        public Component generateCell(final Entity entity) {
            final FileDescriptor fd = entity.getValueEx(fileProperty);
            if (fd == null) {
                return componentsFactory.createComponent(Label.class);
            }
            if (PersistenceHelper.isNew(fd)) {
                Label label = componentsFactory.createComponent(Label.class);
                label.setValue(fd.getName());
                return label;
            } else {
                Button button = componentsFactory.createComponent(Button.class);
                button.setStyleName("link");
                button.setAction(new AbstractAction("download") {

                    @Override
                    public void actionPerform(Component component) {
                        exportDisplay.show(fd);
                    }

                    @Override
                    public String getCaption() {
                        return fd.getName();
                    }
                });
                return button;
            }
        }
    });
}
Also used : ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) Entity(com.haulmont.cuba.core.entity.Entity) ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor)

Example 2 with ExportDisplay

use of com.haulmont.cuba.gui.export.ExportDisplay in project cuba by cuba-platform.

the class CompanionDependencyInjector method getInjectedInstance.

private Object getInjectedInstance(Class<?> type, String name, AnnotatedElement element) {
    if (Component.class.isAssignableFrom(type)) {
        // Injecting a UI component
        return frameOwner.getComponent(name);
    } else if (Datasource.class.isAssignableFrom(type)) {
        // Injecting a datasource
        return frameOwner.getDsContext().get(name);
    } else if (DsContext.class.isAssignableFrom(type)) {
        // Injecting the DsContext
        return frameOwner.getDsContext();
    } else if (DataSupplier.class.isAssignableFrom(type)) {
        // Injecting the DataSupplier
        return frameOwner.getDsContext().getDataSupplier();
    } else if (FrameContext.class.isAssignableFrom(type)) {
        // Injecting the FrameContext
        return frameOwner.getContext();
    } else if (Action.class.isAssignableFrom(type)) {
        // Injecting an action
        return ComponentsHelper.findAction(name, frameOwner.getWrappedFrame());
    } else if (ExportDisplay.class.isAssignableFrom(type)) {
        // Injecting an ExportDisplay
        ExportDisplay exportDisplay = beanLocator.get(ExportDisplay.NAME);
        exportDisplay.setFrame(frameOwner.getWrappedFrame());
        return exportDisplay;
    } else if (ThemeConstants.class.isAssignableFrom(type)) {
        // Injecting a Theme
        ThemeConstantsManager themeManager = beanLocator.get(ThemeConstantsManager.NAME);
        return themeManager.getConstants();
    } else if (Logger.class == type && element instanceof Field) {
        return LoggerFactory.getLogger(((Field) element).getDeclaringClass());
    } else if (Config.class.isAssignableFrom(type)) {
        ClientConfiguration configuration = beanLocator.get(Configuration.NAME);
        // noinspection unchecked
        return configuration.getConfigCached((Class<? extends Config>) type);
    } else {
        Object instance;
        // Try to find a Spring bean
        Map<String, ?> beans = beanLocator.getAll(type);
        if (!beans.isEmpty()) {
            instance = beans.get(name);
            // If a bean with required name found, return it. Otherwise return first found.
            if (instance != null)
                return instance;
            else
                return beans.values().iterator().next();
        }
        // There are no Spring beans of required type - the last option is Frame
        if (type.isAssignableFrom(FrameOwner.class)) {
            return frameOwner;
        }
        return null;
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Action(com.haulmont.cuba.gui.components.Action) ThemeConstantsManager(com.haulmont.cuba.gui.theme.ThemeConstantsManager) Config(com.haulmont.cuba.core.config.Config) Logger(org.slf4j.Logger) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) Field(java.lang.reflect.Field) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier) ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) ClientConfiguration(com.haulmont.cuba.client.ClientConfiguration)

Example 3 with ExportDisplay

use of com.haulmont.cuba.gui.export.ExportDisplay in project cuba by cuba-platform.

the class ServerLogWindow method downloadLog.

public void downloadLog() {
    final String fileName = logFileNameField.getValue();
    if (fileName != null) {
        try {
            JmxInstance selectedConnection = getSelectedConnection();
            // check if we have many suitable JmxControlBean instances
            // show dialog with context select and size options if needed
            List<String> availableContexts = jmxRemoteLoggingAPI.getAvailableContexts(selectedConnection);
            long size = jmxRemoteLoggingAPI.getLogFileSize(selectedConnection, fileName);
            if (size <= LogArchiver.LOG_TAIL_FOR_PACKING_SIZE && availableContexts.size() == 1) {
                LogDataProvider dataProvider = new LogDataProvider(selectedConnection, fileName, availableContexts.get(0), false);
                dataProvider.obtainUrl();
                ExportDisplay exportDisplay = AppConfig.createExportDisplay(this);
                exportDisplay.show(dataProvider, fileName + ".zip");
            } else {
                openWindow("serverLogDownloadOptionsDialog", OpenType.DIALOG, ParamsMap.of("logFileName", fileName, "connection", selectedConnection, "logFileSize", size, "remoteContextList", availableContexts));
            }
        } catch (RuntimeException | LogControlException e) {
            showNotification(getMessage("exception.logControl"), NotificationType.ERROR);
            log.error("Error downloading log", e);
        }
    } else {
        showNotification(getMessage("log.notSelected"), NotificationType.HUMANIZED);
    }
}
Also used : ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) LogControlException(com.haulmont.cuba.core.sys.logging.LogControlException) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) LogDataProvider(com.haulmont.cuba.web.export.LogDataProvider)

Example 4 with ExportDisplay

use of com.haulmont.cuba.gui.export.ExportDisplay in project cuba by cuba-platform.

the class DomainProvider method run.

@Override
public void run() {
    DomainDescriptionService service = beanLocator.get(DomainDescriptionService.NAME);
    String description = service.getDomainDescription();
    ExportDisplay exportDisplay = beanLocator.getPrototype(ExportDisplay.NAME, true);
    exportDisplay.show(new ByteArrayDataProvider(description.getBytes(StandardCharsets.UTF_8)), "domain-description.html", ExportFormat.HTML);
}
Also used : ByteArrayDataProvider(com.haulmont.cuba.gui.export.ByteArrayDataProvider) ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) DomainDescriptionService(com.haulmont.cuba.core.app.DomainDescriptionService)

Example 5 with ExportDisplay

use of com.haulmont.cuba.gui.export.ExportDisplay in project cuba by cuba-platform.

the class ControllerDependencyInjector method getInjectedInstance.

protected Object getInjectedInstance(Class<?> type, String name, Class annotationClass, AnnotatedElement element) {
    if (annotationClass == WindowParam.class) {
        // Injecting a parameter
        return params.get(name);
    } else if (Component.class.isAssignableFrom(type)) {
        // Injecting a UI component
        return frame.getComponent(name);
    } else if (Datasource.class.isAssignableFrom(type)) {
        // Injecting a datasource
        return frame.getDsContext().get(name);
    } else if (DsContext.class.isAssignableFrom(type)) {
        // Injecting the DsContext
        return frame.getDsContext();
    } else if (DataSupplier.class.isAssignableFrom(type)) {
        // Injecting the DataSupplier
        return frame.getDsContext().getDataSupplier();
    } else if (FrameContext.class.isAssignableFrom(type)) {
        // Injecting the FrameContext
        return frame.getContext();
    } else if (Action.class.isAssignableFrom(type)) {
        // Injecting an action
        return ComponentsHelper.findAction(name, frame);
    } else if (ExportDisplay.class.isAssignableFrom(type)) {
        // Injecting an ExportDisplay
        return AppConfig.createExportDisplay(frame);
    } else if (ThemeConstants.class.isAssignableFrom(type)) {
        // Injecting a Theme
        ThemeConstantsManager themeManager = (ThemeConstantsManager) applicationContext.getBean(ThemeConstantsManager.NAME);
        return themeManager.getConstants();
    } else if (Config.class.isAssignableFrom(type)) {
        ClientConfiguration configuration = (ClientConfiguration) applicationContext.getBean(Configuration.NAME);
        // noinspection unchecked
        return configuration.getConfigCached((Class<? extends Config>) type);
    } else if (Logger.class == type && element instanceof Field) {
        return LoggerFactory.getLogger(((Field) element).getDeclaringClass());
    } else {
        Object instance;
        // Try to find a Spring bean
        Map<String, ?> beans = applicationContext.getBeansOfType(type, true, true);
        if (!beans.isEmpty()) {
            instance = beans.get(name);
            // If a bean with required name found, return it. Otherwise return first found.
            if (instance != null) {
                return instance;
            } else {
                return beans.values().iterator().next();
            }
        }
        // There are no Spring beans of required type - the last option is Companion
        if (frame instanceof AbstractFrame) {
            instance = ((AbstractFrame) frame).getCompanion();
            if (instance != null && type.isAssignableFrom(instance.getClass())) {
                return instance;
            }
        }
    }
    return null;
}
Also used : DsContext(com.haulmont.cuba.gui.data.DsContext) ThemeConstantsManager(com.haulmont.cuba.gui.theme.ThemeConstantsManager) Config(com.haulmont.cuba.core.config.Config) Logger(org.slf4j.Logger) Field(java.lang.reflect.Field) ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) ClientConfiguration(com.haulmont.cuba.client.ClientConfiguration)

Aggregations

ExportDisplay (com.haulmont.cuba.gui.export.ExportDisplay)9 ClientConfiguration (com.haulmont.cuba.client.ClientConfiguration)3 ThemeConstantsManager (com.haulmont.cuba.gui.theme.ThemeConstantsManager)3 Field (java.lang.reflect.Field)3 Config (com.haulmont.cuba.core.config.Config)2 Entity (com.haulmont.cuba.core.entity.Entity)2 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)2 DataSupplier (com.haulmont.cuba.gui.data.DataSupplier)2 Datasource (com.haulmont.cuba.gui.data.Datasource)2 ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)2 Logger (org.slf4j.Logger)2 DomainDescriptionService (com.haulmont.cuba.core.app.DomainDescriptionService)1 JmxInstance (com.haulmont.cuba.core.entity.JmxInstance)1 BeanLocator (com.haulmont.cuba.core.global.BeanLocator)1 DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)1 Messages (com.haulmont.cuba.core.global.Messages)1 LogControlException (com.haulmont.cuba.core.sys.logging.LogControlException)1 ComponentsHelper (com.haulmont.cuba.gui.ComponentsHelper)1 Dialogs (com.haulmont.cuba.gui.Dialogs)1 Notifications (com.haulmont.cuba.gui.Notifications)1