Search in sources :

Example 1 with ComponentsFactory

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

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;
        }
    });
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Table(com.haulmont.cuba.gui.components.Table) Instance(com.haulmont.chile.core.model.Instance) Datatype(com.haulmont.chile.core.datatypes.Datatype) ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) Button(com.haulmont.cuba.gui.components.Button) Component(com.haulmont.cuba.gui.components.Component) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction)

Example 3 with ComponentsFactory

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;
}
Also used : ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) VBoxLayout(com.haulmont.cuba.gui.components.VBoxLayout) BoxLayout(com.haulmont.cuba.gui.components.BoxLayout)

Example 4 with ComponentsFactory

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;
}
Also used : ComponentLoader(com.haulmont.cuba.gui.xml.layout.ComponentLoader) ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) CubaTabSheet(com.haulmont.cuba.web.widgets.CubaTabSheet)

Example 5 with ComponentsFactory

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;
}
Also used : ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) ListEditor(com.haulmont.cuba.gui.components.ListEditor) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) Metadata(com.haulmont.cuba.core.global.Metadata) Collection(java.util.Collection) Scripting(com.haulmont.cuba.core.global.Scripting)

Aggregations

ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)10 MetaClass (com.haulmont.chile.core.model.MetaClass)2 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)2 Entity (com.haulmont.cuba.core.entity.Entity)2 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)2 ExportDisplay (com.haulmont.cuba.gui.export.ExportDisplay)2 ComponentLoader (com.haulmont.cuba.gui.xml.layout.ComponentLoader)2 Datatype (com.haulmont.chile.core.datatypes.Datatype)1 Instance (com.haulmont.chile.core.model.Instance)1 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)1 Scripting (com.haulmont.cuba.core.global.Scripting)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 Op (com.haulmont.cuba.core.global.filter.Op)1 OpManager (com.haulmont.cuba.core.global.filter.OpManager)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 AbstractAction (com.haulmont.cuba.gui.components.AbstractAction)1 BoxLayout (com.haulmont.cuba.gui.components.BoxLayout)1 Button (com.haulmont.cuba.gui.components.Button)1