Ability for GroupTable grouped static by defined in 'group' tag columns #PL-2153

This commit is contained in:
Yuriy Artamonov 2013-05-20 08:45:33 +00:00
parent 105a1bd796
commit 7ed21813ea
7 changed files with 121 additions and 42 deletions

View File

@ -60,7 +60,7 @@ def desktopModule = project(':cuba-desktop')
def uiTestModule = project(':cuba-test-ui') def uiTestModule = project(':cuba-test-ui')
def portalModule = project(':cuba-portal') def portalModule = project(':cuba-portal')
def vaadinVersion = '7.0.5.h.M3' def vaadinVersion = '7.0.5.h.M4'
def servletApi = [group: 'org.apache.tomcat', name: 'servlet-api', version: '6.0.20'] def servletApi = [group: 'org.apache.tomcat', name: 'servlet-api', version: '6.0.20']
def groovyArtifact = [group: 'org.codehaus.groovy', name: 'groovy', version: '1.7.10'] def groovyArtifact = [group: 'org.codehaus.groovy', name: 'groovy', version: '1.7.10']

View File

@ -67,6 +67,15 @@ public class DesktopGroupTable extends DesktopAbstractTable<JXTable> implements
return true; return true;
} }
@Override
public boolean isFixedGrouping() {
return false;
}
@Override
public void setFixedGrouping(boolean groupingByUserEnabled) {
}
@Override @Override
public void setSortable(boolean sortable) { public void setSortable(boolean sortable) {
super.setSortable(sortable); super.setSortable(sortable);
@ -78,4 +87,4 @@ public class DesktopGroupTable extends DesktopAbstractTable<JXTable> implements
super.setEditable(editable); super.setEditable(editable);
impl.setEditable(editable); impl.setEditable(editable);
} }
} }

View File

@ -2,16 +2,15 @@
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved. * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential. * Haulmont Technology proprietary and confidential.
* Use is subject to license terms. * Use is subject to license terms.
* Author: Nikolay Gorodnov
* Created: 18.11.2009 14:44:36
*
* $Id$
*/ */
package com.haulmont.cuba.gui.components; package com.haulmont.cuba.gui.components;
import com.haulmont.cuba.gui.data.GroupInfo; import com.haulmont.cuba.gui.data.GroupInfo;
/**
* @author gorodnov
* @version $Id$
*/
public interface GroupTable extends Table { public interface GroupTable extends Table {
String NAME = "groupTable"; String NAME = "groupTable";
@ -25,4 +24,7 @@ public interface GroupTable extends Table {
void collapse(GroupInfo groupId); void collapse(GroupInfo groupId);
boolean isExpanded(GroupInfo groupId); boolean isExpanded(GroupInfo groupId);
}
boolean isFixedGrouping();
void setFixedGrouping(boolean fixedGrouping);
}

View File

@ -777,6 +777,8 @@
<xs:attributeGroup ref="hasVisibility"/> <xs:attributeGroup ref="hasVisibility"/>
<xs:attributeGroup ref="isTableComponent"/> <xs:attributeGroup ref="isTableComponent"/>
<xs:attribute name="fixedGrouping" type="xs:boolean" use="optional"/>
</xs:complexType> </xs:complexType>
<!-- Filter --> <!-- Filter -->

View File

@ -2,48 +2,59 @@
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved. * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential. * Haulmont Technology proprietary and confidential.
* Use is subject to license terms. * Use is subject to license terms.
* Author: Nikolay Gorodnov
* Created: 25.11.2009 13:37:46
*
* $Id$
*/ */
package com.haulmont.cuba.gui.xml.layout.loaders; package com.haulmont.cuba.gui.xml.layout.loaders;
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.GroupTable; import com.haulmont.cuba.gui.components.GroupTable;
import com.haulmont.cuba.gui.components.IFrame; import com.haulmont.cuba.gui.components.IFrame;
import com.haulmont.cuba.gui.components.Table; import com.haulmont.cuba.gui.components.Table;
import com.haulmont.cuba.gui.data.CollectionDatasource; import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory; import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig; import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Element; import org.dom4j.Element;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
/**
* @author gorodnov
* @version $Id$
*/
public class GroupTableLoader extends AbstractTableLoader<GroupTable> { public class GroupTableLoader extends AbstractTableLoader<GroupTable> {
public GroupTableLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) { public GroupTableLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
super(context, config, factory); super(context, config, factory);
} }
protected GroupTable createComponent( @Override
ComponentsFactory factory protected GroupTable createComponent(ComponentsFactory factory)
) throws InstantiationException, IllegalAccessException { throws InstantiationException, IllegalAccessException {
return factory.createComponent("groupTable"); return factory.createComponent("groupTable");
} }
@Override @Override
protected List<Table.Column> loadColumns( public Component loadComponent(ComponentsFactory factory, Element element, Component parent)
final Table component, throws InstantiationException, IllegalAccessException {
Element columnsElement, GroupTable component = (GroupTable) super.loadComponent(factory, element, parent);
CollectionDatasource ds
) { String fixedGroupingString = element.attributeValue("fixedGrouping");
final List<Table.Column> columns = new ArrayList<Table.Column>(); if (StringUtils.isNotEmpty(fixedGroupingString)) {
component.setFixedGrouping(Boolean.valueOf(fixedGroupingString));
}
return component;
}
@Override
protected List<Table.Column> loadColumns(final Table component, Element columnsElement, CollectionDatasource ds) {
final List<Table.Column> columns = new ArrayList<>();
final Element groupElement = columnsElement.element("group"); final Element groupElement = columnsElement.element("group");
if (groupElement != null) { if (groupElement != null) {
columns.addAll(super.loadColumns(component, groupElement, ds)); columns.addAll(super.loadColumns(component, groupElement, ds));
final List<Object> groupProperties = new ArrayList<Object>(columns.size()); final List<Object> groupProperties = new ArrayList<>(columns.size());
for (Table.Column column : columns) { for (Table.Column column : columns) {
groupProperties.add(column.getId()); groupProperties.add(column.getId());
} }
@ -57,4 +68,4 @@ public class GroupTableLoader extends AbstractTableLoader<GroupTable> {
columns.addAll(super.loadColumns(component, columnsElement, ds)); columns.addAll(super.loadColumns(component, columnsElement, ds));
return columns; return columns;
} }
} }

View File

@ -186,6 +186,16 @@ public class WebGroupTable extends WebAbstractTable<CubaGroupTable>
return component.isExpanded(groupId); return component.isExpanded(groupId);
} }
@Override
public boolean isFixedGrouping() {
return component.isFixedGrouping();
}
@Override
public void setFixedGrouping(boolean fixedGrouping) {
component.setFixedGrouping(fixedGrouping);
}
protected class GroupTableDsWrapper extends SortableCollectionDsWrapper protected class GroupTableDsWrapper extends SortableCollectionDsWrapper
implements GroupTableContainer, implements GroupTableContainer,
AggregationContainer { AggregationContainer {

View File

@ -26,9 +26,11 @@ import java.util.*;
*/ */
public class CubaGroupTable extends CubaTable implements GroupTableContainer { public class CubaGroupTable extends CubaTable implements GroupTableContainer {
private KeyMapper groupIdMap = new KeyMapper(); protected KeyMapper groupIdMap = new KeyMapper();
private GroupPropertyValueFormatter groupPropertyValueFormatter; protected GroupPropertyValueFormatter groupPropertyValueFormatter;
protected boolean fixedGrouping = true;
@Override @Override
public void setContainerDataSource(Container newDataSource) { public void setContainerDataSource(Container newDataSource) {
@ -70,23 +72,30 @@ public class CubaGroupTable extends CubaTable implements GroupTableContainer {
boolean needsResetPageBuffer = false; boolean needsResetPageBuffer = false;
Object[] newGroupProperties = null; Object[] newGroupProperties = null;
if (variables.containsKey("columnorder") && !variables.containsKey("groupedcolumns")) { if (!fixedGrouping) {
newGroupProperties = new Object[0]; if (variables.containsKey("columnorder") && !variables.containsKey("groupedcolumns")) {
} else if (variables.containsKey("groupedcolumns")) { newGroupProperties = new Object[0];
final Object[] ids = (Object[]) variables.get("groupedcolumns"); } else if (variables.containsKey("groupedcolumns")) {
final Object[] groupProperties = new Object[ids.length]; final Object[] ids = (Object[]) variables.get("groupedcolumns");
for (int i = 0; i < ids.length; i++) { final Object[] groupProperties = new Object[ids.length];
groupProperties[i] = columnIdMap.get(ids[i].toString()); for (int i = 0; i < ids.length; i++) {
} groupProperties[i] = columnIdMap.get(ids[i].toString());
newGroupProperties = groupProperties;
// Deny group by generated columns
if (!columnGenerators.isEmpty()) {
List<Object> notGeneratedProperties = new ArrayList<>();
for (Object id : newGroupProperties) {
if (!columnGenerators.containsKey(id) || (id instanceof MetaPropertyPath))
notGeneratedProperties.add(id);
} }
newGroupProperties = notGeneratedProperties.toArray(); newGroupProperties = groupProperties;
// Deny group by generated columns
if (!columnGenerators.isEmpty()) {
List<Object> notGeneratedProperties = new ArrayList<>();
for (Object id : newGroupProperties) {
if (!columnGenerators.containsKey(id) || (id instanceof MetaPropertyPath)) {
notGeneratedProperties.add(id);
}
}
newGroupProperties = notGeneratedProperties.toArray();
}
}
} else {
if (variables.containsKey("columnorder") || variables.containsKey("groupedcolumns")) {
markAsDirty();
} }
} }
@ -235,6 +244,33 @@ public class CubaGroupTable extends CubaTable implements GroupTableContainer {
} }
} }
@Override
protected void setColumnOrder(Object[] columnOrder) {
Collection<?> groupProperties = getGroupProperties();
if (!groupProperties.isEmpty()) {
// check order of grouped and not grouped columns
int i = 1;
while (i < columnOrder.length && isValidOrderPosition(groupProperties, columnOrder, i)) {
i++;
}
if (i < columnOrder.length) {
// found not grouped column on left side of grouped
markAsDirty();
return;
}
}
super.setColumnOrder(columnOrder);
}
protected boolean isValidOrderPosition(Collection<?> groupProperties, Object[] columnOrder, int index) {
if (!groupProperties.contains(columnOrder[index]))
return true;
return groupProperties.contains(columnOrder[index]) &&
groupProperties.contains(columnOrder[index - 1]);
}
@Override @Override
public Collection<?> getGroupProperties() { public Collection<?> getGroupProperties() {
Collection<?> groupProperties = ((GroupTableContainer) items).getGroupProperties(); Collection<?> groupProperties = ((GroupTableContainer) items).getGroupProperties();
@ -335,6 +371,15 @@ public class CubaGroupTable extends CubaTable implements GroupTableContainer {
return ((GroupTableContainer) items).isExpanded(id); return ((GroupTableContainer) items).isExpanded(id);
} }
public boolean isFixedGrouping() {
return fixedGrouping;
}
public void setFixedGrouping(boolean fixedGrouping) {
this.fixedGrouping = fixedGrouping;
markAsDirty();
}
public GroupPropertyValueFormatter getGroupPropertyValueFormatter() { public GroupPropertyValueFormatter getGroupPropertyValueFormatter() {
return groupPropertyValueFormatter; return groupPropertyValueFormatter;
} }