Refs #1641 [WEB] OptionsGroup : item caption shows UUID instead of Instance name

This commit is contained in:
Yuriy Artamonov 2012-12-21 14:58:02 +00:00
parent 03bf9519a1
commit 6c0061dbf4
6 changed files with 78 additions and 114 deletions

View File

@ -2,11 +2,6 @@
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Maksim Tulupov
* Created: 24.11.2009 17:31:03
*
* $Id$
*/
package com.haulmont.cuba.gui.data.impl;
@ -14,8 +9,14 @@ import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.data.CollectionDatasourceListener;
import com.haulmont.cuba.core.entity.Entity;
/**
* @param <T>
* @author tulupov
* @version $Id$
*/
public class CollectionDsListenerAdapter<T extends Entity> extends DsListenerAdapter<T> implements CollectionDatasourceListener<T> {
@Override
public void collectionChanged(CollectionDatasource ds, Operation operation) {
}
}

View File

@ -27,4 +27,4 @@ public class DsListenerAdapter<T extends Entity> implements DatasourceListener<T
@Override
public void valueChanged(T source, String property, Object prevValue, Object value) {
}
}
}

View File

@ -14,17 +14,22 @@ import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.OptionsGroup;
import com.haulmont.cuba.web.toolkit.ui.OptionGroup;
import com.vaadin.data.Property;
import com.vaadin.ui.AbstractSelect;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* @author abramov
* @version $Id$
*/
public class WebOptionsGroup
extends
WebAbstractOptionsField<OptionGroup>
implements
OptionsGroup, Component.Wrapper
{
OptionsGroup, Component.Wrapper {
private static final String HORIZONTAL_STYLENAME = "horizontal";
private Orientation orientation = Orientation.VERTICAL;
@ -52,6 +57,7 @@ public class WebOptionsGroup
attachListener(component);
component.setImmediate(true);
component.setInvalidCommitted(true);
component.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_ITEM);
}
@SuppressWarnings({"unchecked"})
@ -65,10 +71,11 @@ public class WebOptionsGroup
}
}
@Override
@SuppressWarnings({"unchecked"})
protected <T> T getValueFromKey(Object key) {
if (key instanceof Collection) {
final Set<Object> set = new HashSet<Object>();
final Set<Object> set = new HashSet<>();
for (Object o : (Collection) key) {
Object t = getValue(o);
set.add(t);
@ -80,7 +87,7 @@ public class WebOptionsGroup
}
}
protected <T> Object getValue(Object o) {
protected Object getValue(Object o) {
Object t;
if (o instanceof Enum) {
t = o;
@ -99,11 +106,12 @@ public class WebOptionsGroup
super.setValue(getKeyFromValue(value));
}
@Override
protected Object getKeyFromValue(Object value) {
Object v;
if (isMultiSelect()) {
if (value instanceof Collection) {
final Set<Object> set = new HashSet<Object>();
final Set<Object> set = new HashSet<>();
for (Object o : (Collection) value) {
Object t = getKey(o);
set.add(t);

View File

@ -2,10 +2,6 @@
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Dmitry Abramov
* Created: 29.12.2008 16:17:57
* $Id$
*/
package com.haulmont.cuba.web.gui.data;
@ -18,26 +14,24 @@ import com.haulmont.cuba.gui.data.impl.CollectionDsHelper;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.*;
/**
* @author abramov
* @version $Id$
*/
public class CollectionDsWrapper implements Container, Container.ItemSetChangeNotifier {
private static final long serialVersionUID = 1440434590495905389L;
protected boolean autoRefresh;
protected boolean ignoreListeners;
protected CollectionDatasource datasource;
protected Collection<MetaPropertyPath> properties = new ArrayList<MetaPropertyPath>();
private List<ItemSetChangeListener> itemSetChangeListeners = new ArrayList<ItemSetChangeListener>();
// private PersistenceManagerService persistenceManager;
private static Log log = LogFactory.getLog(CollectionDsWrapper.class);
private static final long serialVersionUID = 1440434590495905389L;
protected Collection<MetaPropertyPath> properties = new ArrayList<>();
private List<ItemSetChangeListener> itemSetChangeListeners = new ArrayList<>();
public CollectionDsWrapper(CollectionDatasource datasource) {
this(datasource, false);
@ -58,7 +52,6 @@ public class CollectionDsWrapper implements Container, Container.ItemSetChangeNo
) {
this.datasource = datasource;
this.autoRefresh = autoRefresh;
// this.persistenceManager = ServiceLocator.lookup(PersistenceManagerService.NAME);
final View view = datasource.getView();
final MetaClass metaClass = datasource.getMetaClass();
@ -96,13 +89,14 @@ public class CollectionDsWrapper implements Container, Container.ItemSetChangeNo
}
}
@Override
public Item getItem(Object itemId) {
CollectionDsHelper.autoRefreshInvalid(datasource, autoRefresh);
final Object item = datasource.getItem(itemId);
return item == null ? null : getItemWrapper(item);
}
protected Map<Object, ItemWrapper> itemsCache = new HashMap<Object, ItemWrapper>();
protected Map<Object, ItemWrapper> itemsCache = new HashMap<>();
protected synchronized Item getItemWrapper(Object item) {
ItemWrapper wrapper = itemsCache.get(item);
@ -118,63 +112,77 @@ public class CollectionDsWrapper implements Container, Container.ItemSetChangeNo
return new ItemWrapper(item, properties);
}
@Override
public Collection getContainerPropertyIds() {
return properties;
}
public synchronized Collection getItemIds() {
@Override
public Collection getItemIds() {
CollectionDsHelper.autoRefreshInvalid(datasource, autoRefresh);
return datasource.getItemIds();
}
@Override
public Property getContainerProperty(Object itemId, Object propertyId) {
final Item item = getItem(itemId);
return item == null ? null : item.getItemProperty(propertyId);
}
@Override
public Class getType(Object propertyId) {
MetaPropertyPath propertyPath = (MetaPropertyPath) propertyId;
return propertyPath.getRangeJavaClass();
}
public synchronized int size() {
@Override
public int size() {
CollectionDsHelper.autoRefreshInvalid(datasource, autoRefresh);
return datasource.size();
}
public synchronized boolean containsId(Object itemId) {
@Override
public boolean containsId(Object itemId) {
CollectionDsHelper.autoRefreshInvalid(datasource, autoRefresh);
return datasource.containsItem(itemId);
}
@Override
public Item addItem(Object itemId) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@Override
public Object addItem() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@Override
public boolean removeItem(Object itemId) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@Override
public boolean addContainerProperty(Object propertyId, Class type, Object defaultValue) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@Override
public boolean removeContainerProperty(Object propertyId) throws UnsupportedOperationException {
return this.properties.remove(propertyId);
}
@Override
public boolean removeAllItems() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@Override
public void addListener(ItemSetChangeListener listener) {
this.itemSetChangeListeners.add(listener);
}
@Override
public void removeListener(ItemSetChangeListener listener) {
this.itemSetChangeListeners.remove(listener);
}
@ -191,8 +199,10 @@ public class CollectionDsWrapper implements Container, Container.ItemSetChangeNo
}
protected class DataSourceRefreshListener implements CollectionDatasourceListener<Entity> {
@Override
public void itemChanged(Datasource ds, Entity prevItem, Entity item) {}
@Override
public void stateChanged(Datasource<Entity> ds, Datasource.State prevState, Datasource.State state) {
final boolean prevIgnoreListeners = ignoreListeners;
try {
@ -202,6 +212,7 @@ public class CollectionDsWrapper implements Container, Container.ItemSetChangeNo
}
}
@Override
public void valueChanged(Entity source, String property, Object prevValue, Object value) {
Item wrapper = getItemWrapper(source);
@ -216,6 +227,7 @@ public class CollectionDsWrapper implements Container, Container.ItemSetChangeNo
}
}
@Override
public void collectionChanged(CollectionDatasource ds, Operation operation) {
final boolean prevIgnoreListeners = ignoreListeners;
try {
@ -228,12 +240,11 @@ public class CollectionDsWrapper implements Container, Container.ItemSetChangeNo
ignoreListeners = prevIgnoreListeners;
}
}
}
protected class LazyDataSourceRefreshListener extends DataSourceRefreshListener
implements LazyCollectionDatasourceListener<Entity>
{
implements LazyCollectionDatasourceListener<Entity> {
@Override
public void completelyLoaded(CollectionDatasource.Lazy ds) {
checkMaxFetchUI(ds);
}
@ -243,4 +254,4 @@ public class CollectionDsWrapper implements Container, Container.ItemSetChangeNo
public String toString() {
return "{ds=" + (datasource == null ? "null" : datasource.getId() + "}");
}
}
}

View File

@ -2,10 +2,6 @@
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Dmitry Abramov
* Created: 29.12.2008 17:01:30
* $Id$
*/
package com.haulmont.cuba.web.gui.data;
@ -14,25 +10,28 @@ import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.chile.core.model.MetaPropertyPath;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.MetadataProvider;
import com.haulmont.cuba.core.global.MetadataTools;
import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.data.CollectionDatasourceListener;
import com.haulmont.cuba.gui.data.Datasource;
import com.haulmont.cuba.gui.data.impl.CollectionDsListenerAdapter;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import java.util.*;
/**
* @author abramov
* @version $Id$
*/
public class ItemWrapper implements Item, Item.PropertySetChangeNotifier {
private Map<MetaPropertyPath, PropertyWrapper> properties = new HashMap<MetaPropertyPath, PropertyWrapper>();
private List<PropertySetChangeListener> listeners = new ArrayList<PropertySetChangeListener>();
private static final long serialVersionUID = -7298696379571470141L;
private Map<MetaPropertyPath, PropertyWrapper> properties = new HashMap<>();
private List<PropertySetChangeListener> listeners = new ArrayList<>();
protected Object item;
private static final long serialVersionUID = -7298696379571470141L;
public ItemWrapper(Object item, MetaClass metaClass) {
this(item, AppBeans.get(MetadataTools.class).getPropertyPaths(metaClass));
}
@ -45,13 +44,11 @@ public class ItemWrapper implements Item, Item.PropertySetChangeNotifier {
}
if (item instanceof CollectionDatasource) {
((CollectionDatasource) item).addListener(new CollectionDatasourceListener<Entity>() {
public void collectionChanged(CollectionDatasource ds, Operation operation) {}
((CollectionDatasource) item).addListener(new CollectionDsListenerAdapter<Entity>() {
@Override
public void itemChanged(Datasource<Entity> ds, Entity prevItem, Entity item) {
fireItemProperySetChanged();
}
public void stateChanged(Datasource<Entity> ds, Datasource.State prevState, Datasource.State state) {}
public void valueChanged(Entity source, String property, Object prevValue, Object value) {}
});
}
}
@ -66,6 +63,7 @@ public class ItemWrapper implements Item, Item.PropertySetChangeNotifier {
return new PropertyWrapper(item, propertyPath);
}
@Override
public Property getItemProperty(Object id) {
if (id instanceof MetaPropertyPath) {
return properties.get(id);
@ -77,27 +75,33 @@ public class ItemWrapper implements Item, Item.PropertySetChangeNotifier {
}
}
@Override
public Collection getItemPropertyIds() {
return properties.keySet();
}
@Override
public boolean addItemProperty(Object id, Property property) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@Override
public boolean removeItemProperty(Object id) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@Override
public void addListener(PropertySetChangeListener listener) {
if (!listeners.contains(listener)) listeners.add(listener);
}
@Override
public void removeListener(PropertySetChangeListener listener) {
listeners.remove(listener);
}
private class PropertySetChangeEvent implements Item.PropertySetChangeEvent {
@Override
public Item getItem() {
return ItemWrapper.this;
}
@ -112,4 +116,4 @@ public class ItemWrapper implements Item, Item.PropertySetChangeNotifier {
public Entity getItem() {
return item instanceof Datasource ? ((Datasource) item).getItem() : (Entity) item;
}
}
}

View File

@ -2,76 +2,16 @@
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Nikolay Gorodnov
* Created: 24.11.2009 16:31:35
*
* $Id$
*/
package com.haulmont.cuba.web.toolkit.ui;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Resource;
import com.vaadin.terminal.gwt.client.ui.VOptionGroup;
import com.vaadin.ui.ClientWidget;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@SuppressWarnings("serial")
/**
* @author gorodnov
* @version $Id$
*/
@ClientWidget(VOptionGroup.class)
public class OptionGroup extends com.vaadin.ui.OptionGroup {
protected Set<Object> disabledOptions = null;
public void setOptionDisabled(Object id, boolean disabled) {
if (disabled) {
if (disabledOptions == null) {
disabledOptions = new HashSet<Object>();
}
disabledOptions.add(id);
} else {
if (disabledOptions == null) return;
disabledOptions.remove(id);
if (disabledOptions.isEmpty()) {
disabledOptions = null;
}
}
}
public boolean isOptionDisabled(Object id) {
return disabledOptions != null && disabledOptions.contains(id);
}
public Set<Object> getDisabledOptions() {
if (disabledOptions != null) {
return Collections.unmodifiableSet(disabledOptions);
} else {
return Collections.emptySet();
}
}
protected int paintOption(PaintTarget target, String[] selectedKeys,
int keyIndex, Object id, String key, String caption, Resource icon
) throws PaintException {
target.startTag("so");
if (icon != null) {
target.addAttribute("icon", icon);
}
target.addAttribute("caption", caption);
if (id != null && id.equals(getNullSelectionItemId())) {
target.addAttribute("nullselection", true);
}
target.addAttribute("key", key);
if (isSelected(id) && keyIndex < selectedKeys.length) {
target.addAttribute("selected", true);
selectedKeys[keyIndex++] = key;
}
if (isOptionDisabled(id)) {
target.addAttribute("disabled", true);
}
target.endTag("so");
return keyIndex;
}
}
}