diff --git a/modules/gui/src/com/haulmont/cuba/gui/data/impl/CollectionDsListenerAdapter.java b/modules/gui/src/com/haulmont/cuba/gui/data/impl/CollectionDsListenerAdapter.java index 456dbb9c92..73e0070dd0 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/data/impl/CollectionDsListenerAdapter.java +++ b/modules/gui/src/com/haulmont/cuba/gui/data/impl/CollectionDsListenerAdapter.java @@ -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 + * @author tulupov + * @version $Id$ + */ public class CollectionDsListenerAdapter extends DsListenerAdapter implements CollectionDatasourceListener { + @Override public void collectionChanged(CollectionDatasource ds, Operation operation) { } } diff --git a/modules/gui/src/com/haulmont/cuba/gui/data/impl/DsListenerAdapter.java b/modules/gui/src/com/haulmont/cuba/gui/data/impl/DsListenerAdapter.java index 14c9bf7e72..10e2e4cf9f 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/data/impl/DsListenerAdapter.java +++ b/modules/gui/src/com/haulmont/cuba/gui/data/impl/DsListenerAdapter.java @@ -27,4 +27,4 @@ public class DsListenerAdapter implements DatasourceListener 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 getValueFromKey(Object key) { if (key instanceof Collection) { - final Set set = new HashSet(); + final Set set = new HashSet<>(); for (Object o : (Collection) key) { Object t = getValue(o); set.add(t); @@ -80,7 +87,7 @@ public class WebOptionsGroup } } - protected 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 set = new HashSet(); + final Set set = new HashSet<>(); for (Object o : (Collection) value) { Object t = getKey(o); set.add(t); diff --git a/modules/web/src/com/haulmont/cuba/web/gui/data/CollectionDsWrapper.java b/modules/web/src/com/haulmont/cuba/web/gui/data/CollectionDsWrapper.java index ecda99a865..0844160618 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/data/CollectionDsWrapper.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/data/CollectionDsWrapper.java @@ -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 properties = new ArrayList(); - private List itemSetChangeListeners = new ArrayList(); - -// private PersistenceManagerService persistenceManager; - - private static Log log = LogFactory.getLog(CollectionDsWrapper.class); - - private static final long serialVersionUID = 1440434590495905389L; + protected Collection properties = new ArrayList<>(); + private List 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 itemsCache = new HashMap(); + protected Map 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 { + @Override public void itemChanged(Datasource ds, Entity prevItem, Entity item) {} + @Override public void stateChanged(Datasource 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 - { + implements LazyCollectionDatasourceListener { + @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() + "}"); } -} +} \ No newline at end of file diff --git a/modules/web/src/com/haulmont/cuba/web/gui/data/ItemWrapper.java b/modules/web/src/com/haulmont/cuba/web/gui/data/ItemWrapper.java index c1c5667589..e96f662bf4 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/data/ItemWrapper.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/data/ItemWrapper.java @@ -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 properties = new HashMap(); - private List listeners = new ArrayList(); + private static final long serialVersionUID = -7298696379571470141L; + + private Map properties = new HashMap<>(); + private List 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() { - public void collectionChanged(CollectionDatasource ds, Operation operation) {} + ((CollectionDatasource) item).addListener(new CollectionDsListenerAdapter() { + @Override public void itemChanged(Datasource ds, Entity prevItem, Entity item) { fireItemProperySetChanged(); } - public void stateChanged(Datasource 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; } -} +} \ No newline at end of file diff --git a/modules/web/src/com/haulmont/cuba/web/toolkit/ui/OptionGroup.java b/modules/web/src/com/haulmont/cuba/web/toolkit/ui/OptionGroup.java index 3103ff3bae..87171fe81c 100644 --- a/modules/web/src/com/haulmont/cuba/web/toolkit/ui/OptionGroup.java +++ b/modules/web/src/com/haulmont/cuba/web/toolkit/ui/OptionGroup.java @@ -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 disabledOptions = null; - - public void setOptionDisabled(Object id, boolean disabled) { - if (disabled) { - if (disabledOptions == null) { - disabledOptions = new HashSet(); - } - 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 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; - } -} +} \ No newline at end of file