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;
}
}
});
}
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;
}
}
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);
}
}
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);
}
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;
}
Aggregations