use of com.haulmont.cuba.gui.xml.layout.ComponentsFactory 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.xml.layout.ComponentsFactory in project cuba by cuba-platform.
the class LinkColumnHelper method initColumn.
public static void initColumn(Table table, final String propertyName, final Handler handler) {
final ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.NAME);
table.addGeneratedColumn(propertyName, new Table.ColumnGenerator() {
@Override
public Component generateCell(final Entity entity) {
// //process properties like building.house.room
String[] props = propertyName.split("\\.");
Instance nestedEntity = entity;
for (int i = 0; i < props.length - 1; i++) {
nestedEntity = nestedEntity.getValue(props[i]);
if (nestedEntity == null) {
break;
}
}
final Object value = (nestedEntity == null) ? null : nestedEntity.getValue(props[props.length - 1]);
if (value != null) {
Button button = componentsFactory.createComponent(Button.class);
button.setStyleName("link");
button.setAction(new AbstractAction("open") {
@Override
public void actionPerform(Component component) {
handler.onClick(entity);
}
@Override
public String getCaption() {
String str;
Datatype datatype = Datatypes.get(value.getClass());
if (datatype != null) {
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
str = datatype.format(value, sessionSource.getLocale());
} else {
str = value.toString();
}
return str;
}
});
button.setStyleName("link");
return button;
}
return null;
}
});
}
use of com.haulmont.cuba.gui.xml.layout.ComponentsFactory in project cuba by cuba-platform.
the class CustomOperationEditor method createComponent.
@Override
protected Component createComponent() {
ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.class);
BoxLayout layout = componentsFactory.createComponent(VBoxLayout.class);
return layout;
}
use of com.haulmont.cuba.gui.xml.layout.ComponentsFactory in project cuba by cuba-platform.
the class WebTabSheet method addLazyTab.
@Override
public TabSheet.Tab addLazyTab(String name, Element descriptor, ComponentLoader loader) {
// todo replace
ComponentsFactory cf = AppBeans.get(ComponentsFactory.NAME);
CssLayout tabContent = cf.createComponent(CssLayout.NAME);
tabContent.setStyleName("c-tabsheet-lazytab");
tabContent.setSizeFull();
Tab tab = new Tab(name, tabContent);
tabs.put(name, tab);
com.vaadin.ui.Component tabComponent = tabContent.unwrapComposition(com.vaadin.ui.Component.class);
tabMapping.put(tabComponent, new ComponentDescriptor(name, tabContent));
com.vaadin.ui.TabSheet.Tab tabControl = this.component.addTab(tabComponent);
getLazyTabs().add(tabComponent);
this.component.addSelectedTabChangeListener(new LazyTabChangeListener(tabContent, descriptor, loader));
context = loader.getContext();
if (!postInitTaskAdded && context instanceof ComponentLoader.ComponentContext) {
((ComponentLoader.ComponentContext) context).addPostInitTask((c, w) -> initComponentTabChangeListener());
postInitTaskAdded = true;
}
if (getDebugId() != null) {
this.component.setTestId(tabControl, AppUI.getCurrent().getTestIdManager().getTestId(getDebugId() + "." + name));
}
if (AppUI.getCurrent().isTestMode()) {
this.component.setCubaId(tabControl, name);
}
if (context instanceof ComponentLoader.ComponentContext) {
tabContent.setFrame(((ComponentLoader.ComponentContext) context).getFrame());
} else {
throw new IllegalStateException("'context' must implement " + "com.haulmont.cuba.gui.xml.layout.ComponentLoader.ComponentContext");
}
return tab;
}
use of com.haulmont.cuba.gui.xml.layout.ComponentsFactory in project cuba by cuba-platform.
the class DynamicAttributeCustomFieldGenerator method generateField.
@Override
public Component generateField(Datasource datasource, String propertyId) {
ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.class);
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(datasource.getMetaClass(), propertyId);
if (metaPropertyPath == null) {
log.error("MetaPropertyPath for dynamic attribute {} not found", propertyId);
return null;
}
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaPropertyPath.getMetaProperty());
if (categoryAttribute == null) {
log.error("Dynamic attribute {} not found", propertyId);
return null;
}
listEditor.setEntityJoinClause(categoryAttribute.getJoinClause());
listEditor.setEntityWhereClause(categoryAttribute.getWhereClause());
ListEditor.ItemType itemType = listEditorItemTypeFromDynamicAttrType(categoryAttribute.getDataType());
listEditor.setItemType(itemType);
Metadata metadata = AppBeans.get(Metadata.class);
Scripting scripting = AppBeans.get(Scripting.class);
if (!Strings.isNullOrEmpty(categoryAttribute.getEntityClass())) {
Class<?> clazz = scripting.loadClass(categoryAttribute.getEntityClass());
if (clazz == null) {
log.error("Unable to find class of entity {} for dynamic attribute {}", categoryAttribute.getEntityClass(), categoryAttribute.getCode());
return null;
}
MetaClass metaClass = metadata.getClassNN(clazz);
listEditor.setEntityName(metaClass.getName());
listEditor.setUseLookupField(BooleanUtils.isTrue(categoryAttribute.getLookup()));
}
// noinspection unchecked
datasource.addStateChangeListener(e -> {
if (e.getState() == Datasource.State.VALID) {
Object value = datasource.getItem().getValue(propertyId);
if (value != null && value instanceof Collection) {
listEditor.setValue(value);
}
}
});
listEditor.addValueChangeListener(e -> {
datasource.getItem().setValue(propertyId, e.getValue());
});
listEditor.setWidthFull();
return listEditor;
}
Aggregations