Search in sources :

Example 11 with Property

use of com.vaadin.data.Property in project cuba by cuba-platform.

the class WebPickerField method setDatasource.

@SuppressWarnings("unchecked")
@Override
public void setDatasource(Datasource datasource, String property) {
    if ((datasource == null && property != null) || (datasource != null && property == null))
        throw new IllegalArgumentException("Datasource and property should be either null or not null at the same time");
    if (datasource == this.datasource && ((metaPropertyPath != null && metaPropertyPath.toString().equals(property)) || (metaPropertyPath == null && property == null)))
        return;
    if (this.datasource != null) {
        metaProperty = null;
        metaPropertyPath = null;
        component.setPropertyDataSource(null);
        this.datasource.removeItemChangeListener(securityWeakItemChangeListener);
        securityWeakItemChangeListener = null;
        this.datasource.removeItemChangeListener(weakItemChangeListener);
        weakItemChangeListener = null;
        this.datasource.removeItemPropertyChangeListener(weakItemPropertyChangeListener);
        weakItemPropertyChangeListener = null;
        this.datasource = null;
        if (itemWrapper != null) {
            itemWrapper.unsubscribe();
        }
        disableBeanValidator();
    }
    if (datasource != null) {
        checkDatasourceProperty(datasource, property);
        // noinspection unchecked
        this.datasource = datasource;
        metaPropertyPath = getResolvedMetaPropertyPath(datasource.getMetaClass(), property);
        metaProperty = metaPropertyPath.getMetaProperty();
        itemWrapper = createDatasourceWrapper(datasource, Collections.singleton(metaPropertyPath));
        Property itemProperty = itemWrapper.getItemProperty(metaPropertyPath);
        component.setPropertyDataSource(itemProperty);
        itemChangeListener = e -> {
            Object newValue = InstanceUtils.getValueEx(e.getItem(), metaPropertyPath.getPath());
            setValue(newValue);
        };
        weakItemChangeListener = new WeakItemChangeListener(datasource, itemChangeListener);
        // noinspection unchecked
        datasource.addItemChangeListener(weakItemChangeListener);
        itemPropertyChangeListener = e -> {
            if (!isBuffered() && e.getProperty().equals(metaPropertyPath.toString())) {
                setValue(e.getValue());
            }
        };
        weakItemPropertyChangeListener = new WeakItemPropertyChangeListener(datasource, itemPropertyChangeListener);
        // noinspection unchecked
        datasource.addItemPropertyChangeListener(weakItemPropertyChangeListener);
        if (datasource.getState() == Datasource.State.VALID && datasource.getItem() != null) {
            if (property.equals(metaPropertyPath.toString())) {
                Object newValue = InstanceUtils.getValueEx(datasource.getItem(), metaPropertyPath.getPath());
                setValue(newValue);
            }
        }
        initRequired(metaPropertyPath);
        if (metaProperty.isReadOnly()) {
            setEditable(false);
        }
        handleFilteredAttributes(this, this.datasource, metaPropertyPath);
        securityItemChangeListener = e -> handleFilteredAttributes(this, this.datasource, metaPropertyPath);
        securityWeakItemChangeListener = new WeakItemChangeListener(datasource, securityItemChangeListener);
        // noinspection unchecked
        this.datasource.addItemChangeListener(securityWeakItemChangeListener);
        initBeanValidator();
    }
}
Also used : WeakItemChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemChangeListener) WeakItemPropertyChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener) Property(com.vaadin.data.Property) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 12 with Property

use of com.vaadin.data.Property in project VaadinUtils by rlsutton1.

the class ReportParameterTable method addSelectionListener.

@Override
public void addSelectionListener(final ValueChangeListener listener) {
    UI ui = UI.getCurrent();
    if (ui != null) {
        Runnable runner = new Runnable() {

            @Override
            public void run() {
                grid.addSelectionListener(new SelectionListener() {

                    /**
                     */
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void select(SelectionEvent event) {
                        listener.valueChange(new ValueChangeEvent() {

                            /**
                             */
                            private static final long serialVersionUID = 1L;

                            @Override
                            public Property<Collection<Long>> getProperty() {
                                return new Property<Collection<Long>>() {

                                    /**
                                     */
                                    private static final long serialVersionUID = 1L;

                                    @Override
                                    public Collection<Long> getValue() {
                                        return getSelectedIds();
                                    }

                                    @Override
                                    public void setValue(Collection<Long> newValue) throws com.vaadin.data.Property.ReadOnlyException {
                                    }

                                    @Override
                                    public Class<? extends Collection<Long>> getType() {
                                        return null;
                                    }

                                    @Override
                                    public boolean isReadOnly() {
                                        return false;
                                    }

                                    @Override
                                    public void setReadOnly(boolean newStatus) {
                                    }
                                };
                            }
                        });
                    }
                });
            }
        };
        UI.getCurrent().accessSynchronously(runner);
    } else {
        logger.warn("No vaadin session available, not setting up UI");
    }
}
Also used : ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) UI(com.vaadin.ui.UI) SelectionEvent(com.vaadin.event.SelectionEvent) Collection(java.util.Collection) Property(com.vaadin.data.Property) SelectionListener(com.vaadin.event.SelectionEvent.SelectionListener)

Example 13 with Property

use of com.vaadin.data.Property in project VaadinUtils by rlsutton1.

the class MultiSelectConverter method addBackReference.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void addBackReference(T entity) {
    if (!isOwningSide()) {
        Property itemProperty = getBackReferenceItemProperty(entity);
        Object property = itemProperty.getValue();
        if (property == null || !(property instanceof Collection)) {
            itemProperty.setValue(getPropertyDataSource().getItem().getEntity());
        // one to many
        } else {
            // many to many
            Preconditions.checkArgument(property instanceof Collection, "Expected a Collection got " + itemProperty.getType() + " " + property.getClass().getCanonicalName());
            Collection c = (Collection) property;
            c.add(getPropertyDataSource().getItem().getEntity());
            itemProperty.setValue(c);
        }
    }
}
Also used : Collection(java.util.Collection) Property(com.vaadin.data.Property) EntityItemProperty(com.vaadin.addon.jpacontainer.EntityItemProperty)

Example 14 with Property

use of com.vaadin.data.Property in project Activiti by Activiti.

the class RunReportsPage method createList.

protected Table createList() {
    reportTable = new Table();
    reportListQuery = new ReportListQuery();
    reportListContainer = new LazyLoadingContainer(reportListQuery);
    reportTable.setContainerDataSource(reportListContainer);
    // Column headers
    reportTable.addGeneratedColumn("icon", new ThemeImageColumnGenerator(Images.REPORT_22));
    reportTable.setColumnWidth("icon", 22);
    reportTable.addContainerProperty("name", String.class, null);
    reportTable.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN);
    // Listener to change right panel when clicked on a report
    reportTable.addListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {
            // the value of the property is the itemId of the table entry
            Item item = reportTable.getItem(event.getProperty().getValue());
            if (item != null) {
                String processDefinitionId = (String) item.getItemProperty("id").getValue();
                setDetailComponent(new ReportDetailPanel(processDefinitionId, RunReportsPage.this));
                // Update URL
                ExplorerApp.get().setCurrentUriFragment(new UriFragment(ReportNavigator.REPORT_URI_PART, processDefinitionId));
            } else {
                // Nothing selected
                setDetailComponent(null);
                ExplorerApp.get().setCurrentUriFragment(new UriFragment(ReportNavigator.REPORT_URI_PART));
            }
        }
    });
    return reportTable;
}
Also used : Item(com.vaadin.data.Item) ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) Table(com.vaadin.ui.Table) ThemeImageColumnGenerator(org.activiti.explorer.ui.util.ThemeImageColumnGenerator) LazyLoadingContainer(org.activiti.explorer.data.LazyLoadingContainer) Property(com.vaadin.data.Property) UriFragment(org.activiti.explorer.navigation.UriFragment)

Example 15 with Property

use of com.vaadin.data.Property in project Activiti by Activiti.

the class ProcessInstancePage method createList.

protected Table createList() {
    final Table table = new Table();
    LazyLoadingQuery query = new ProcessInstanceListQuery();
    processInstanceContainer = new LazyLoadingContainer(query);
    table.setContainerDataSource(processInstanceContainer);
    table.addListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {
            // the value of the property is the itemId of the table entry
            Item item = table.getItem(event.getProperty().getValue());
            if (item != null) {
                String processInstanceId = (String) item.getItemProperty("id").getValue();
                setDetailComponent(new AlfrescoProcessInstanceDetailPanel(processInstanceId, ProcessInstancePage.this));
                // Update URL
                ExplorerApp.get().setCurrentUriFragment(new UriFragment(ProcessInstanceNavigator.PROCESS_INSTANCE_URL_PART, processInstanceId));
            } else {
                // Nothing is selected
                setDetailComponent(null);
                ExplorerApp.get().setCurrentUriFragment(new UriFragment(ProcessInstanceNavigator.PROCESS_INSTANCE_URL_PART));
            }
        }
    });
    // Create column headers
    table.addGeneratedColumn("icon", new ThemeImageColumnGenerator(Images.PROCESS_22));
    table.setColumnWidth("icon", 22);
    table.addContainerProperty("name", String.class, null);
    table.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN);
    return table;
}
Also used : Table(com.vaadin.ui.Table) LazyLoadingContainer(org.activiti.explorer.data.LazyLoadingContainer) UriFragment(org.activiti.explorer.navigation.UriFragment) Item(com.vaadin.data.Item) ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) ThemeImageColumnGenerator(org.activiti.explorer.ui.util.ThemeImageColumnGenerator) Property(com.vaadin.data.Property) LazyLoadingQuery(org.activiti.explorer.data.LazyLoadingQuery)

Aggregations

Property (com.vaadin.data.Property)26 Item (com.vaadin.data.Item)18 ValueChangeEvent (com.vaadin.data.Property.ValueChangeEvent)16 Table (com.vaadin.ui.Table)15 UriFragment (org.activiti.explorer.navigation.UriFragment)11 LazyLoadingContainer (org.activiti.explorer.data.LazyLoadingContainer)10 ThemeImageColumnGenerator (org.activiti.explorer.ui.util.ThemeImageColumnGenerator)8 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)4 WeakItemChangeListener (com.haulmont.cuba.gui.data.impl.WeakItemChangeListener)3 Label (com.vaadin.ui.Label)3 LazyLoadingQuery (org.activiti.explorer.data.LazyLoadingQuery)3 MetaClass (com.haulmont.chile.core.model.MetaClass)2 WeakItemPropertyChangeListener (com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener)2 ErrorMessage (com.vaadin.server.ErrorMessage)2 Collection (java.util.Collection)2 HistoricFormProperty (org.activiti.engine.history.HistoricFormProperty)2 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)2 PrettyTimeLabel (org.activiti.explorer.ui.custom.PrettyTimeLabel)2 ClickableLabel (au.com.vaadinutils.fields.ClickableLabel)1 Enumeration (com.haulmont.chile.core.datatypes.Enumeration)1