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